首页 > 解决方案 > 值不能为空。参数名称:path1

问题描述

我正在尝试使用以下设置下载文件。问题是,我得到一个例外说

Value cannot be null. Parameter name: path1

出于某种原因,它DownloadLocationT是空的,我不知道为什么。

if (dl.EndsWith(".las"))
    {
        dl = dl.Replace("{", "").Replace("}", "").TrimEnd("las".ToCharArray()) + "zip";
    }
    FileInfo fi = new FileInfo(dl);
    var newFile = Path.Combine(Startup.appSettings.DownloadLocationT, fi.Name);
        if (System.IO.File.Exists(newFile))
            {
                System.IO.File.Delete(newFile);
                Thread.Sleep(2000);
            }
         System.IO.File.Copy(dl, newFile);
         return Ok(dl);

这是appSettings

public class AppSettings
    {
        public string ArecGISConnString { get; set; }
        public string AllowOrigin { get; set; }
        public string DMSUrl { get; set; }
        public string DownloadLocation { get; set; }
        public string DownloadLocationT { get; set; }
        public string AdminEmailToVerify { get; set; }
        public string PoTreePath { get; set; }
        public string PoTreeOut { get; set; }
        public string MetadataPath { get; set; }
        public string Referer { get; set; }
    }

和实际的appSettings

"AppSettings": {
   //shortened for brevity
    "DownloadLocationT": "C:\\Downloads",
    "AdminEmailToVerify": "info@info.com"
  }

我得到一个异常说它Value cannot be null. Parameter name: path1 似乎找不到路径或文件夹DownloadLocationT

标签: c#.net-coredownloadpath

解决方案


推荐阅读