0

i'm using the asp.net file upload control. What i'd like to be able to do is upload the and save it on the server as a different name. Can i do this or do i need to upload first and then figure out how to rename it once it's on the server. wondering what my options are. thanks

0

4 Answers 4

3
FileUpload.PostedFile.SaveAs

http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.saveas.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

You should just save the file with the required name as it is shown in the MSDN:

Uploading Files in ASP.NET 2.0

Comments

0
if (FileUpload.HasFile)
{
     string Prename = "PavanKumar";               
     string ext = System.IO.Path.GetExtension(FileUpload.PostedFile.FileName);
     disp.SaveAs(Server.MapPath("~/Admin/") + Prename +ext);
}

1 Comment

Just Get the Extension and add it to the Required filename You Required and Its Done
0

You can pass in the file name you want and pass it to the SaveAs method like...

Suppose you want to store your file in the UserFiles Folder that is on the root of your website:

FileUpload.PostedFile.SaveAs(Server.Mappath("~/UserFiles/") + "NewFileName");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.