Click or drag to resize

IItemContentAsyncGetWriteStreamAsync Method (String, Int64)

IT Hit WebDAV Classes Reference
Saves file's content to WebDAV server.

Namespace:  ITHit.WebDAV.Client
Assembly:  ITHit.WebDAV.Client (in ITHit.WebDAV.Client.dll) Version: 2.0.420.0
Syntax
Task<Stream> GetWriteStreamAsync(
	string contentType,
	long contentLength
)

Parameters

contentType
Type: SystemString
Media type of the file.
contentLength
Type: SystemInt64
Length of data to be written.

Return Value

Type: TaskStream
Stream to write resource content.
Exceptions
ExceptionCondition
NotFoundExceptionThis resource doesn't exist on the server.
ConflictException The resource is version controlled and has to be checked out to be edited.
WebDavHttpExceptionServer returned unknown error.
WebDavExceptionUnexpected error occurred.
Examples
In the following example a file is uploaded to a WebDAV server.
string license = "<?xml version='1.0' encoding='utf...
WebDavSessionAsync session = new WebDavSessionAsync(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IFolderAsync folder = await session.OpenFolderAsync(new Uri("http://server:8080/Sales"));
FileInfo file = new FileInfo("C:\\Products.exe");

IFileAsync file = await folder.CreateFileAsync(file.Name);
file.AllowWriteStreamBuffering = false;
file.TimeOut = 36000000; // 10 hours
using (Stream webStream = await file.GetWriteStreamAsync("application/octet-stream", file.Length))
{
    int bufSize = 1048576; // 1Mb
    byte[] buffer = new byte[bufSize];
    int bytesRead = 0;

    using (FileStream fileStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
    {
        while ( (bytesRead = fileStream.Read(buffer, 0, bufSize))>0)
            await webStream.WriteAsync(buffer, 0, bytesRead);
    }
}
See Also