IItemContent.GetWriteStream Method (String, Int64, String)

IT Hit WebDAV for .NET

Saves resource's content to WebDAV server.

[Visual Basic]
Function GetWriteStream( _
   ByVal contentType As String, _
   ByVal contentLength As Long, _
   ByVal lockToken As String _
) As Stream
[C#]
Stream GetWriteStream(
   string contentType,
   long contentLength,
   string lockToken
);

Parameters

contentType
Media type of the resource.
contentLength
Length of data to be written.
lockToken
Lock token for this resource.

Return Value

Stream to write resource content.

Exceptions

Exception Type Condition
NotFoundException This resource doesn't exist on the server.
ConflictException The resource is version controlled and has to be checked out to be edited.
WebDavHttpException Server returned unknown error.
WebDavException Unexpected error occurred.

Example

 string license = "<?xml version='1.0' encoding='utf...
 WebDavSession session = new WebDavSession(license);
 session.Credentials = new NetworkCredential("User1", "pwd");
 IFolder folder = session.OpenFolder(new Uri("http://server:8080/Sales"));
 FileInfo file = new FileInfo("C:\\Products.exe");
 LockInfo lockInfo = folder.Lock(LockScope.Exclusive, true, "User 1", new TimeSpan(0, 30, 0));
 IResource resource = folder.CreateResource(file.Name, lockInfo.LockToken.LockToken);
 using (Stream webStream = resource.GetWriteStream(
     "application/octet-stream", file.Length, lockInfo.LockToken.LockToken))
 {
     int bufSize = 1048576; // 1Mb
     byte[] buffer = new byte[bufSize];
     int bytesRead = 0;

     using (FileStream fileStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         while ( (bytesRead = fileStream.Read(buffer, 0, bufSize))>0)
             webStream.Write(buffer, 0, bytesRead);
     }
 }
 folder.Unlock(lockInfo.LockToken.LockToken);
 

See Also

IItemContent Interface | ITHit.WebDAV.Client Namespace | IItemContent.GetWriteStream Overload List