IContent.Write Method 

Saves the content of the file from the specified stream to the WebDAV repository.

[Visual Basic]
Function Write( _
   ByVal Stream As Stream, _
   ByVal String As String, _
   ByVal Int64 As Long, _
   ByVal Int64 As Long _
) As Boolean
bool Write(
   Stream content,
   String contentType,
   Int64 startIndex,
   Int64 totalFileSize


Stream to read the content of the file from.
Indicates the media type of the file.
Start offset to which content shall be saved.
Entire length of the file. Is is not less then length of content stream.

Return Value

Boolean value indicating whether entire stream was written. This value is used by engine to take decision whether autocheckin shall be performed.


IIS and ASP.NET does not support files upload larger than 2Gb. If you need to upload files larger than 2Gb you must develop HttpListener-based WebDAV server or implement resumable upload interfaces.

If you are creating HttpHandler-based WebDAV server you must specify the file maximum upload size in web.config of your web application. By default maximum upload size is set to 4096 KB (4 MB) by ASP.NET. This limit is used to prevent denial of service attacks caused by users posting large files to the server. To increase the upload limit add <httpRuntime> section to your web application web.config file and specify the limit in kilobytes:

          <httpRuntime maxRequestLength="2097151" /> //2Gb

When client uploads file to IIS, ASP.NET first creates the file in a the temporary upload directory. Only when the entire file is uploaded to server you can read its content from stream. By default ASP.NET uploads files to %FrameworkInstallLocation%\Temporary ASP.NET Files folder. You must make sure you have enough disk space to keep temporary files uploaded to your server. To change this folder location add the following section to your web.config file:

          <compilation tempDirectory="temporary files directory" />
To avoid temporary file creation and pass content directly to engine set the PutUploadProgressAndResumeModule module in your web.config file. Unlike IIS/ASP.NET, HttpListener-based server does not create any temporary files when handling uploads.


Exception TypeCondition
LockedExceptionThe file was locked and client did not provide lock token.
NeedPrivilegesExceptionThe user doesn't have enough privileges.
InsufficientStorageExceptionQuota limit is reached.
DavExceptionIn other cases.


The code below is part of 'NtfsStorage' sample provided with the SDK.

public virtual bool Write(Stream content, string contentType, long startIndex, long totalFileSize)
    //Set timeout to maximum value to be able to upload large files.
    HttpContext.Current.Server.ScriptTimeout = int.MaxValue;
    return context.FileOperation(
        () => writeInternal(content, startIndex, totalFileSize),
private bool writeInternal(Stream content, long startIndex, long totalLength)
    if (startIndex == 0 && fileInfo.Length > 0)
    RewriteStream("SerialNumber", GetStreamAndDeserialize<int>("SerialNumber", context.Logger) + 1);

    using (var fileStream = fileInfo.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
        if (fileStream.Length < startIndex)
            throw new DavException("Previous piece of file was not uploaded.", DavStatus.PRECONDITION_FAILED);

        fileStream.Seek(startIndex, SeekOrigin.Begin);
        var buffer = new byte[bufSize];

        int lastBytesRead;
            while ((lastBytesRead = content.Read(buffer, 0, bufSize)) > 0)
                fileStream.Write(buffer, 0, lastBytesRead);
        catch (HttpException)
            // The remote host closed the connection (for example Cancel or Pause pressed)

    return true;

See Also

IContent Interface | ITHit.WebDAV.Server Namespace