Rename file name during uploading in Asp .Net

 In this article we will see how to rename file name during uploading in asp .net. Renaming of files is really important when you want to upload your files using your custom names. For this article we will use  FileUpload control to upload files and inbuild .Net methods to rename and upload file.

HTML:


        

CodeBehind

protected void btnUploadFile_Click(object sender, EventArgs e)
    {
        //==== Add Namespace System.IO

        //==== Get file name without its extension.
        string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(flUpload.FileName);

        //==== Get file extension.
        string fileExtension = Path.GetExtension(flUpload.FileName);

        //=== Now we have both file name and its extension seperately we can now eaisly rename file name.

        //===== Adding some text in begining and end of the file name
        fileNameWithoutExtension = "AddedText-" + fileNameWithoutExtension + "-AddedText";

        //===== Now lets upload the renamed file.

        flUpload.PostedFile.SaveAs(Server.MapPath("/"+ fileNameWithoutExtension + fileExtension));




    }

 

 
We are nothing without our users ! You can help us offer even more high quality content. Please share our page !
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
1 + 7 =
 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2017 CodingFusion