简体   繁体   中英

Uploading a file using fileupload control in asp.net

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

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));

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM