GithubHelp home page GithubHelp logo

decatec / portable-webdav-library Goto Github PK

View Code? Open in Web Editor NEW
46.0 8.0 11.0 3.38 MB

Moved to codeberg.org - https://codeberg.org/DecaTec/Portable-WebDAV-Library - The Portable WebDAV Library is a strongly typed, async WebDAV client library which is fully compliant to RFC 4918, RFC 4331 and "Additional WebDAV Collection Properties". It is implemented as .NETStandard 1.1 library in oder to be used on any platform supporting .NETStandard 1.1.

Home Page: https://decatec.de

License: Microsoft Public License

C# 100.00%
webdav portable uwp dotnet portable-webdav-library netstandard netcore xamarin mono multiplatform

portable-webdav-library's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

portable-webdav-library's Issues

Upload and download with progress?

Hello,

The release history mentions that it's possible to upload/download with progress, but that functionality is supported only for the UWP library variant.

Are there plans to support this on the .NET library side?

Regards,

Mark R.

In combination with OwnCloud based WebDAV, the Uri in the WebDavSessionListItem is wrong?

I'm using an OwnCloud based WebDAV (stackstorage.com) and when calling the

var session = new WebDavSession(...);
string path = "https://***.stackstorage.com/remote.php/webdav/root-folder";
var resources = await session.ListAsync(path);

The Uri property in the first WebDavSessionListItem is defined as
https://***.stackstorage.com/remote.php/webdav/root-folder/remote.php/webdav/root-folder/sub-folder/

Instead of

https://***.stackstorage.com/remote.php/webdav/root-folder/sub-folder/

Not working WebDavSession

Hello,
WebDavSession works well until 0.4, but it does not work after updating to 0.5.1.
(But WebDavClient works good.)
Please fix it.

// The base URL of the WebDAV server.
var webDavServerUrl = "http://192.168.0.250/dav";

// Specify the user credentials and use it to create a WebDavSession instance.
var credentials = new PasswordCredential(webDavServerUrl, "MyUsername", "MyPassword");
var webDavSession = new WebDavSession(@"http://192.168.0.250/dav", credentials);
var items = await webDavSession.ListAsync(@"/");

foreach (var item in items)
{
// Handle the response (list of WebDavSessionListItems), e.g item.Uri is the URL of an item (folder or file).
}

Exception thrown: 'DecaTec.WebDav.Exceptions.WebDavException' in mscorlib.dll

I have a WebDAV server running on apache2 on Ubuntu 16.04 LTS. One of my users is getting the following error when attempting to list files in the WebDAV from his application:

 Exception thrown: 'DecaTec.WebDav.Exceptions.WebDavException' in mscorlib.dll
 Error while executing ListAsync (wrong response status code). Expected status code: 207 (MultiStatus); actual status code: 401 (Unauthorized)

I'm not sure if this is a server issue or a client issue. My user is able to get into the WebDAV directory with his app but as soon as he tries to list anything, he gets the mentioned error. If it is a server side error, what do I need to change?

WP8.1 WinRT exception at WebDavSession.ListAsync

The exceptions occurs when WebDavSession.ListAsync is executed.

An exception of type 'System.NotSupportedException' occurred in mscorlib.ni.dll but was not handled in user code. Additional information: Specified method is not supported.

Stacktrace

   at System.Net.HttpWebRequest.set_ProtocolVersion(Version value)
   at System.Net.Http.HttpClientHandler.CreateAndPrepareWebRequest(HttpRequestMessage request)
   at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at DecaTec.WebDav.WebDavClient.<SendAsync>d__187.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at DecaTec.WebDav.WebDavSession.<ListAsync>d__73.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at NextcloudClient.NextcloudClient.<List>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at NextcloudApp.Services.DirectoryService.<StartDirectoryListing>d__38.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at NextcloudApp.Services.DirectoryService.<StartDirectoryListing>d__37.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at NextcloudApp.ViewModels.DirectoryListPageViewModel.<StartDirectoryListing>d__125.MoveNext()

Issues when using library in UWP project

