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?

5

2 Answers

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)); 
0
 string createfolder = "/tmp/jobres/" + uId; System.IO.Directory.CreateDirectory(createfolder); AsyncFileUpload1.SaveAs(Path.Combine(createfolder,AsyncFileUpload1.PostedFile.FileName)); 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like