←Select platform

DownloadCompleted Event

Summary
An event that indicates an asynchronous download operation has been completed.

Syntax
C#
C++/CLI
Python
public event EventHandler<SharePointClientDownloadCompletedEventArgs> DownloadCompleted 
public: 
event EventHandler<SharePointClientDownloadCompletedEventArgs^>^ DownloadCompleted 
def DownloadCompleted(sender,e): # sender: SharePointClient e: SharePointClientDownloadCompletedEventArgs 
Event Data

The event handler receives an argument of type SharePointClientDownloadCompletedEventArgs containing data related to this event. The following SharePointClientDownloadCompletedEventArgs properties provide information specific to this event.

PropertyDescription
Cancelled (Inherited from System.ComponentModel.AsyncCompletedEventArgs)Gets a value indicating whether an asynchronous operation has been canceled.
DestinationData Gets the download destination stream data.
DestinationFileName Gets the download operation destination file name.
Error (Inherited from System.ComponentModel.AsyncCompletedEventArgs)Gets a value indicating which error occurred during an asynchronous operation.
SourceUri Gets the URI of the source item being downloaded.
UserState (Inherited from System.ComponentModel.AsyncCompletedEventArgs)Gets the unique identifier for the asynchronous task.
Remarks

The SharePointClient class supports downloading an item asynchronously using the DownloadFileAsync and GetDownloadStreamAsync methods. When you call these methods, control returns instantly to your program and the DownloadCompleted event occurs when the download operation is completed (whether or not the operation was successful).

Note that the SharePointClientDownloadCompletedEventArgs derives from the standard .NET System.ComponentModel.AsyncCompletedEventArgs class and adds properties specified to SharePoint download support.

When the download operation is completed, the DownloadCompleted event will receive a SharePointClientDownloadCompletedEventArgs object containing the foolowing information about the operation:

Property Value
SourceUri

The source URI. This is the same value as the sourceUri parameter passed to the DownloadFileAsync or GetDownloadStreamAsync method.

DestinationFileName

The destination file name. This is the same value as the destinationFileName parameter passed to DownloadFileAsync if this method was called to initiate the download. If GetDownloadStreamAsync was called to initiate the download, then the value of this property is null (Nothing in Visual Basic)

DestinationData

A SharePointClientDownloadData object that contains the download stream information if GetDownloadStreamAsync was called to initiate the download. If DownloadFileAsync was used to initiate the download, then the value of this property will be null (Nothing in Visual Basic)

Note that you are responsible for calling System.IDisposable.Dispose on DestinationData if you subscribe to the DownloadCompleted event.

System.ComponentModel.AsyncCompletedEventArgs.Error

Gets a value that indicates which error occurred during the asynchronous download operation. If an exception is raised during the asynchronous download operation, the class assigns 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 the SharePointClientDownloadCompletedEventArgs class.

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 download operation. The value of this property is the same as the userState parameter passed to the DownloadFileAsync or GetDownloadStreamAsync method.

System.ComponentModel.AsyncCompletedEventArgs.Cancelled

true if the asynchronous download operation has been canceled; otherwise, false. This class does not change the value of this property from the default value of false

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.SharePoint.Client; 
 
 
public void SharePointClientDownloadFileAsyncExample() 
{ 
   // 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; 
 
   // Replace SHAREPOINT_DOCUMENT_NAME with a valid document on the folder above, for example 
   // MyDocument.tif 
   string documentName = SHAREPOINT_DOCUMENT_NAME; 
 
   // Build the full URL to the document are we going to download 
   UriBuilder builder = new UriBuilder(siteUri); 
   builder.Path = Path.Combine(builder.Path, folderName); 
   builder.Path = Path.Combine(builder.Path, documentName); 
   Uri sourceDocumentUri = builder.Uri; 
 
   SharePointClient spClient = new SharePointClient(); 
 
   // Optional: Set the credentials: 
   spClient.Credentials = new NetworkCredential(USER_NAME, PASSWORD, DOMAIN); 
 
   string tempFileName = Path.GetTempFileName(); 
 
   // 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); 
 
   // Download the SharePoint item to the temporary file asynchronously 
   spClient.DownloadCompleted += new EventHandler<SharePointClientDownloadCompletedEventArgs>(MyDownloadFileAsyncCompleted); 
   spClient.DownloadFileAsync(sourceDocumentUri, tempFileName, wait); 
 
   // Wait till the operation completes 
   wait.WaitOne(); 
   wait.Close(); 
 
   // Delete the temporary file we created 
   File.Delete(tempFileName); 
} 
 
private static void MyDownloadFileAsyncCompleted(object sender, SharePointClientDownloadCompletedEventArgs e) 
{ 
   // Remove our handler 
   SharePointClient spClient = sender as SharePointClient; 
   spClient.DownloadCompleted -= new EventHandler<SharePointClientDownloadCompletedEventArgs>(MyDownloadFileAsyncCompleted); 
 
   if (e.Error == null && !e.Cancelled) 
   { 
      // All is OK, use RasterCodecs to get its info 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         using (CodecsImageInfo imageInfo = codecs.GetInformation(e.DestinationFileName, true)) 
         { 
            // Show the image info 
            Console.WriteLine("URL:        {0}", e.SourceUri); 
            Console.WriteLine("Pages:      {0}", imageInfo.TotalPages); 
            Console.WriteLine("Size:       {0} by {1} pixels", imageInfo.Width, imageInfo.Height); 
            Console.WriteLine("Resolution: {0} by {1} dpi", imageInfo.XResolution, imageInfo.YResolution); 
            Console.WriteLine("Bits/Pixel: {0}", imageInfo.BitsPerPixel); 
         } 
      } 
   } 
   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(); 
} 
Requirements

Target Platforms

Help Version 22.0.2023.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.