public void DownloadFileAsync(Uri sourceUri,string destinationFileName,object userState)
sourceUri
The full URI for the source item in the SharePoint server. This value cannot be null (Nothing in VB). It must be the URI to a valid SharePoint item, for example http://server/Shared Documents/File.ext
destinationFileName
The destination file name to download the item to. If the file already exists, it will be overwritten. This value cannot be null (Nothing in VB).
userState
The optional user-supplied state object that is used to identify the task that raised the DownloadCompleted event.
This method will return control immediately to your program and the DownloadCompleted event will occur when the download operation is completed (whether or not the operation is successful).
To download a file synchronously, use the DownloadFile method.
To download an item to a stream, use the GetDownloadStream or GetDownloadStreamAsync method.
To upload an item to SharePoint, use the UploadFile, UploadFileAsync, UploadStream or UploadStreamAsync method.
This example will download a document asynchronously at the specified SharePoint URI into a disk file and then get the image information using Leadtools.Codecs.RasterCodecs.
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/MySiteUri 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.tifstring documentName = SHAREPOINT_DOCUMENT_NAME;// Build the full URL to the document are we going to downloadUriBuilder 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 completesAutoResetEvent wait = new AutoResetEvent(false);// Download the SharePoint item to the temporary file asynchronouslyspClient.DownloadCompleted += new EventHandler<SharePointClientDownloadCompletedEventArgs>(MyDownloadFileAsyncCompleted);spClient.DownloadFileAsync(sourceDocumentUri, tempFileName, wait);// Wait till the operation completeswait.WaitOne();wait.Close();// Delete the temporary file we createdFile.Delete(tempFileName);}private static void MyDownloadFileAsyncCompleted(object sender, SharePointClientDownloadCompletedEventArgs e){// Remove our handlerSharePointClient spClient = sender as SharePointClient;spClient.DownloadCompleted -= new EventHandler<SharePointClientDownloadCompletedEventArgs>(MyDownloadFileAsyncCompleted);if (e.Error == null && !e.Cancelled){// All is OK, use RasterCodecs to get its infousing (RasterCodecs codecs = new RasterCodecs()){using (CodecsImageInfo imageInfo = codecs.GetInformation(e.DestinationFileName, true)){// Show the image infoConsole.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 occuredif (e.Error != null)Console.WriteLine(e.Error.Message);elseConsole.WriteLine("User cancelled");}// Tell whoever is listening that we are doneEventWaitHandle wait = e.UserState as EventWaitHandle;wait.Set();}