ASP.NET MVC-将文件保存在本地网络中的网络附加存储(NAS)中

时间:2020-01-07 13:14:56

标签: c# asp.net-mvc file-upload

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

进行更改时,出现一个错误,提示找不到部分路径。

如何进行此更改?

我的代码:

//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));
          });

       }

0 个答案:

没有答案
相关问题