←Select platform

UploadStream Method

Summary

Uploads the data in a stream to a SharePoint server folder.

Syntax

C#
VB
C++
public void UploadStream(  
   Stream sourceStream, 
   Uri siteUri, 
   string destinationPath 
) 
Public Sub UploadStream( _ 
   ByVal sourceStream As Stream, _ 
   ByVal siteUri As Uri, _ 
   ByVal destinationPath As String _ 
) 
public: 
void UploadStream(  
   Stream^ sourceStream, 
   Uri^ siteUri, 
   String^ destinationPath 
) 

Parameters

sourceStream
The stream containing the item data to upload. This value cannot be null (Nothing in VB).

siteUri
Full URL to the destination SharePoint site. This could be http://MySite or http://MySiteCollection/MySite. This value cannot be null (Nothing in VB).

destinationPath
Destination path (folder and file name) of the item to be created in the SharePoint server. See the remarks section for more information. This value cannot be null (Nothing in VB).

Remarks

This method will upload the content of sourceStream to SharePoint server. The location and name of the destination item in the server is determined as follows:

DestinationFileFullUrl = siteUri + destinationPath

For example, assume the SharePoint server contains a folder with the following name:

http://site/Shared Documents/

And you want the uploaded item with the name File.ext into this folder. You can perform this using this code:

Uri siteUri = new Uri(@"http://site"); 
string destinationPath = @"Shared Documents/File.ext"; 
sharePointClientObject.UploadFile(sourceFileName, siteUri, destinationPath); 

You can use the .NET System.IO.Path and System.UriBuilder classes to build the path and URI of the items. No that destinationPath is allowed to contain slashes (/) as in HTTP URI's or forward slashes (\) as in Windows paths or a mix of both.

This method will not return until the item is finished uploading to the server. If an error occurs, this method will throw an exception.

To upload the data of a stream asynchronously, use UploadStreamAsync.

To upload a disk file to the server, use UploadFile or UploadFileAsync.

To down an item from SharePoint, use DownloadFile, DownloadFileAsync, GetDownloadStream or GetDownloadStreamAsync.

Example

This example will create a stream from an image file and uploads it to SharePoint.

C#
VB
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.SharePoint.Client 
 
Private Shared Sub SharePointClientUploadStreamExample() 
   Dim sourceFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif" 
   ' Replace SHAREPOINT_SITE_URI with a valid URL to a SharePoint site, for example 
   ' http://SiteCollection/MySite 
   Dim siteUri As New Uri(SHAREPOINT_SITE_URI) 
 
   ' Replace SHAREPOINT_FOLDER_NAME with a valid folder on the site above, for example 
   ' "Documents" or "Documents\Sub Documents" 
   Dim folderName As String = SHAREPOINT_FOLDER_NAME 
 
   ' Open a stream to the file 
   Using stream As FileStream = File.OpenRead(sourceFileName) 
      Dim spClient As New SharePointClient() 
      spClient.OverwriteExistingFiles = True 
 
      ' Optional: Set the credentials: 
      spClient.Credentials = New NetworkCredential(USER_NAME, PASSWORD, DOMAIN) 
 
      ' Build the upload document full path (folder + file name) 
      Dim destinationPath As String = Path.Combine(folderName, Path.GetFileName(sourceFileName)) 
 
      ' Upload the document 
      spClient.UploadStream(stream, siteUri, destinationPath) 
   End Using 
End Sub 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.SharePoint.Client; 
 
private static void SharePointClientUploadStreamExample() 
{ 
   string sourceFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif"; 
   // Replace SHAREPOINT_SITE_URI with a valid URL to a SharePoint site, for example 
   // http://SiteCollection/MySite 
   Uri siteUri = new Uri(SHAREPOINT_SITE_URI); 
 
   // Replace SHAREPOINT_FOLDER_NAME with a valid folder on the site above, for example 
   // "Documents" or "Documents\Sub Documents" 
   string folderName = SHAREPOINT_FOLDER_NAME; 
 
   // Open a stream to the file 
   using (FileStream stream = File.OpenRead(sourceFileName)) 
   { 
      SharePointClient spClient = new SharePointClient(); 
      spClient.OverwriteExistingFiles = true; 
 
      // Optional: Set the credentials: 
      spClient.Credentials = new NetworkCredential(USER_NAME, PASSWORD, DOMAIN); 
 
      // Build the upload document full path (folder + file name) 
      string destinationPath = Path.Combine(folderName, Path.GetFileName(sourceFileName)); 
 
      // Upload the document 
      spClient.UploadStream(stream, siteUri, destinationPath); 
   } 
} 

Requirements

Target Platforms

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
Click or drag to resize