找不到路径'C:\ Users \ Username \ Desktop \ GPUpdate.xlsx'的一部分。只有在IE的ASP.NET
问题描述:
我一直只在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>
}
尝试比其他不同的文件夹 'C:\ Users \用户名\桌面\ GPUpdate.xlsx' - 这条道路是专门针对你或登录的用户配置文件。它可能在开发过程中工作,因为IIS使用您的用户名称作为应用程序池。尝试像C:\ Uploads一样的东西。 –
Server.MapPath(“/ upload”)解析为什么? –
@EddiePaz路径'C:\ Users \ UserName \ Desktop \ FileName.xlsx'是用户尝试上传的文件可能已保存的位置,我不确定每个用户将保存文件的位置,它可能位于其上的任何位置本地机 – Papi