我現在正在學習 C#,我正在制作一種用戶可以下載某些檔案的工具。但是,我希望下載的檔案最終位于“下載”檔案夾中,而不是“bin\Realse”中
之前還創建了路徑: [(System.IO.Directory.CreateDirectory("C:\Users\" Environment.UserName.ToString() "\Downloads\Glebi-Tool\Games");) ]
代碼:
private void btnMinecraft_Click(object sender, EventArgs e)
{
wc.DownloadFileCompleted = new AsyncCompletedEventHandler(FileDownloadComplete1);
Uri rarurl = new Uri("https://cdn.discordapp.com/attachments/1016411808887746570/1016422145229848686/MfW10_Fix_Repair_UWP_Generic.rar");
wc.DownloadFileAsync(rarurl, "MfW10_Fix_Repair_UWP_Generic.rar", @"C:\\Users\\" Environment.UserName() "\\Downloads\\Glebi-Tool\\Games");
}
uj5u.com熱心網友回復:
所以我設法自己弄清楚了。這是答案:
private void btnMinecraft_Click(object sender, EventArgs e)
{
if (System.IO.File.Exists(@"C:\\Users\\" Environment.UserName "\\Downloads\\Glebi-Tool\\Games\\MfW10_Fix_Repair_UWP_Generic.rar"))
{
MessageBox.Show("Already Downlaoded");
}
else
{
{
using (var wc = new WebClient())
wc.DownloadFile("https://cdn.discordapp.com/attachments/1016411808887746570/1016422145229848686/MfW10_Fix_Repair_UWP_Generic.rar", "MfW10_Fix_Repair_UWP_Generic.rar");
}
string fromPath = Path.Combine(Application.StartupPath, "MfW10_Fix_Repair_UWP_Generic.rar");
string toPath = Path.Combine(@"C:\\Users\\" Environment.UserName "\\Downloads\\Glebi-Tool\\Games", "MfW10_Fix_Repair_UWP_Generic.rar");
// Move the file.
File.Move(fromPath, toPath);
MessageBox.Show("Download Completed");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/506406.html
