我希望能够将文件上传到我的服务器上。
我知道我的代码有效,我无法弄清楚路径名称是怎么回事,以及如何将其设置为网站目录。
这是我的c#
protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
{
string uploadFolder = "~/files/";
string fileName = e.UploadedFile.FileName;
e.UploadedFile.SaveAs(uploadFolder + fileName);
e.CallbackData = fileName;
}
这是我在尝试上传文件时收到的错误消息
Could not find a part of the path 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\~\files\project_questionnaire.doc'.
我已经为uploadFolder尝试了一切......“../files”“files /”“/ files /”等。
任何帮助将不胜感激!
答案 0 :(得分:10)
protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
{
string uploadFolder = Server.MapPath("~/files/");
string fileName = e.UploadedFile.FileName;
e.UploadedFile.SaveAs(uploadFolder + fileName);
e.CallbackData = fileName;
}
有关优秀指南,请参阅here。