我是根据返回文件列表,(包括URL)
foreach循环下载文件。
问题是,怎么在下载完成事件里获取 我这个下载完成的URL或者是其他的一些信息呢?
因为我要将这些信息入库。谢谢。
private void CompletedBin(object sender, AsyncCompletedEventArgs e)
WebClient WebC =(WebClient)sender;
string s = WebC.BaseAddress;
}
这样获取不到信息,
webclientURL下载C#WINFORM
foreach循环下载文件。
问题是,怎么在下载完成事件里获取 我这个下载完成的URL或者是其他的一些信息呢?
因为我要将这些信息入库。谢谢。
private void CompletedBin(object sender, AsyncCompletedEventArgs e)
WebClient WebC =(WebClient)sender;
string s = WebC.BaseAddress;
}
这样获取不到信息,
webclientURL下载C#WINFORM
??
string the_Info;
Process the_Process;
ProcessStartInfo the_StartInfo;/// <summary>
/// 压缩文件t
/// </summary>
public void CreatZip()
{
string srcFile = Server.MapPath("../Excel/Excels/" + Num + ".xlsx");
string srcFileOut = Server.MapPath("../Excel/Excels/" + Num + ".zip");
the_rar = "HaoZipC.exe";
the_Info = "a " + srcFileOut + " " + srcFile;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = "C:\\Program Files\\HaoZip\\";
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
}
谢谢 。我只是想知道我下载完成的文件URL就成
{
bool flag = true;
foreach (TMSService.TerminalFile file in termfile)
{ bool f = true;
if (File.Exists(@"" + path + "Filehash.xml"))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"" + path + "Filehash.xml");
XmlNode root = xmlDoc.DocumentElement;
XmlNode a = root.SelectSingleNode("Table1");
foreach (XmlNode item in a.ChildNodes)
{
string[] array = item.InnerText.Split(',');
if (array[1] == file.hashCode)
{ if (File.Exists(array[0]))
{
f = false;
fileinfo.Append(Path.GetFileName(file.fileUrl) + ""+file.fileTypeName+"\n");
labfileInfo.Text = fileinfo.ToString();
break;
}
else
{
flag = DownloadBin();
} } }
if (f)
{
flag = DownloadBin();
}
}
else
{
flag = DownloadBin();
}
} return flag; } public bool DownloadBin()
{ bool flag = true;
try
{
string pathdll = pathRS();
labfileBin.Text = Path.GetFileName(binName) + "(应用程序文件) (正在连接 )";
string nowtime = System.DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd HH:m:ss");
Directory.CreateDirectory(pathdll + "Download/" + nowtime);
string fileName = Path.GetFileName(binName);
string destPath = Path.Combine(pathdll + "Download/" + nowtime, fileName);
PathDll = destPath.Replace("\\", "/");
urlbin = destPath.Replace("\\", "/");
DirectoryInfo dd = new DirectoryInfo(pathdll + "Download/" + nowtime);
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(CompletedBin);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChangedBin);
webClient.DownloadFileAsync(new Uri(binName), destPath); }
catch (Exception)
{
labfileBin.Text = Path.GetFileName(binName) + "(应用程序文件)";
labfileBin.ForeColor = Color.Red;
flag = false;
}
return flag;
}
webClient.DownloadFileAsync(new Uri(binName), destPath);在下载前把BaseAddress的值设好。 webClient.BaseAddress = binName;
webClient.DownloadFileAsync(new Uri(binName), destPath);