public void InfoFiles(ref Content Files, ref DataUser User, ref ListView ListFiles, string Folder, bool forward) { if (User.CheckIntConnect()) { ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(User.Data.UrlServer, Folder, User.Data.Name, User.Data.Password); Request.Accept = "*/*"; Request.Headers.Add("Depth: 1"); Request.Method = "PROPFIND"; HttpWebResponse Response = Act.GetResponseStream(Request); Stream ResponseStream = Response.GetResponseStream(); Files.All.Clear(); ListFiles.Items.Clear(); Files.SetInfoContent(ResponseStream, ref Files.All, ref ListFiles); ResponseStream.Close(); Response.Close(); if (forward) { if (!User.Data.Hrefs.Contains(Folder)) { User.Data.Hrefs.Add(Folder); } } else { User.Data.Hrefs.RemoveAt(User.Data.Hrefs.Count - 1); } } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } } } else { if (GotMessage != null) { GotMessage("Вы не подключены к Интернету!"); } } }
private void Download(object it) { if (InterUser.CheckIntConnect()) { int index = (int)it; if (InterFiles.All[index].ContentType != "d:collection") { ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(InterUser.Data.UrlServer, InterFiles.All[index].Href, InterUser.Data.Name, InterUser.Data.Password); Request.Method = WebRequestMethods.Http.Get; HttpWebResponse Response = Act.GetResponseStream(Request); int byteTransferRate = 8192; byte[] bytes = new byte[byteTransferRate]; int bytesRead = 0; long totalBytesRead = 0; Directory.CreateDirectory("./Download/"); long contentLength = long.Parse(Response.GetResponseHeader("Content-Length")); Stream NewStream = Response.GetResponseStream(); FileStream NewFileStream = new FileStream("./Download/" + InterFiles.All[index].DisplayName, FileMode.Create, FileAccess.Write); do { bytesRead = NewStream.Read(bytes, 0, bytes.Length); if (bytesRead > 0) { totalBytesRead += bytesRead; NewFileStream.Write(bytes, 0, bytesRead); } }while (bytesRead > 0); NewStream.Close(); NewFileStream.Close(); Response.Close(); } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } } } } handle.Set(); }