Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
WebDAV .NET
>
Tutorial
> Get stream to write to file
Here is one example how to use GetOutputStream method to upload 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 output = resource.GetOutputStream("http://myserver/dav/file1.dat"); FileStream file = new FileStream("c:\\file1.dat", FileMode.Open); byte[] buffer = new byte[2048]; int len = 0; while ((len = file.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, len); output.Flush(); } output.Close(); file.Close(); //Press ENTER to exit. Console.Read(); } } }
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 output As Stream = resource.GetOutputStream("http://myserver/dav/file1.dat") Dim file As FileStream = New FileStream("c:\\file1.dat", FileMode.Open) Dim buffer() As Byte = New Byte(2048) {} Dim len As Integer = file.Read(buffer, 0, buffer.Length) While (len > 0) output.Write(buffer, 0, len) output.Flush() len = file.Read(buffer, 0, buffer.Length) End While file.Close() output.Close() 'Press ENTER to exit Console.Read() End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*