public event EventHandler<SharePointClientUploadCompletedEventArgs> UploadCompleted
The event handler receives an argument of type SharePointClientUploadCompletedEventArgs containing data related to this event. The following SharePointClientUploadCompletedEventArgs properties provide information specific to this event.
Property | Description |
---|---|
Cancelled (Inherited from System.ComponentModel.AsyncCompletedEventArgs) | Gets a value indicating whether an asynchronous operation has been canceled. |
DestinationPath | Gets the destination path on the SharePoint server. |
Error (Inherited from System.ComponentModel.AsyncCompletedEventArgs) | Gets a value indicating which error occurred during an asynchronous operation. |
SiteUri | Gets the SharePoint server site URI. |
SourceFileName | Gets the source file name. |
SourceStream | Gets the source stream. |
UserState (Inherited from System.ComponentModel.AsyncCompletedEventArgs) | Gets the unique identifier for the asynchronous task. |
The SharePointClient class supports uploading an item asynchronously through UploadFileAsync and UploadStreamAsync. When you call these methods, control returns instantly to your program and the UploadCompleted event will occur when the upload operation is completed (successfully or when an error occur).
Note that the SharePointClientUploadCompletedEventArgs derives from the standard .NET System.ComponentModel.AsyncCompletedEventArgs class and adds properties specified to SharePoint upload support.
When the upload operation is completed, the UploadCompleted event will receive an object of type SharePointClientUploadCompletedEventArgs containing the operation result as following:
Property | Value |
---|---|
SourceFileName |
The source file name. This is the same value as the sourceFileName parameter passed to UploadFileAsync if this method is used to initiate the upload operation. If UploadStreamAsync was used instead, then the value of this property will be null ( Nothing in Visual Basic) |
SourceStream |
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 Visual Basic) |
SiteUri |
The Share Point server site URI. This is the same value as the siteUri parameter passed to UploadFileAsync or UploadStreamAsync. |
DestinationPath |
The destination path. This is the same value as the destinationPath parameter passed to UploadFileAsync or UploadStreamAsync. |
System.ComponentModel.AsyncCompletedEventArgs.Error |
Gets a value that indicates which error occurred during the asynchronous upload operation. If an exception is raised during the asynchronous upload operation, the class will assign the exception to the System.ComponentModel.AsyncCompletedEventArgs.Error property. The client application's event-handler delegate should check the System.ComponentModel.AsyncCompletedEventArgs.Error property before accessing any properties in SharePointClientUploadCompletedEventArgs. The value of the System.ComponentModel.AsyncCompletedEventArgs.Error property is null (Nothing in Visual Basic) if the operation was canceled |
System.ComponentModel.AsyncCompletedEventArgs.UserState |
Gets the unique identifier for the asynchronous upload operation. The value of this property is the same as the userState parameter passed to UploadFileAsync or UploadStreamAsync. |
System.ComponentModel.AsyncCompletedEventArgs.Cancelled |
true if the asynchronous upload operation has been canceled; otherwise, false. This class does not change the value of this property from the default value of false |
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.SharePoint.Client;
public void SharePointClientUploadFileAsyncExample()
{
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;
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>(UploadFileAsyncCompleted);
spClient.UploadFileAsync(sourceFileName, siteUri, destinationPath, wait);
// Wait till the operation completes
Console.WriteLine("Waiting to upload to finish");
wait.WaitOne();
wait.Close();
Console.WriteLine("Upload completed");
}
private static void UploadFileAsyncCompleted(object sender, SharePointClientUploadCompletedEventArgs e)
{
// Remove our handler
SharePointClient spClient = sender as SharePointClient;
spClient.UploadCompleted -= new EventHandler<SharePointClientUploadCompletedEventArgs>(UploadFileAsyncCompleted);
if (e.Error == null && !e.Cancelled)
{
// All OK, the file is in SharePoint
}
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:\LEADTOOLS22\Resources\Images";
}