public void downloadFile(string localpath, string webpath, ListView weblistview, UserInformation userinformation, FileInformationForListView.RefreshListViewSuccess refresh, UpYunLibrary.UpYun.SetProgressBar setprogressbar) { ArrayList filename = new ArrayList();//foldername = new ArrayList(); for (int i = 0; i < weblistview.SelectedItems.Count; i++) { if (!weblistview.SelectedItems[i].SubItems[1].Text.Equals("0 B")) filename.Add(weblistview.SelectedItems[i].Text); } fileinformationforlistview.downloadFile(localpath, webpath, filename, userinformation, refresh, setprogressbar); }
public void downloadFile(string localpath, string webpath, ArrayList filenamelist, UserInformation userinformation, FileInformationForListView.RefreshListViewSuccess refresh, UpYunLibrary.UpYun.SetProgressBar setprogressbar) { Thread thread = new Thread(() => downloadFileByUpYun(localpath, webpath, filenamelist, userinformation, refresh, setprogressbar)); thread.IsBackground = true; thread.Start(); }
public void downloadFileByUpYun(string localpath, string webpath, ArrayList filenamelist, UserInformation userinformation, FileInformationForListView.RefreshListViewSuccess refresh, UpYunLibrary.UpYun.SetProgressBar setprogressbar) { int SelectNum = filenamelist.Count, count; FileStream Fs = null; try { for (int i = 0; i < SelectNum; i++) { Fs = new FileStream(localpath + filenamelist[i], FileMode.Create); string CopyLink = ""; if (userinformation.Url.Substring(userinformation.Url.Length - 1).Equals("/")) CopyLink = userinformation.Url + webpath.Substring(1) + filenamelist[i]; else CopyLink = userinformation.Url + "/" + webpath.Substring(1) + filenamelist[i]; HttpWebRequest Hwr = (HttpWebRequest)WebRequest.Create(CopyLink); HttpWebResponse rps = (HttpWebResponse)Hwr.GetResponse(); Stream stream = rps.GetResponseStream(); byte[] byts = new byte[rps.ContentLength]; System.Threading.Timer FileTm = new System.Threading.Timer(CalculateSpeedTime, null, 0, 1000); while ((count = stream.Read(byts, 0, 5000)) != 0) { TempDataSize += count; Fs.Write(byts, 0, count); setprogressbar(false, filenamelist[i].ToString(), (Fs.Length / Convert.ToDouble(byts.Length)) * 100.0, TransSpeed); } } } catch (Exception ex) { refresh(false); XtraMessageBox.Show(ex.ToString()); } finally { refresh(true); Fs.Close(); } }
//public void upFolder(string webpath, string localpath, ArrayList foldername, UserInformation userinformation, RefreshListViewSuccess refresh, UpYunLibrary.UpYun.SetProgressBar setprogressbar) //{ //} public void upFileByUpYun(string localpath, string webpath, ArrayList filenamelist, UserInformation userinformation, RefreshListViewSuccess refresh, UpYunLibrary.UpYun.SetProgressBar setprogressbar) { int SelectNum = filenamelist.Count; try { for (int i = 0; i < SelectNum; i++) { string localpath_up = localpath + filenamelist[i]; FileStream fs = new FileStream(localpath_up, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); byte[] postArray = r.ReadBytes((int)fs.Length); string webpath_up = webpath + filenamelist[i]; userinformation.upYun.writeFile(webpath_up, postArray, true, setprogressbar); fs.Close(); } } catch (Exception ex) { refresh(false); XtraMessageBox.Show(ex.ToString(), "错误信息"); } refresh(true); }