private static List<WebDavResource> ExtractResources(Stream strm, string rootpath, string fullpath) { List<WebDavResource> webDavResources = new List<WebDavResource>(); try { TextReader treader = new StreamReader (strm); string xml = treader.ReadToEnd (); treader.Dispose (); XDocument xdoc = XDocument.Parse(xml); foreach (XElement element in xdoc.Descendants(XName.Get("response", "DAV:"))) { WebDavResource resource = new WebDavResource(); // Do not add hidden files // Hidden files cannot be downloaded from the IIs // For further information see http://support.microsoft.com/kb/216803/ var prop = element.Descendants(XName.Get("prop", "DAV:")).FirstOrDefault(); var node = prop.Element(XName.Get("ishidden", "DAV:")); if ((node != null) && (node.Value == "1")) continue; node = prop.Element(XName.Get("displayname", "DAV:")); if (node != null) resource.Name = node.Value; node = element.Element(XName.Get("href", "DAV:")); if (node != null) { Uri href; if (Uri.TryCreate(node.Value, UriKind.Absolute, out href)) resource.Uri = href; else if (Uri.TryCreate(string.Format("{0}{1}",fullpath,node.Value), UriKind.Absolute, out href)) resource.Uri = href; } node = prop.Element(XName.Get("getcontentlength", "DAV:")); if (node != null) resource.Size = int.Parse(node.Value, CultureInfo.CurrentCulture); node = prop.Element(XName.Get("creationdate", "DAV:")); if (node != null) resource.Created = DateTime.Parse(node.Value, CultureInfo.CurrentCulture); node = prop.Element(XName.Get("getlastmodified", "DAV:")); if (node != null) resource.Modified = DateTime.Parse(node.Value, CultureInfo.CurrentCulture); // Check if the resource is a collection node = prop.Element(XName.Get("resourcetype", "DAV:")).Element(XName.Get("collection", "DAV:")); resource.IsDirectory = node != null; node = prop.Element(XName.Get("getcontenttype", "DAV:")); if (node != null) resource.ContentType = node.Value; node = prop.Element(XName.Get("getetag", "DAV:")); if (node != null) resource.Etag = node.Value; node = prop.Element(XName.Get("quota-used-bytes", "DAV:")); if (node != null) resource.QuotaUsed = long.Parse(node.Value); node = prop.Element(XName.Get("quota-available-bytes", "DAV:")); if (node != null) resource.QutoaAvailable = long.Parse(node.Value); if (resource.Name == null && resource.Uri != null) { if (resource.IsDirectory) resource.Name = resource.Uri.Segments.Last().TrimEnd(new char[]{'/'}); else resource.Name = resource.Uri.Segments.Last(); if (resource.Uri.AbsolutePath.Equals(rootpath)) resource.Name = "/"; } webDavResources.Add(resource); } } catch (Exception e) { // TODO: Implement better error handling Debug.WriteLine(e.Message); webDavResources = new List<WebDavResource>(); } return webDavResources; }
private static List <WebDavResource> ExtractResources(Stream strm, string rootpath, string fullpath) { List <WebDavResource> webDavResources = new List <WebDavResource>(); try { TextReader treader = new StreamReader(strm); string xml = treader.ReadToEnd(); treader.Dispose(); XDocument xdoc = XDocument.Parse(xml); foreach (XElement element in xdoc.Descendants(XName.Get("response", "DAV:"))) { WebDavResource resource = new WebDavResource(); // Do not add hidden files // Hidden files cannot be downloaded from the IIs // For further information see http://support.microsoft.com/kb/216803/ var prop = element.Descendants(XName.Get("prop", "DAV:")).FirstOrDefault(); var node = prop.Element(XName.Get("ishidden", "DAV:")); if ((node != null) && (node.Value == "1")) { continue; } node = prop.Element(XName.Get("displayname", "DAV:")); if (node != null) { resource.Name = node.Value; } node = element.Element(XName.Get("href", "DAV:")); if (node != null) { Uri href; if (Uri.TryCreate(node.Value, UriKind.Absolute, out href)) { resource.Uri = href; } else if (Uri.TryCreate(string.Format("{0}{1}", fullpath, node.Value), UriKind.Absolute, out href)) { resource.Uri = href; } } node = prop.Element(XName.Get("getcontentlength", "DAV:")); if (node != null) { resource.Size = int.Parse(node.Value, CultureInfo.CurrentCulture); } node = prop.Element(XName.Get("creationdate", "DAV:")); if (node != null) { resource.Created = DateTime.Parse(node.Value, CultureInfo.CurrentCulture); } node = prop.Element(XName.Get("getlastmodified", "DAV:")); if (node != null) { resource.Modified = DateTime.Parse(node.Value, CultureInfo.CurrentCulture); } // Check if the resource is a collection node = prop.Element(XName.Get("resourcetype", "DAV:")).Element(XName.Get("collection", "DAV:")); resource.IsDirectory = node != null; node = prop.Element(XName.Get("getcontenttype", "DAV:")); if (node != null) { resource.ContentType = node.Value; } node = prop.Element(XName.Get("getetag", "DAV:")); if (node != null) { resource.Etag = node.Value; } node = prop.Element(XName.Get("quota-used-bytes", "DAV:")); if (node != null) { resource.QuotaUsed = long.Parse(node.Value); } node = prop.Element(XName.Get("quota-available-bytes", "DAV:")); if (node != null) { resource.QutoaAvailable = long.Parse(node.Value); } if (resource.Name == null && resource.Uri != null) { if (resource.IsDirectory) { resource.Name = resource.Uri.Segments.Last().TrimEnd(new char[] { '/' }); } else { resource.Name = resource.Uri.Segments.Last(); } if (resource.Uri.AbsolutePath.Equals(rootpath)) { resource.Name = "/"; } } webDavResources.Add(resource); } } catch (Exception e) { // TODO: Implement better error handling Debug.WriteLine(e.Message); webDavResources = new List <WebDavResource>(); } return(webDavResources); }