Editor: Visual Studio 2017 Community
Hallo,
für ein Projekt wird ein WebDav Client benötigt, der die Liste aller vorhandenen Dateien auslesen kann.
Hierzu wurde ein NuGet Paket "Portable WebDav Library" installiert.
Des weiteren wurden Beispiel-Codes aus der Onlinedokumentation entnommen:
OnlineDoku: decatec.de/ext/PortableWebDAVL…cd5-9eb6-0850cd041621.htm
Beim Ausführen der Beispiel-Befehle stoppt das Programm stets an den Befehlen
- webDavSession.ListAsync
- webDavClient.PropFindAsync
Wenn diese Befehle ausgeführt werden sollen, stoppt die Ausführung des Programms gänzlich mit einem Exit Code 0.
Ein Abfangen von etwaigen Fehlern ist mit try-catch Methoden nicht möglich.
Im Ausgabefenster wird keine Fehlermeldung ausgegeben.
Kann jemand einen Tip oder Ratschlag geben?
Spoiler anzeigen
*Topic verschoben*
Hallo,
für ein Projekt wird ein WebDav Client benötigt, der die Liste aller vorhandenen Dateien auslesen kann.
Hierzu wurde ein NuGet Paket "Portable WebDav Library" installiert.
Des weiteren wurden Beispiel-Codes aus der Onlinedokumentation entnommen:
OnlineDoku: decatec.de/ext/PortableWebDAVL…cd5-9eb6-0850cd041621.htm
Beim Ausführen der Beispiel-Befehle stoppt das Programm stets an den Befehlen
- webDavSession.ListAsync
- webDavClient.PropFindAsync
Wenn diese Befehle ausgeführt werden sollen, stoppt die Ausführung des Programms gänzlich mit einem Exit Code 0.
Ein Abfangen von etwaigen Fehlern ist mit try-catch Methoden nicht möglich.
Im Ausgabefenster wird keine Fehlermeldung ausgegeben.
Kann jemand einen Tip oder Ratschlag geben?
C#-Quellcode
- static readonly string Username = "username";
- static readonly string Password = "password";
- static readonly string URL = @"http://www.myserver.com/webdav/";
- static readonly string Folder = "/dav/";
- static async void WebDavRead()
- {
- // The base URL of the WebDAV server.
- //var webDavServerUrl = "http://www.myserver.com/webdav/";
- // Specify the user credentials and use it to create a WebDavSession instance.
- var credentials = new NetworkCredential(Username, Password);
- var webDavSession = new WebDavSession(URL, credentials);
- var propFind = PropFind.CreatePropFindWithEmptyProperties(PropNameConstants.IsHidden, PropNameConstants.DisplayName, PropNameConstants.Name, PropNameConstants.GetContentType, PropNameConstants.CreationDate, PropNameConstants.ResourceType, PropNameConstants.GetLastModified, PropNameConstants.GetContentLength);
- var items = await webDavSession.ListAsync(Folder, propFind);
- foreach (var item in items)
- {
- // Handle the response (list of WebDavSessionListItems), e.g item.Uri is the URL of an item (folder or file).
- }
- try
- {
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- static async void WebDavTest2()
- {
- try
- {
- // The base URL of the WebDAV server.
- var webDavServerUrl = URL;
- // Specify the user credentials and pass it to a HttpBaseProtocolFilter.
- var credentials = new NetworkCredential(Username, Password);
- var httpClientHandler = new HttpClientHandler()
- {
- Credentials = credentials
- };
- // Use the HttpClientHandler (with credentials) to create a new WebDavClient.
- var webDavClient = new WebDavClient(httpClientHandler);
- // Create a PropFind object with represents a so called 'allprop' request.
- var pf = PropFind.CreatePropFindAllProp();
- var response = await webDavClient.PropFindAsync(webDavServerUrl + Folder, WebDavDepthHeaderValue.Infinity, pf);
- // You could also use an XML string directly for use with the WebDavClient.
- //var xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propfind xmlns:D=\"DAV:\"><D:allprop /></D:propfind>";
- //var response = await webDavClient.PropFindAsync(webDavServerUrl + @"/MyFolder/", WebDavDepthHeaderValue.Infinity, xmlString);
- // Use the WebDavResponseContentParser to parse the response message and get a MultiStatus instance (this is also an async method).
- var multistatus = await WebDavResponseContentParser.ParseMultistatusResponseContentAsync(response.Content);
- // Now you can use the MultiStatus object to get access to the items properties.
- foreach (var responseItem in multistatus.Response)
- {
- // Handle propfind multistatus response, e.g responseItem.Href is the URL of an item (folder or file).
- }
- // Dispose the WebDavClient when it is not longer needed.
- webDavClient.Dispose();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- finally
- {
- Console.WriteLine("End");
- }
- }
*Topic verschoben*
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Marcus Gräfe“ ()