RENAME FILES TO UPLOAD TO SERVER ASP.NET

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
 929  View(s)
Ratings:
Rate this:

I need to rename the files before uploading them to my local directory.

How I can do this this?

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: rename files to upload to server ASP.NET

    Hi Chintoo, 


    try this:

     protected void button1_Click(object sender, EventArgs e){

        string directory = Server.MapPath("uploads");

        string fExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);

        string fileName = "newFileName" + fExtension;

        this.FileUpload1.SaveAs(Path.Combine(directory,fileName));

    }

    Hope this will solve your problem

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!