여러 파일을 하나씩 다운로드하려면 어떻게해야합니까? 내 코드 사용.C에서 DownloadFileAsync를 사용하여 하나씩 여러 파일 다운로드
//Download File
public void DownloadFile(string url, string folderfile)
{
WebClient wc = new WebClient();
try
{
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadChanged);
wc.DownloadFileAsync(new Uri(url), folderfile);
}
catch (Exception ex)
{
MessageBox.Show("Error: \n\n" + ex.Message);
}
}
private void DownloadChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn/totalBytes * 100.0;
int percente = int.Parse(Math.Truncate(percentage).ToString());
PBar.Value = percente;
progress.Text = percente + " %";
size.Text = string.Format("{0} MB/{1} MB", (e.BytesReceived/1024d/1024d).ToString("0.00"), (e.TotalBytesToReceive/1024d/1024d).ToString("0.00"));
}
private void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show("Erro: " + e.Error.Message);
}
else
{
info.Text = "Download Success.";
}
}
public void CheckFileDownload()
{
string urlGame = "http://localhost/";
string Game = "Game.exe";
string Support = "Support.Xml";
string Info = "Info.xml";
if (!File.Exists(Game))
{
//Download Game
DownloadFile(urlGame + Game, Game);
info.Text = "Downloading: " + Game;
//If the game is downloading full
DownloadFile(urlGame + Info, Info);
DownloadFile(urlGame + Support, Support);
info.Text = "Updating information...";
}
}
private void Launcher_Load(object sender, EventArgs e)
{
CheckFileDownload();
}
게임을 다운로드 한 후 검사 점 파일을 업데이트해야하기 때문에.
여러 주제를 살펴 보았지만 성공하지 못했습니다. 도와 주신 모든 분들께 감사드립니다 ... 나쁜 영어로 죄송합니다.
감사합니다. 나는 매우 감사 할 것입니다 ...
처음부터 다운로드 링크가 모두 있습니까? – Niklas
안녕하세요. 네, 있어요! –
문제를 해결하는 데 도움이 되었습니까? – Niklas