2016-06-14 83 views
0

我一直只在IE中得到這個問題,任何想法爲什麼。所有在我的本地機器和Chrome上都可以正常工作,但IE不支持。 Web MVC應用程序基本上將用戶文件上傳到指定的服務器位置。該應用程序位於IIS 8.5中。我已經給運行應用程序池的用戶帳戶訪問指定的文件夾。找不到路徑'C: Users Username Desktop GPUpdate.xlsx'的一部分。只有在IE的ASP.NET

請參閱下面的代碼。

public ActionResult Upload(HttpPostedFileBase file) 
    { 

     List<CleanSupplierClaim> supplierClaimsData = new List<CleanSupplierClaim>(); 

     try 
     { 
      if (file.ContentLength > 0) 
      { 



       var fileName = Path.GetFileName(file.FileName); 

       var targetPath = Server.MapPath("/upload"); 
       if (!Directory.Exists(targetPath)) 
       { 
        Directory.CreateDirectory(targetPath); 
        file.SaveAs(Path.Combine(targetPath, fileName)); 
       } 
       else 
       { 

        file.SaveAs(Path.Combine(targetPath, fileName));  
       } 

任何想法可能是什麼問題。

我在下面添加了視圖代碼。

@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{ 
    <form action="Upload" method="post" enctype="multipart/form-data"> 
     <table style="margin-top:150px"> 
      <tr> 
       <td> 
        <label for="file"> Filename</label> 
       </td> 
       <td> 
        <input type="file" name="file" id="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,.xlsm" /> 
       </td> 
       <td> 
        <input type="submit" value="Upload" id="uploadbutton" onclick="showProgressLoadingSpinner()" /> 
       </td> 
      </tr> 
     </table> 

    </form> 
} 
+0

嘗試比其他不同的文件夾 'C:\ Users \用戶名\桌面\ GPUpdate.xlsx' - 這條道路是專門針對你或登錄的用戶配置文件。它可能在開發過程中工作,因爲IIS使用您的用戶名稱作爲應用程序池。嘗試像C:\ Uploads一樣的東西。 –

+0

Server.MapPath(「/ upload」)解析爲什麼? –

+0

@EddiePaz路徑'C:\ Users \ UserName \ Desktop \ FileName.xlsx'是用戶嘗試上傳的文件可能已保存的位置,我不確定每個用戶將保存文件的位置,它可能位於其上的任何位置本地機 – Papi

回答

0

嘗試改變

var targetPath = Server.MapPath("/upload"); 

var targetPath = Server.MapPath("~/upload"); 
+0

我試過改變,但仍然沒有運氣。這個問題只能在IE中找到。版本是11 – Papi

+0

你可以在調用方法時顯示如何設置文件參數嗎? –

+0

我已經做了編輯並在 – Papi

相關問題