Home > DeveloperSection > Forums > rename files to upload to server ASP.NET
Chintoo Semi

Total Post:135

Points:947
Posted on    August-21-2014 12:34 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 629  View(s)
Rate this:

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

How I can do this this?



Sumit Kesarwani

Total Post:378

Points:2694
Supported
Posted on    August-21-2014 1:11 AM

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


Don't want to miss updates? Please click the below button!

Follow MindStick