2013-12-10 26 views
1

我的上傳表單顯示了這兩個錯誤信息,即使我的文檔是36kb,並且它表示它們仍然不工作超過100000.發生了什麼事?我正在從Web表單進行測試,並且在將控件放在服務器上時,它不會輸出更新後的錯誤消息,而是舊的。它也沒有正確上傳到文件結構(從外觀相同的文件夾內)上傳無法正常工作,不會給出正確的信息/文件太大/錯誤的文檔類型

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 


namespace FileUpload 
{ 
    //this backend for the web control will be used to upload a file that will have it's XML tags pulled and displayed on a page. 
    //this code checks if the fileupload control has input inside it, then proceeds to the next page with the document saved. 
    public partial class UploadFileControl : System.Web.UI.UserControl 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 
     //names the script manager which will be used when the user attempts to upload a form/gives an error if they incorrectly attempt to upload 
     protected void UploadButton_Click(object sender, EventArgs e) 
     { 
      //if file is located 
      if (FileUploadControl.HasFile) 
      { 
       try 
       { 
        //allow content type of document/docx 
        if (FileUploadControl.PostedFile.ContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") 
        { 
         //if the file is is less than 51mb 
         if (FileUploadControl.PostedFile.ContentLength < 10000) 
         { 
          //name the filename, find the path of the name 
          string filename = Path.GetFileName(FileUploadControl.FileName); 
          //path of server upload (we just need to save it as a variable to be found on the next page, as it will be made/deleted 
          FileUploadControl.SaveAs(Server.MapPath("~/") + filename); 
          //update the label with file uploaded 
          StatusLabel.Text = "Upload status: File uploaded!"; 

          //move onto template wizard page 
          Response.Redirect("http://portal.acoura.com/admin/templatewizard.aspx", false); 

          //will be used to grab the document string 
          return; 

         } 
         else 
          //display the size the file needs to be less than 
          StatusLabel.Text = "Upload status: The file has to be less than 10mb!"; 
        } 
        else 
         //tell the user only docx files are accepted 
         StatusLabel.Text = "Upload status: Only DOCX files are accepted!"; 
       } 
       catch (Exception ex) 
       { 
        //display the exception message, in which case it would be either size/type/if it's present 
        StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; 
       } 
      } 
     } 
    } 
} 

回答

1

您確定該ContentLength行嗎?也許,如果你改變這個

if (FileUploadControl.PostedFile.ContentLength < 10000) 

這個

if (FileUploadControl.PostedFile.ContentLength < 10485760) // 10mb 

代碼將成功運行

+0

乾杯。我在星期幾做了一個類似的帖子,也沒有人接受它,我不確定如何格式化。它現在成功地重定向並將文件上傳到目錄! – DevAL

相關問題