skazantsev / WebDavClient

Asynchronous cross-platform WebDAV client for .NET Core
MIT License
155 stars 30 forks source link

The DEPTH option "1,noroot" should be added #45

Open zspasojevic opened 4 years ago

zspasojevic commented 4 years ago

Hi,

The plugin as I see currently only supports options to fetch properties for resource itself, resource + children and the infinite one. In a situation where I need to fetch the files tree I want to fetch only children for each call and that can be done with "1,noroot" depth setting. For clarification, at the moment when I fetch the "Images" folder props I get => Images folder, image1.jpg, image2.jpg etc. I want only the images, not the selected folder.

image

https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2003/aa142960%28v%3dexchg.65%29

skazantsev commented 4 years ago

Thank you for reporting this. I didn't know about 1,noroot, it turns out to be an extension from Microsoft and not a part of the original spec (as well as infinity,noroot). I marked it as up-for-grabs and I can accept a Pull Request for this if you or someone else wants to add support for it (would be nice to include infinity,noroot as well).

Could be worked around by sending a custom Depth header, though

Headers = new List<KeyValuePair<string, string>>
{
  new KeyValuePair<string, string>("Depth", "1,noroot")
}
zspasojevic commented 4 years ago

Thanks for the response. I'll be glad to make a PR for this. Workaround is giving me a 400 bad request, maybe I'm not using it in the right way. Can you show me an example of setting the PropfindParameters to send with this custom header.

skazantsev commented 4 years ago

Sure, here is an example:

var propfindParams = new PropfindParameters
{
  Headers = new List<KeyValuePair<string, string>>
  {
    new KeyValuePair<string, string>("Depth", "1,noroot")
  }
};
var response = await client.Propfind("__URL__", propfindParams);

I checked that a request with this header is sent but I cannot check that it actually works since I don't have a WebDAV server that supports this header.

I wonder why the server returns 400 in your case, probably there's error details in the response body. Fiddler or other HTTP debugging tools could help here.