2012-07-25 29 views
0

我無法通過asp上傳文件:FileUpload總是FileUpload1.HasFile爲false 以下是我的代碼,我嘗試上傳文件,但不幸的是仍然我無法上傳文件無法上傳文件的asp:FileUpload在asp.net 3.5與c#2.0

ASPX代碼

背後的C#代碼

protected void btSave_Click(object sender, EventArgs e) 
{ 
    try 
    { 
      noteFile = ""; 
      /*File is existed or not cheked**/ 
      if (FileUpload1.HasFile) 
      { 
       /*File Size Checked*/ 
       if (FileUpload1.FileBytes.Length < 1024 * 1000) 
       { 
        /*File Type Checked*/ 
        string fileType=Path.GetExtension(FileUpload1.FileName); 
        if (fileType == ".xls" || fileType == ".doc") 
        { 
         /*get the last 'noteID' and add 1 to noteID*/ 
         dt.Clear(); 
         dt = dConnect.noteInfo(0, "", "", "", "", "", "", "", "admin"); 
         noteID = 0; 

         /*Check the file name if any singal gile is save then need to delete it*/ 
         dt.Clear(); 
         dt = dConnect.noteInfo(0, "", "", "", "", "", "", dt.Rows[0]["noteID"].ToString() + '_', "byAdminFile"); 
         exceprionString = ""; 
         exceprionString = dConnect.exceptionMessage(); 

         if (dt.Rows.Count == 0 && exceprionString.Equals("")) 
         { 
          noteID = 1 + Convert.ToInt32(dt.Rows[0]["noteID"].ToString()); 

          FileUpload1.SaveAs(Server.MapPath("~/note") + noteID.ToString() + '_' + FileUpload1.FileName); 

          noteFile = noteID.ToString() + '_' + FileUpload1.FileName; 
         } 
         else 
         { 
          noteFile = ""; 
          SMS("Only One File Can Stor Per Note"); 
         } 
        } 
        else 
         SMS("Only Word or Excel File Can Upload"); 

       } 
       else 
        SMS("File Size Should Not More Than 1 MB"); 
      } 
      else 
      { 
       noteFile = ""; 
       SMS(FileUpload1.FileName.ToString()); 
      } 

    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
}  
+0

你忘了標記的文件大小 – 2012-07-25 05:36:20

回答

0

請檢查您的文件中包含一些數據。我正面臨與空白文件相同的問題。我在空白文件中添加了一些文本,並解決了我的問題。

,並檢查您可以嘗試使用下面的代碼

if(FileUpload1.PostedFile.ContentLength > 1048576);