Problem:
When using the Portable WebDAV Library in a Universal Windows Platform (UWP) project, an exception is thrown when accessing WebDAV resources using WebDavClient or WebDavSession with user credentials:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.NotSupportedException: This IRandomAccessStream does not support the GetInputStreamAt method because it requires cloning and this stream does not support cloning.

Cause of the exception
The class WebDavClient derives from System.Net.Http.HttpClient in order so send requests to WebDAV resources. The assembly referenced in UWP projects is

System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

This version contains a bug in the HttpClient (see MSDN forums).
This bug will be fixed in a future release of the System.Net.Http assembly.

Workaround
To be able to use the Portable WebDAV Library in UWP project, a pre-release version of System.Net.Http has to be used as a workaround.
To use the pre-release version, follow these steps:

  • Right click on your project in Visual Studio
  • Manage NuGet Packages...
    managenugetpackages
  • Browse
  • Search for 'System.Net.Http' and tick the option Include prerelease
  • Install the latest beta version of this package
    addsystemnethttpprerelease

Keep in mind that when using a pre-release package, there might be other bugs or side effects.

As soon as the System.Net.Http assembly got updated, this workaround will not longer be necessary.

See this wiki article for more information.

The absolute URIs provided do not have the same host/scheme

Getting the The absolute URIs provided do not have the same host/scheme exception when running the following code on Xamarin iOS:

var webDavSession = new WebDavSession(new Uri("http://localhost:5050/"), new NetworkCredential());
var items = await webDavSession.ListAsync(@"packages/");
return items.Select(i => i.Name).ToList();

Make the library usable with untrusted/invalid SSL certificates

When trying to access WebDAV resources with an untrusted/invalid SSL certificate, you'll receive an exception.
Using the library in a .NET Framework (4.5+) project, this can be circumvented by adding following line of code before calling methods of the library:
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

When using the library in a UWP app, the class ServicePointManager is not available. Thus, there is no possibility to use the library with untrusted/invalid SSL certificates.
Again, this would only be possible when not using System.Net.Http.HttpClient, but Windows.Web.Http.HttpClient instead.

Therefor, the library needs to be split up in two parts: one for .NET Framework, Windows 8 and ASP.NET Core, the other for Windows 8.1, Windows Phone 8.1 and UWP apps.

System.FormatException: String was not recognized as a valid DateTime.

Hi there,

Wanted to test the library with a CalDAV server, but I keep getting an exception when it's trying to parse the CreationDate property because it's null. This might be something that's weirdly set-up from the backend people, but would be nice if the library handled it.

Editing WebDavSessionListItem Properties

Is it possible to change and save a WebDavSessionListItem property value of a file on a WebDav server? If it is possible, can it be included in the documentation? If it is not possible, should the WebDavSessionListItem properties be read only?

Example:

var items = await webDavSession.ListAsync("uri");
var item = items["index"];
item.DisplayName = "New Value";
//Save item                

Problems with MoveAsync

Hello, dear developers. Thank for your great job!

I have problem with MoveAsync method if dest name has bracktes [ and ]

This problem arise periodically, but if arised - problem reproduced very stable.

In the same time (while problem reproduced) if i use other webdav clients for this operation - everthing ok.

MoveAsyn return false, without any exception and problem detalization.

I use Portable-WebDAV-Library version 1.1.2.

Make WebDavSessionListItem's immutable

There's no need for the client to change its properties. Because the properties are mutable, the client may try to change the WebDAV property simply by changing the WebDavSessionListItem's property.

Problem with empty loop in async operations

Hello, dear developer. I have problem.

For example, I set webdav session timeout to 1 minutes. Then i call ExistsAsync from webdav session. And if this request is long time, my app begins to consume 20% processor time. And it is problem if my app works in several threads.

Such an impression that in webdav session wait we have empty cycle like

while (condition)
;

without any pauses for careful about processor.

Improve unit tests

  • Existing unit tests need to be improved (mocking, etc.). The dependency of a real WebDAV server need to be removed.
  • Add unit tests for better coverage.

Thanks for release 0.7.0

