←Select platform

DownloadFile Method

Summary

Downloads an item from a SharePoint server to a disk.

Syntax

C#
VB
C++
public void DownloadFile( 
   Uri sourceUri, 
   string destinationFileName 
) 
  
Public Sub DownloadFile( _ 
   ByVal sourceUri As Uri, _ 
   ByVal destinationFileName As String _ 
)  
public: 
void DownloadFile(  
   Uri^ sourceUri, 
   String^ destinationFileName 
)  

Parameters

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).

Remarks

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

To download a file asynchronously, use the DownloadFileAsync 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.

Example

This example will download a document at the specified SharePoint URI into a disk file and then get the image information using Leadtools.Codecs.RasterCodecs.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.SharePoint.Client; 
 
private static void SharePointClientDownloadFileExample() 
{ 
   // 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(); 
   try 
   { 
      // Download the SharePoint item to the temporary file 
      spClient.DownloadFile(sourceDocumentUri, tempFileName); 
 
      // Use RasterCodecs to get its info 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         using (CodecsImageInfo imageInfo = codecs.GetInformation(tempFileName, true)) 
         { 
            // Show the image info 
            Console.WriteLine("URL:        {0}", sourceDocumentUri); 
            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); 
         } 
      } 
   } 
   finally 
   { 
      // Delete the temporary file 
      File.Delete(tempFileName); 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.SharePoint.Client 
 
Private Shared Sub SharePointClientDownloadFileExample() 
   ' 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 
 
   ' Replace SHAREPOINT_DOCUMENT_NAME with a valid document on the folder above, for example 
   ' MyDocument.tif 
   Dim documentName As String = SHAREPOINT_DOCUMENT_NAME 
 
   ' Build the full URL to the document are we going to download 
   Dim builder As New UriBuilder(siteUri) 
   builder.Path = Path.Combine(builder.Path, folderName) 
   builder.Path = Path.Combine(builder.Path, documentName) 
   Dim sourceDocumentUri As Uri = builder.Uri 
 
   Dim spClient As New SharePointClient() 
 
   ' Optional: Set the credentials: 
   spClient.Credentials = New NetworkCredential(USER_NAME, PASSWORD, DOMAIN) 
 
   Dim tempFileName As String = Path.GetTempFileName() 
   Try 
      ' Download the SharePoint item to the temporary file 
      spClient.DownloadFile(sourceDocumentUri, tempFileName) 
 
      ' Use RasterCodecs to get its info 
      Using codecs As New RasterCodecs() 
         Using imageInfo As CodecsImageInfo = codecs.GetInformation(tempFileName, True) 
            ' Show the image info 
            Console.WriteLine("URL:        {0}", sourceDocumentUri) 
            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) 
         End Using 
      End Using 
   Finally 
      ' Delete the temporary file 
      File.Delete(tempFileName) 
   End Try 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.