-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInternetFileDownloader.cs
40 lines (32 loc) · 1.08 KB
/
InternetFileDownloader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.IO;
using System.Net;
namespace TestDataManager
{
public class InternetFileDownloader
{
private const string TMP_DATA_PATH = "KelpNet/TestData/";
static readonly string TmpFolderPath = Path.Combine(Path.GetTempPath(), TMP_DATA_PATH);
public static string Download(string url, string fileName)
{
WebClient downloadClient = new WebClient();
string savedPath = Path.Combine(TmpFolderPath, fileName);
if (File.Exists(fileName))
{
return fileName;
}
// Check and download files
if (!File.Exists(savedPath))
{
Console.WriteLine(fileName + "downloaded");
if (!Directory.Exists(TmpFolderPath))
{
Directory.CreateDirectory(TmpFolderPath);
}
// Start asynchronous download
downloadClient.DownloadFileTaskAsync(new Uri(url), savedPath).Wait();
}
return savedPath;
}
}
}