IItemContentGetReadStreamAsync Method (Int64, Int64, String, IDictionaryString, String, CancellationToken)
IT Hit WebDAV Classes Reference
Loads part of the content of the file from WebDAV server using eTag to
ensure the content is up-to-date.
Namespace:
ITHit.WebDAV.Client
Assembly:
ITHit.WebDAV.Client (in ITHit.WebDAV.Client.dll) Version: 6.0.4052-Beta
Syntax Task<ContentStream> GetReadStreamAsync(
long startIndex,
long count,
string eTag,
IDictionary<string, string> headers = null,
CancellationToken cancellationToken = null
)
Function GetReadStreamAsync (
startIndex As Long,
count As Long,
eTag As String,
Optional headers As IDictionary(Of String, String) = Nothing,
Optional cancellationToken As CancellationToken = Nothing
) As Task(Of ContentStream)
Task<ContentStream^>^ GetReadStreamAsync(
long long startIndex,
long long count,
String^ eTag,
IDictionary<String^, String^>^ headers = nullptr,
CancellationToken cancellationToken = nullptr
)
abstract GetReadStreamAsync :
startIndex : int64 *
count : int64 *
eTag : string *
?headers : IDictionary<string, string> *
?cancellationToken : CancellationToken
(* Defaults:
let _headers = defaultArg headers null
let _cancellationToken = defaultArg cancellationToken null
*)
-> Task<ContentStream>
Parameters
- startIndex
- Type: SystemInt64
Start position to retrieve count number of bytes from. - count
- Type: SystemInt64
Number of bytes to retrieve. - eTag
- Type: SystemString
The ETag that will be passed in the If-Range header. - headers (Optional)
- Type: System.Collections.GenericIDictionaryString, String
Request headers. - cancellationToken (Optional)
- Type: System.ThreadingCancellationToken
Propagates notification that operations should be canceled.
Return Value
Type:
TaskContentStreamStream to read file content.
Exceptions 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(long,long,string)] 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...
WebDavSession session = new WebDavSession(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IFolder folder = await session.GetFolderAsync(new Uri("https://server:8080/Sales"));
FileInfo file = new FileInfo("C:\\Temp\\Products.cff");
IFile file = await folder.GetResourceAsync(file.Name);
string etag = file.Etag;
int bufSize = 1048576;
byte[] buffer = new byte[bufSize];
int totalWritten = 10;
using (ContentStream stream = await file.GetReadStreamAsync(totalWritten, resource.ContentLength, etag, out contentModified))
{
if (stream.ContentModified)
totalWritten = 0;
using (FileStream fs = file.OpenWrite())
{
fs.Seek(totalWritten, SeekOrigin.Begin);
int bytesRead;
while ((bytesRead = (await stream.ReadAsync(buffer, 0, bufSize))) > 0)
await fs.WriteAsync(buffer, 0, bytesRead);
}
}
See Also