rename files to upload to server ASP.NET

Total Post:135

Points:947

 1355  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. 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

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.