Click or drag to resize

IItemContentAsyncGetReadStreamAsync Method (Int64, Int64, DateTime)

IT Hit WebDAV Classes Reference
Loads part of the content of the file from WebDAV server using lastModifiedUtc to ensure the content is up-to-date.

Namespace:  ITHit.WebDAV.Client
Assembly:  ITHit.WebDAV.Client (in ITHit.WebDAV.Client.dll) Version: 2.0.420.0
Syntax
Task<ContentStream> GetReadStreamAsync(
	long startIndex,
	long count,
	DateTime lastModifiedUtc
)

Parameters

startIndex
Type: SystemInt64
Start position to retrieve count number of bytes from.
count
Type: SystemInt64
Number of bytes to retrieve.
lastModifiedUtc
Type: SystemDateTime
The file modification date that will be passed in the If-Range header. If the file content was modified since passed modification date, the library will throw FileContentModified exception.

Return Value

Type: TaskContentStream
Stream to read file content.
Exceptions
ExceptionCondition
NotFoundExceptionThis resource doesn't exist on the server.
WebDavHttpExceptionServer returned unknown error.
WebDavExceptionUnexpected error occurred.
Remarks

Loads part of the content of the file from WebDAV server if it's content was not changed. If the content was modified the complete new content is returned.

Examples
This sample shows how to use the GetReadStreamAsync(Int64, Int64, DateTime) method. First 1024 bytes of server file are already saved to local file. Code tries to download the rest of the file content.
string license = "<?xml version='1.0' encoding='utf...
WebDavSessionAsync session = new WebDavSessionAsync(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IFolderAsync folder = session.OpenFolder(new Uri("http://server:8080/Sales"));
FileInfo file = new FileInfo("C:\\Temp\\Products.cff");
IFileAsync file = folder.GetResource(file.Name);

DateTime modifTime = file.LastModified.ToUniversalTime();
int bufSize = 1048576; // 1Mb
byte[] buffer = new byte[bufSize];
int totalWritten = 1024;

using (Stream stream = file.GetReadStream(totalWritten, resource.ContentLength, modifTime, out contentModified))
{
    if (contentModified) 
        totalWritten = 0; // entire file content is returned

    using (FileStream fs = file.OpenWrite())
    {
        fs.Seek(totalWritten, SeekOrigin.Begin);
        int bytesRead;
        while ((bytesRead = stream.Read(buffer, 0, bufSize)) > 0)
            fs.Write(buffer, 0, bytesRead);
    }
}
See Also