Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
WebDAV .NET
>
Tutorial
> Get stream to read from file
Here is one example how to use GetInputStream method to download file.
C# example
using System; using System.IO; using System.Net; using Independentsoft.Webdav; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); WebdavSession session = new WebdavSession(credential); Resource resource = new Resource(session); Stream input = resource.GetInputStream("http://myserver/dav/file1.dat"); FileStream file = new FileStream("c:\\file1.dat", FileMode.CreateNew); byte[] buffer = new byte[2048]; int len = 0; while ((len = input.Read(buffer, 0, buffer.Length)) > 0) { file.Write(buffer, 0, len); } file.Close(); input.Close(); } } }
VB example
Imports System Imports System.IO Imports System.Net Imports Independentsoft.Webdav Namespace Sample Class Module1 Shared Sub Main(ByVal args() As String) Dim credential As NetworkCredential = New NetworkCredential("username", "password") Dim session As WebdavSession = New WebdavSession(credential) Dim resource As Resource = New Resource(session) Dim input As Stream = resource.GetInputStream("http://myserver/dav/file1.dat") Dim file As FileStream = New FileStream("c:\\file1.dat", FileMode.CreateNew) Dim buffer() As Byte = New Byte(2048) {} Dim len As Integer = input.Read(buffer, 0, buffer.Length) While (len > 0) file.Write(buffer, 0, len) len = input.Read(buffer, 0, buffer.Length) End While file.Close() input.Close() End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*