-1

文件夹权限很好。它不会给我一个错误。我单击下面调用此函数的上传按钮,完成后,我上传的文件不存在。有任何想法吗?谢谢!

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;
        }
    }
}
4

2 回答 2

2

这应该 -->("C:/inetpub/wwwroot/w4/DanyaWebReports/Data" + 文件名);

是这样 -->("C:/inetpub/wwwroot/w4/DanyaWebReports/Data/" + 文件名);

于 2013-01-07T22:26:06.647 回答
2

看着这条线

fileUpload.SaveAs("C:/inetpub/ ------ directory --------/Data" + filename);

文件保存在目录------目录--------

例如文件名 this.jpg 代码提出的文件将是 Datathis.jpg 并将保存在文件夹 ------ 目录 --------

如果要保存在网站的 Data 目录中,请尝试

fileUpload.SaveAs(Server.MapPath("Data")+"\\"+filename);
于 2013-01-07T22:26:25.870 回答