文件夹权限很好。它没有给我一个错误。我点击上面按下这个功能的上传按钮,当它完成时,我上传的文件不在那里。有任何想法吗?谢谢!
protected void submitFile(object sender, EventArgs e){
if(fileUpload.HasFile)
{
try
{
if(
fileUpload.PostedFile.FileName.ToLower().Substring(fileUpload.PostedFile.FileName.Length - 3) == "doc" ||
fileUpload.PostedFile.FileName.ToLower().Substring(fileUpload.PostedFile.FileName.Length - 4) == "docx")
{
if(fileUpload.PostedFile.ContentLength < 512000)
{
string filename = Path.GetFileName(fileUpload.FileName);
filename = filename.Replace(" ", "");
fileUpload.SaveAs("C:/inetpub/ ------ directory --------/Data" + filename);
StatusLabel.Text = "Upload status: File uploaded complete.";
}
else
StatusLabel.Text = "Upload status: The file has exceded the maximum file size of 500 kb. Please ensure that the file is smaller than 500 kb and try again";
}
else
StatusLabel.Text = "Upload status: Only PDF and Microsoft Word files are accepted. Please try again.";
}
catch(Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
答案 0 :(得分:2)
应该这个 - &gt;(“C:/ inetpub / wwwroot / w4 / DanyaWebReports / Data”+ filename);
是这个 - &gt;(“C:/ inetpub / wwwroot / w4 / DanyaWebReports / Data /”+ filename);
答案 1 :(得分:2)
看这一行
fileUpload.SaveAs("C:/inetpub/ ------ directory --------/Data" + filename);
文件保存在目录------目录--------
中例如对于文件名this.jpg,代码提出的文件将是Datathis.jpg并将保存在文件夹------目录中--------
如果要保存在网站的数据目录中,请尝试
fileUpload.SaveAs(Server.MapPath("Data")+"\\"+filename);