public Stream SourceStream { get; }
The source stream.
This is the same value as the sourceStream parameter passed to UploadStreamAsync if this method is used to initiate the upload operation. If UploadFileAsync was used instead, then the value of this property will be null ( Nothing in VB)
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.SharePoint.Client;
public void SharePointClientUploadStreamAsyncExample()
{
string sourceFileName = LEAD_VARS.ImagesDir + @"\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;
// Get 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);
// If this is a console application demo, we might exit the program before the operation completes,
// so use a wait handle to not exit this method till the opreation completes
AutoResetEvent wait = new AutoResetEvent(false);
// Build the upload document full path (folder + file name)
string destinationPath = Path.Combine(folderName, Path.GetFileName(sourceFileName));
// Upload the document
spClient.UploadCompleted += new EventHandler<SharePointClientUploadCompletedEventArgs>(UploadStreamAsyncCompleted);
spClient.UploadStreamAsync(stream, siteUri, destinationPath, wait);
// Wait till the operation completes
Console.WriteLine("Waiting to upload to finish");
wait.WaitOne();
wait.Close();
}
}
private static void UploadStreamAsyncCompleted(object sender, SharePointClientUploadCompletedEventArgs e)
{
// Remove our handler
SharePointClient spClient = sender as SharePointClient;
spClient.UploadCompleted -= new EventHandler<SharePointClientUploadCompletedEventArgs>(UploadStreamAsyncCompleted);
Console.WriteLine("The source stream: {0}", e.SourceStream);
if (e.Error == null && !e.Cancelled)
{
// All OK, the file is in SharePoint
Console.WriteLine("Upload completed");
}
else
{
// Some error occured
if (e.Error != null)
Console.WriteLine(e.Error.Message);
else
Console.WriteLine("User cancelled");
}
// Tell whoever is listening that we are done
EventWaitHandle wait = e.UserState as EventWaitHandle;
wait.Set();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}