Leadtools.SharePoint.Client Namespace > SharePointClient Class : UploadFile Method |
http://MySite
or http://MySiteCollection/MySite
. This value cannot be null (Nothing in Visual Basic).
public void UploadFile( string sourceFileName, Uri siteUri, string destinationPath )
'Declaration Public Sub UploadFile( _ ByVal sourceFileName As String, _ ByVal siteUri As Uri, _ ByVal destinationPath As String _ )
'Usage Dim instance As SharePointClient Dim sourceFileName As String Dim siteUri As Uri Dim destinationPath As String instance.UploadFile(sourceFileName, siteUri, destinationPath)
public void UploadFile( string sourceFileName, Uri siteUri, string destinationPath )
function Leadtools.SharePoint.Client.SharePointClient.UploadFile( sourceFileName , siteUri , destinationPath )
public: void UploadFile( String^ sourceFileName, Uri^ siteUri, String^ destinationPath )
http://MySite
or http://MySiteCollection/MySite
. This value cannot be null (Nothing in Visual Basic).This method will upload the content of sourceFileName to SharePoint server. The location and name of the destination item in the server is determined as follows:
DestinationFileFullUrl = siteUri + destinationPath
For example, assume the SharePoint server contains a folder with the following name:
http://site/Shared Documents/
And you want the uploaded item with the name File.ext
into this folder. You can perform this using this code:
Uri siteUri = new Uri(@"http://site"); string destinationPath = @"Shared Documents/File.ext"; sharePointClientObject.UploadFile(sourceFileName, siteUri, destinationPath);
You can use the .NET System.IO.Path and System.UriBuilder classes to build the path and URI of the items. No that destinationPath is allowed to contain slashes (/) as in HTTP URI's or forward slashes (\) as in Windows paths or a mix of both.
This method will not return until the item is finished uploading to the server. If an error occurs, this method will throw an exception.
To upload a file asynchronously, use UploadFileAsync.
To upload the data in a stream to the server, use UploadStream or UploadStreamAsync.
To down an item from SharePoint, use DownloadFile, DownloadFileAsync, GetDownloadStream or GetDownloadStreamAsync.
Private Shared Sub SharePointClientUploadFileExample() Dim sourceFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif" ' 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 Dim spClient As New SharePointClient() spClient.OverwriteExistingFiles = True ' Optional: Set the credentials: spClient.Credentials = New NetworkCredential(USER_NAME, PASSWORD, DOMAIN) ' Build the upload document full path (folder + file name) Dim destinationPath As String = Path.Combine(folderName, Path.GetFileName(sourceFileName)) ' Upload the document spClient.UploadFile(sourceFileName, siteUri, destinationPath) End Sub
private static void SharePointClientUploadFileExample() { string sourceFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\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); // Build the upload document full path (folder + file name) string destinationPath = Path.Combine(folderName, Path.GetFileName(sourceFileName)); // Upload the document spClient.UploadFile(sourceFileName, siteUri, destinationPath); }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2