Independentsoft
Home
Purchase
Support
Company
Contact
WebDAV .NET
>
Tutorial
> Get property
The following example shows you how to get a property of a file.
C# example
using System; using System.Net; using System.Threading.Tasks; using Independentsoft.Webdav; namespace Sample { class Program { static async Task Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); using (WebdavClient client = new WebdavClient(credential)) { client.BaseAddress = new Uri("https://myserver/dav/"); Property contentType = await client.GetProperty("documents/report.pdf", DavProperty.GetContentType); if (contentType != null) { Console.WriteLine("Content type: " + contentType.Value); } // A property in another namespace; null when the file does not have it. Property author = await client.GetProperty("documents/report.pdf", new PropertyName("author", "http://example.com/ns")); Console.WriteLine("Author: " + (author != null ? author.Value : "not set")); } } } }
VB example
Imports System Imports System.Net Imports System.Threading.Tasks Imports Independentsoft.Webdav Namespace Sample Module Program Sub Main(args As String()) RunAsync().GetAwaiter().GetResult() End Sub Private Async Function RunAsync() As Task Dim credential As New NetworkCredential("username", "password") Using client As New WebdavClient(credential) client.BaseAddress = New Uri("https://myserver/dav/") Dim contentType As [Property] = Await client.GetProperty("documents/report.pdf", DavProperty.GetContentType) If contentType IsNot Nothing Then Console.WriteLine("Content type: " & contentType.Value) End If ' A property in another namespace; Nothing when the file does not have it. Dim author As [Property] = Await client.GetProperty("documents/report.pdf", New PropertyName("author", "http://example.com/ns")) Console.WriteLine("Author: " & If(author IsNot Nothing, author.Value, "not set")) End Using End Function End Module End Namespace
Need help? Ask our developers:
Name*
Email*
Message*