/// <summary> /// Returns IFolder corresponding to path. /// </summary> /// <param name="path">Path to the folder.</param> /// <returns>Folder corresponding to requested path.</returns> public IFolder OpenFolder (Uri path) { WebDavFolder folder = new WebDavFolder(); folder.SetCredentials(this.Credentials); folder.Open(path); return folder; }
/// <summary> /// Creates new folder with specified name as child of this one. /// </summary> /// <param name="name">Name of the new folder.</param> /// <returns>IFolder</returns> public IFolder CreateFolder(string name) { WebDavFolder folder = new WebDavFolder(); try { NetworkCredential credentials = (NetworkCredential) this._credentials; HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(this.Href.AbsoluteUri + name); request.Method = "MKCOL"; request.Credentials = credentials; string auth = "Basic " + Convert.ToBase64String( System.Text.Encoding.Default.GetBytes(credentials.UserName + ":" + credentials.Password)); request.Headers.Add("Authorization", auth); Console.WriteLine("Create WebDav Folder: " + this.Href.AbsoluteUri + name); using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { Console.WriteLine("Response..."); if (response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.NoContent) { folder.SetCredentials(this._credentials); folder.Open(this.Href.AbsoluteUri + name + "/"); } } } catch (Exception e) { Console.WriteLine(e.Message); } return folder; }