I want to say thank you for finally releasing .NET Core version of library.
I was using it before and have to manually provide .NET Core support until you finally remove this burden from me.
Big Thank You!!!! ๐Ÿฅ‡

WebDavSession.ListAsync: URL with converted special characters is converted back

I have the problem, that a URL with special characters will be always transformed back (unescape), when I call the ListAsync function.

I debugged this problem and traced it back to the UriHelper.

uri = UriHelper.CombineUri(this.BaseUri, uri, true);

var uri1PathSplitted = WebUtility.UrlDecode(ur1Absolute).Split(slashCharArr, StringSplitOptions.RemoveEmptyEntries);

Nuspec issues

I see the following issues with the current NuGet package:

  1. The assemblies for .NET profile 32 (Uwp) and .NET profile 111 (Netfx) have different assembly names.
  2. According to this documentation, the usage of the profile number is not a recommended practice. The TFM for profile 32 should therefore be portable-win81+wpa81
  3. The profile 111 assembly should be in the lib folder portable-net45+win8+wpa81.

NuGet believes - due to the NetFx assembly being in the lib folder - that this is an assembly for the full .NET Framework (version 1,1) is, which doesn't seem right.

AdditionalProperties not working on Xamarin.Android (and possibly on Xamarin.iOS)

I noticed that additional properties don't work on Xamarin.Android. I was trying to get the additional property "favorite" from my server (a nextcloud installation). Investigating more I found that the helper function
GetUtf8EncodedXmlWebDavRequestString in WebDavHelper fails during serialization of Prop object when it contains any XmlElement in AdditionalProperties field, returning an empty string. This is the occurring exception:

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: XmlAnyElementAttribute can only be applied to members of type XmlElement, XmlElement[] or XmlNode[]. The target object is System.Xml.Linq.XElement\n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteAnyElementContent (System.Xml.Serialization.XmlTypeMapMemberAnyElement member, System.Object memberValue) [0x0007c] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMembers (System.Xml.Serialization.ClassMap map, System.Object ob, System.Boolean isValueList) [0x000c0] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElementElements (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x0000c] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElement (System.Xml. Serialization.XmlTypeMapping typeMap, System.Object ob, System.String element, System.String namesp) [0x00033] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, System.String element, System.String namesp, System.Boolean isNullable, System.Boolean needType, System.Boolean writeWrappingElem) [0x001b9] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object memberValue) [0x00212] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMembers (System.Xml.Serialization.ClassMap map, System.Object ob, System.Boolean isValueList) [0x000ff] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElementElements (System.Xml.Seri alization.XmlTypeMapping typeMap, System.Object ob) [0x0000c] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElement (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, System.String element, System.String namesp) [0x00033] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, System.String element, System.String namesp, System.Boolean isNullable, System.Boolean needType, System.Boolean writeWrappingElem) [0x001b9] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteRoot (System.Object ob) [0x00059] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Serialization.XmlSerializer.Serialize (System.Object o, System.Xml.Serialization.XmlSerializationWriter writer) [0x00016] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at System.Xml.Seria lization.XmlSerializer.Serialize (System.Xml.XmlWriter xmlWriter, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces) [0x00058] in <69fb168feda3422cb50a9a4f302b574c>:0 \n --- End of inner exception stack trace ---\n at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter xmlWriter, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces) [0x00093] in <69fb168feda3422cb50a9a4f302b574c>:0 \n at DecaTec.WebDav.Tools.WebDavHelper.GetUtf8EncodedXmlWebDavRequestString (System.Xml.Serialization.XmlSerializer xmlSerializer, System.Object objectToSerialize, System.Collections.Generic.KeyValuePair'2[System.String,System.String][] xmlNamespaces) [0x00073] in D:\\Sogeit\\Portable-WebDAV-Library\\DecaTec.WebDav\\Tools\\WebDavHelper.cs:59

Set Translate header to f to force IIS WebDAV to serve unmapped files

I just found out why WinSCP is able to download files from IIS with custom extensions as opposed to other clients, including this one.

It turns out it sends an Translate: f header, which forces IIS to serve the file as is even if it's extension is not mapped.

See https://winscp.net/tracker/show_bug.cgi?id=1255 for the original WinSCP issue and the Ms documentation here: https://msdn.microsoft.com/en-us/library/cc250063.aspx

The rfc4918 does not state mention the header but WinSCP sends it along for every GET request. I will run some more tests to see if it does so consistently. If so, I'll send a PR to address this.

Async methods are missing CancellationToken

It would be very useful to have also a method with requestUrl / requestUri and cancellationToken. (With no Lock parameter)

Like:
public Task<WebDavResponseMessage> MkcolAsync(string requestUrl, CancellationToken cancellationToken);

and

public Task<WebDavResponseMessage> MkcolAsync(Uri requestUri, CancellationToken cancellationToken);

Assembly 'DecaTec.WebDav.XmlSerializers' not found

I just tried this library. I created a new console project (C#, .NET 4.5.2). Then downloaded the DLL, tried installing via Install-Package PortableWebDavLibrary -Version 1.1.3, and also compiled the source directly. The result is always the same. When creating a new instance of WebDavSession: "System.IO.FileNotFoundException" in mscorlib.dll:

The assembly with display name 'DecaTec.WebDav.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'DecaTec.WebDav.XmlSerializers, Version=1.1.3.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Any ideas?

Disable Expect: 100-continue header?

I've an remote server (BaseX in this case) which does not send a response when an Expect: 100-continue header is sent along with the request. As far as I can tell the header is automatically appended by .NET Core/libcurl in certain scenarios. I've tested the behavior of WinSCP to see what it does and it does not send the Expect header.

Disabling it is pretty straightforward: just set System.Net.Http.HttpClient.DefaultRequestHeaders.ExpectContinue to false. This can be achieved without an modification to this library.

Did anyone encounter this issue before? If it is valuable I can send a PR if we want to disable the Expect header by default.

Support Proxy/Gateway

Access to a WebDAV server by proxy or gateway does not work. The WebSession.ListAsync method throws an exception:
The absolute URIs provided do not have the same host/scheme. at DecaTec.WebDav.Tools.UriHelper.CombineUri(Uri uri1, Uri uri2, Boolean removeDuplicatePath) at DecaTec.WebDav.WebDavSession.<ListAsync>d__77.MoveNext()

This occurs because the href's in response does not match with request URL.

Example:

There is a WebProxy property in WebDavSession, this one is not used. Support of this property should solve the problem?

Support for netstandard1.3

It would be nice when your project would support netstandard1.3. You can reuse the source for the .NET Framework without changes (tried with master). TBH: It might be useful to wait for the VS 2017 release (.NET Core 2.0) to ease the pain with the current inconsistencies of the .NET Core tooling.

System.FormatException when the ETag property is read ?

The WebDavSessionListItem looks like:

{
  "CreationDate": "0001-01-01T00:00:00",
  "ContentLanguage": null,
  "DisplayName": "***.mp3",
  "ContentLength": 9229800,
  "ContentType": "audio/mpeg",
  "LastModified": "2010-06-21T23:03:32+02:00",
  "ETag": "\"4f106d2c0189d98edf7f160d012d5c49\"",
  "Source": null,
  "ResourceType": null,
  "ContentClass": null,
  "DefaultDocument": null,
  "Uri": "https://***.stackstorage.com:443/remote.php/webdav/***.mp3",
  "IsCollection": false,
  "IsHidden": false,
  "IsReadonly": false,
  "IsRoot": false,
  "IsStructuredDocument": false,
  "LastAccessed": "0001-01-01T00:00:00",
  "Name": "***.mp3",
  "ParentName": null,
  "QuotaAvailableBytes": 670940972544,
  "QuotaUsedBytes": 9229800
}

When using DownloadFileAsync, I get this exception:

An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code

Additional information: The format of value '4f106d2c0189d98edf7f160d012d5c49' is invalid.

Nuget Install Failing

.NET Standard 1.1 includes .NET Framework 4.5. When trying to install via Nuget for a .NET 4.5 project in VS the following error occurs.

Could not install package 'PortableWebDavLibrary 0.8.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.