-
Notifications
You must be signed in to change notification settings - Fork 11
Xamarin
As the Portable WebDAV Library targets .NETStandard 1.1, it can also be used in Xamarin projects (UWP/iOS/Android).
This page lists some topics when developing for iOS/Android using the Portable WebDAV Library.
When it comes to relative Uris, the class System.Uri
behaves a little different on iOS/Android which can result in exceptions raised in the library.
Have a look at following example:
var myUri = new Uri("/folder", UriKind.RelativeOrAbsolute);
- On Windows systems, the Uri created is a relative Uri with no
Scheme
andHost
. - On iOS/Android, the Uri created is an absolute Uri (
file:///folder
) with theScheme
'file'.
This can result in exceptions thrown in the library code ("The absolute URIs provided do not have the same host/scheme"), e.g. on WebDavSession.ListAsync
:
var webDavSession = new WebDavSession(new Uri("http://localhost"), new NetworkCredential("user", "pass"));
var items = await webDavSession.ListAsync("/folder"); // Will raise exception
Solution:
As of version 0.7.1.0, the Portable WebDAV Library handles these issues internally.
When an absolute Uri
with the Scheme
"file" is passed to the library, it gets converted into a relative Uri
automatically.
When using the library on Xamarin projects, creating a new Uri
by using this Uri
constructor should be avoided: new Uri("/folder", UriKind.RelativeOrAbsolute)
.
But as a little helper, the class UriHelper
from the library now contains two new methods (CreateUriFromUrl
and TryCreateUriFromUrl
) which can be used to create a Uri
from a URL string.
Currently unknown WebDAV properties are not supported when using the Portable WebDAV Library on Xamarin. This is due to the fact that these AdditionalProperties
of Prop
cannot be (de-) serialized on Xamarin. The operations will throw an exception that the XmlAnyElementAttribute
cannot be applied to XElement
arrays.
As a workaround, use WebDavClient
providing XML strings directly (e.g. for PropFind). These XML strings need to be created by the client using the library.