简体   繁体   English

找不到路径“ xxx \\ xxx.xlsx”的一部分

[英]Could not find a part of the path 'xxx\xxx.xlsx'

I have a MVC application which utilized Open XML to upload excel files. 我有一个MVC应用程序,该应用程序利用Open XML上传Excel文件。 Everything works fine on my local machine, but as soon as I deploy it it doesn't seem to work and throws the above exception. 一切在我的本地计算机上都可以正常运行,但是一旦我部署它,它似乎就无法正常工作并抛出上述异常。 I have given permissions to the folder for user running in IIS, which is a AD account I created. 我已为在IIS(我创建的AD帐户)中运行的用户授予了该文件夹的权限。 But still throws the exception. 但是仍然抛出异常。 I have seen some posts about this but I am having no luck. 我已经看到了一些有关此的帖子,但是我没有运气。 Please see my code below and maybe advice on any changes. 请在下面查看我的代码,并就任何更改提出建议。

public ActionResult Upload(HttpPostedFileBase file, string sSheetName)
        {
            string sid = HttpContext.Session.SessionID;

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

            try
            {
                if (file.ContentLength > 0)
                {
                    var fileName = file.FileName;
                    var targetFolder = Server.MapPath("~/upload/");
                    string targetPath = Path.Combine(targetFolder, fileName);
                    file.SaveAs(targetPath);

将以下行添加到web.config中,以使用AD帐户运行应用程序。

<identity impersonate="true" userName="domain\user" password="password" />

Have a look at these troubleshooting items for you... They should get you going... 看看这些故障排除项目为您...它们应该帮助您...

  • Make sure "Enable parent paths" in IIS turned on 确保IIS中的“启用父路径”已打开
  • Try and log what the path on the server is actually been made of.... Given that the server/your local machine paths aren't completely identical, you might have issues there... 尝试记录服务器路径实际上是由什么组成的。...由于服务器/本地机器路径并不完全相同,因此那里可能存在问题...
  • Store the base URL in a configuration, and then append the folder structure from the root folder onwards. 将基本URL存储在配置中,然后从根文件夹开始追加文件夹结构。 So you would store yoursite.com as a configuration, and then append your folder configuration after.... That would make your file accessible. 因此,您将yoursite.com存储为配置,然后在其后追加文件夹配置...。这将使您的文件可访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM