首页 > 解决方案 > ASP.NET MVC - 将文件保存在位于本地网络中的网络附加存储 (NAS) 中

问题描述

我需要更改保存文件的位置。它们被直接保存到应用程序中,但我将切换到公司网络上的路径。

在进行更改时,我收到一个错误,即找不到路径的一部分。

如何进行此更改?

我的代码:

//file Path's at WebConfig
<add key="TempUploadFolder" value="~\\naswebwin\web$\WEB_DESV\Apps-C\Farm-APL85\RDVE_RVEWEB" />
<add key="FinalUploadFolder" value="~\\naswebwin\web$\WEB_DESV\Apps-C\Farm-APL85\RDVE_RVEWEB\Apontamento" />


if (!string.IsNullOrWhiteSpace(model.FilePath))
     {
       //convert to list
       var fileList = model.FilePath.Split(';').Distinct().ToList();

       //for each file in the list, move from temporary folder to final folder
       model.FilePath = string.Join(";", fileList);

       string rootPath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings.Get("FinalUploadFolder"));
      _rootPathTempUpload = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings.Get("TempUploadFolder"));

      var files = Directory.EnumerateFiles(_rootPathTempUpload, "*.*", SearchOption.AllDirectories)
       .Where(s => fileList.Any(file => s.Contains(file)))
       .ToList();

         files.ForEach(fileToMove =>
         {
             var fileName = System.IO.Path.GetFileName(fileToMove);
             System.IO.File.Move(fileToMove, System.IO.Path.Combine(rootPath, fileName));
          });

       }

标签: c#asp.net-mvcfile-upload

解决方案


只需从您的上传路径中删除 ~ 符号,例如

<add key="TempUploadFolder" value="\\naswebwin\web$\WEB_DESV\Apps-C\Farm- 
 APL85\RDVE_RVEWEB\" />

推荐阅读