Independentsoft
Home
Purchase
Support
Company
Contact
WebDAV .NET
>
Tutorial
> List folder
The following example shows you how to list the files and folders in a folder.
C# example
using System; using System.Collections.Generic; 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/"); IReadOnlyList<ResourceInfo> resources = await client.List("documents/"); foreach (ResourceInfo resource in resources) { if (resource.IsCollection) { Console.WriteLine("[folder] " + resource.Name); } else { Console.WriteLine(resource.Name + " (" + resource.ContentLength + " bytes)"); } } } } } }
VB example
Imports System Imports System.Collections.Generic 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 resources As IReadOnlyList(Of ResourceInfo) = Await client.List("documents/") For Each resource As ResourceInfo In resources If resource.IsCollection Then Console.WriteLine("[folder] " & resource.Name) Else Console.WriteLine(resource.Name & " (" & resource.ContentLength & " bytes)") End If Next End Using End Function End Module End Namespace
Need help? Ask our developers:
Name*
Email*
Message*