1

I want to upload a file using FileUpload Control in asp.net and i'm using the following code to do that:

string filename1 = System.IO.Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs("C:\\Users\\admin\\Desktop\\ExperimentForFolder\\" + filename1);

i also tried

FileUploadControl.SaveAs(@"C:\Users\admin\Desktop\ExperimentForFolder\" + filename1);

But it is still freaking out. I don't understand what is wrong. Can you please help me.

Thanks in anticipation

6
  • 1
    may be permission denied? Commented May 1, 2011 at 13:53
  • @SLaks postimage.org/image/mh0rog4k Commented May 1, 2011 at 13:55
  • 2
    That error might mean you try to upload big file.. try small simple text file of few Kilobytes. Commented May 1, 2011 at 13:59
  • @Shadow you are right !! How can i then upload large files ? Commented May 1, 2011 at 14:07
  • What IIS you have? Anyway, you need to change the configuration files: stackoverflow.com/questions/4971071/… Commented May 1, 2011 at 14:11

2 Answers 2

4

Why do you need to save the file to your machine's Desktop?

Your ultimate option should be to use your Application Folder. It can be done like...

FileUpload1.SaveAs(Server.MapPath("~/AppFolderName/" + FileName));
Sign up to request clarification or add additional context in comments.

6 Comments

@Muhammad how can i get the application folder physical path? I understand using ~ (tilde) symbol would take you to the application root folder, but how can i access the file path (i mean full physical path to the file) again so that i allow users to download the component which was uploaded by me ?
Server.MapPath function is what you need. try to explore this method workoing.
@Muhammad how can i read the contents of the uploaded file and store in some string variable ? How can i do that ?
What do you mean by Contents ? I not full understand your question.
yes, First of you have to put some app folder, then you can read the file using System.IO.File.Read(AppFolderPath);
|
1

You need permissions over the place you store the file into... don't store in the server desktop.

Try this for start:

FileUploadControl.SaveAs(Server.MapPath(filename1));

This will store the file in the same place as your .aspx file, if it works you can then create separate folder there then change the code to:

FileUploadControl.SaveAs(Server.MapPath("ExperimentForFolder/" + filename1));

2 Comments

How can i get the application folder full physical path ?
Server.MapPath(filename1) will return full physical path.

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.