Namespace: ITHit.WebDAV.Server
Exception | Condition |
---|---|
NeedPrivilegesException | The user doesn't have enough privileges. |
DavException | In other cases. |
By default ASP.NET buffers content on server side before sending output. You must turn off buffering to eliminate keeping entire file content in memory before sending:
HttpContext.Current.Response.BufferOutput = false;
Client application can request only a part of a file specifying Range header. Download managers may use this header to download single file using several threads at a time.
The code below is part of 'WebDAVServer.NtfsStorage' sample provided with the SDK.
public virtual void Read(Stream output, long startIndex, long count) { //Set timeout to maximum value to be able to download large files. HttpContext.Current.Server.ScriptTimeout = int.MaxValue; if (ContainsDownloadParam(context.Request.RawUrl)) { AddContentDisposition(context, Name); } context.FileOperation( this, () => readInternal(output, startIndex, count), Privilege.Read); } private void readInternal(Stream output, long startIndex, long count) { var buffer = new byte[bufSize]; using (var fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read)) { fileStream.Seek(startIndex, SeekOrigin.Begin); int bytesRead; var toRead = (int)Math.Min(count, bufSize); try { while (toRead > 0 && (bytesRead = fileStream.Read(buffer, 0, toRead)) > 0) { output.Write(buffer, 0, bytesRead); count -= bytesRead; } } catch (HttpException) { // The remote host closed the connection (for example Cancel or Pause pressed). } } }