Namespace: ITHit.WebDAV.Client
Task<ContentStream> GetReadStreamAsync( long startIndex, long count, DateTime lastModifiedUtc )
Exception | Condition |
---|---|
NotFoundException | This resource doesn't exist on the server. |
WebDavHttpException | Server returned unknown error. |
WebDavException | Unexpected error occurred. |
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.
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); } }