2013-01-07 93 views
-1

文件夾權限是好的。它不會給我一個錯誤。我點擊下面這個函數的上傳按鈕,當它完成時,我上傳的文件不在那裏。有任何想法嗎?謝謝!asp.net文件上傳問題;文件沒有上傳

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

有史以來最好的標題? –

+0

謝謝。我也是這麼想。對不起,我改了它。 – Bender

+0

你是否附加了一個調試器並檢查了'SaveAs'部分是否被實際執行?或者你有什麼異常?基本上,你能否詳細說明你所嘗試過的? –

回答

2

應此 - >( 「C:/的Inetpub/wwwroot的/ W4/DanyaWebReports /數據」 +文件名);

be this - >(「C:/ inetpub/wwwroot/w4/DanyaWebReports/Data /」+ filename);

+0

YES!我很笨,我也是新手,謝謝!我想知道是誰把「Datatest.doc」放在我的應用程序文件夾裏。批量 – Bender

2

望着這條線

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

的文件被保存在目錄------目錄--------

例如,對於文件名this.jpg該代碼提出的文件將爲Datathis.jpg並將保存在文件夾------目錄--------

如果要保存在網站的Data目錄中,請嘗試

fileUpload.SaveAs(Server.MapPath("Data")+"\\"+filename);