我创建新文件夹,但如何保存文件,请帮助我。
string createfolder = "E:/tmp/jobres/" + uId;
System.IO.Directory.CreateDirectory(createfolder);
AsyncFileUpload1.SaveAs(Server.MapPath("/tmp/jobres/" + AsyncFileUpload1.PostedFile.FileName));
但如何将我的文件存储在已创建的文件夹中?
答案 0 :(得分:3)
由于您在保存时使用MapPath
,因此您的目录可能会在错误的位置创建。在创建目录时,您应该使用MapPath
:
var createfolder = Path.Combine(Server.MapPath("/tmp/jobres/"), uId.ToString());
System.IO.Directory.CreateDirectory(createfolder);
AsyncFileUpload1.SaveAs(Path.Combine(createdFolder, AsyncFileUpload1.PostedFile.FileName));
答案 1 :(得分:2)
string createfolder = "/tmp/jobres/" + uId;
System.IO.Directory.CreateDirectory(createfolder);
AsyncFileUpload1.SaveAs(Path.Combine(createfolder,AsyncFileUpload1.PostedFile.FileName));