我在谷歌上查過,為自己嘗試了任何答案,但都沒有奏效。我想下載 2 個檔案并將它們都保存到用戶臨時檔案 (C:\Users%UserName%\AppData\Local\Temp)。我可以使用字串輕松找到臨時檔案 (string tempPath = Environment.GetEnvironmentVariable("TEMP");) 我現在無法比這更進一步。
uj5u.com熱心網友回復:
您可以直接下載到臨時檔案夾:
using System.Net;
string tempPath = Environment.GetEnvironmentVariable("TEMP");
using (var client = new WebClient())
{
client.DownloadFile("http://example.com/file/file1.txt", @$"{tempPath}\file.txt");
client.DownloadFile("http://example.com/file/file2.txt", @$"{tempPath}\file2.txt");
}
或者移動已經下載的檔案:
using System.IO;
string tempPath = Environment.GetEnvironmentVariable("TEMP");
File.Move(@"C:\User\Downloads\Filename.txt", @$"{tempPath}\file.txt");
File.Move(@"C:\User\Downloads\Filename2.txt", @$"{tempPath}\file2.txt");
@字串之前的 是字串文字,而$是字串插值,您可以稍后搜索這些不錯的功能。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/483186.html
下一篇:在C#中“按名稱”傳遞的引數
