简体   繁体   中英

how to create folder and save file in it using c#

I create new folder but how to save file in that please help me.

string createfolder = "E:/tmp/jobres/" + uId;    
System.IO.Directory.CreateDirectory(createfolder);
AsyncFileUpload1.SaveAs(Server.MapPath("/tmp/jobres/" + AsyncFileUpload1.PostedFile.FileName));

but how to store my file in created folder?

Since you are using MapPath on save, your directory may be created in the wrong spot. You should be using MapPath when creating your directory as well:

var createfolder = Path.Combine(Server.MapPath("/tmp/jobres/"), uId.ToString());    
System.IO.Directory.CreateDirectory(createfolder);
AsyncFileUpload1.SaveAs(Path.Combine(createdFolder, AsyncFileUpload1.PostedFile.FileName));
 string createfolder = "/tmp/jobres/" + uId;                           
 System.IO.Directory.CreateDirectory(createfolder);
 AsyncFileUpload1.SaveAs(Path.Combine(createfolder,AsyncFileUpload1.PostedFile.FileName));

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