我正在尝试将文件下载到Azure WebJob的临时文件夹中...

 public static string DownloadLogo(string url)
    {
        var fileName = $"{Path.GetTempPath()}logo.png";

        using (var client = new WebClient())
        {
            client.DownloadFile(url, fileName);
        }
        return fileName;
    }


我收到以下错误:

Exception: System.Net.WebException: Could not find a part of the path 'D:\local\Temp\jobs\continuous\BillingProcessor\t2argeef.l1b\public\logo.png'. ---> System.Net.WebException: Could not find a part of the path 'D:\local\Temp\jobs\continuous\BillingProcessor\t2argeef.l1b\public\logo.png'. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\local\Temp\jobs\continuous\BillingProcessor\t2argeef.l1b\public\logo.png'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)
   at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
   --- End of inner exception stack trace ---
   at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
   at System.Net.FileWebRequest.GetResponseCallback(Object state)
   --- End of inner exception stack trace ---
   at System.Net.WebClient.DownloadFile(Uri address, String fileName)


单独注意:


我导航到D:\ local \ Temp \ jobs \ continuous \ BillingProcessor \ t2argeef.l1b \,但公用文件夹不存在
我有相同的代码运行其他webjob部署而没有任何问题

最佳答案

我尝试了您的代码,但效果很好。但是我的文件名是D:\local\Temp\logo.png,与您的文件名不同。

所以我试图将路径更改为{Path.GetTempPath()}t2argeef.l1b/public/logo.png,然后它将显示与您相同的错误。因此,现在我确定问题是文件夹不存在。

我解决问题的方法是转到Kudu并创建如pic所示的文件夹。然后运行webjob,效果很好。这是result

而且我认为您的kudu环境TEMP已更改,这导致您的临时文件夹目录错误。因此,您可以使用TEMPKudu console或Kudu环境page中检查set环境。

如果仍有问题,请告诉我。

关于c# - 尝试在WebJob中使用TempPath时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53602012/

10-12 22:36