示例#1
0
文件: IFolder.cs 项目: HaKDMoDz/eStd
        /// <summary>
        /// Creates a resource with a specified name.
        /// </summary>
        /// <param name="name">Name of the new resource.</param>
        /// <returns>Newly created resource.</returns>
        public IResource CreateResource(string name)
        {
            WebDavResource resource = new WebDavResource();
            try
            {
                resource.SetHref(new Uri(this.Href.AbsoluteUri + name));
                NetworkCredential credentials = (NetworkCredential) this._credentials;
                string auth = "Basic " +
                              Convert.ToBase64String(
                                  System.Text.Encoding.Default.GetBytes(credentials.UserName + ":" +
                                                                        credentials.Password));
                HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(resource.Href);
                request.Method = "PUT";
                request.Credentials = credentials;
                request.ContentType = "text/xml";
                request.Accept = "text/xml";
                request.Headers["translate"] = "f";
                request.Headers.Add("Authorization", auth);
                using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
                {
                    if (response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.NoContent)
                    {
                        this.Open(this.Href);
                        resource = (WebDavResource) this.GetResource(name);
                        resource.SetCredentials(this._credentials);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return resource;
        }
示例#2
0
文件: IFolder.cs 项目: HaKDMoDz/eStd
 /// <summary>
 /// Gets the specified resource from server.
 /// </summary>
 /// <param name="name">Name of the resource.</param>
 /// <returns>Resource corresponding to requested name.</returns>
 public IResource GetResource(string name)
 {
     IHierarchyItem item =
         this._children.Where(i => i.ItemType == ItemType.Resource && i.DisplayName == name).Single();
     WebDavResource resource = new WebDavResource();
     resource.SetCredentials(this._credentials);
     resource.SetHierarchyItem(item);
     return resource;
 }