Eddie Jack

Eddie Jack

  • NA
  • 156
  • 139.1k

Rename file while uploading file in specific folder

Jul 29 2011 12:03 AM
Hi…

I want to rename my file name that while I am uploading file in my files folder. Which
 changes should I do in below code?. New name should be pick from text box.

protected
void Upload_Click(object sender, EventArgs e)
   {
       String strFilename = Path.GetFileName(FileUpload1.FileName);
       String StrFilePathName = String.Empty;
       String strBaseDir = AppDomain.CurrentDomain.BaseDirectory + "Files";
 if (!Directory.Exists(strBaseDir))
       {
           Directory.CreateDirectory(strBaseDir);
       }
       StrFilePathName = strBaseDir + "\\" + strFilename;
       FileUpload1.SaveAs(StrFilePathName);
       if (!FileUpload1.HasFile) return;
       Response.Redirect("~/Default2.aspx");
   }

Answers (2)