2012-07-25 60 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);