Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Share .NET
>
Tutorial
> Upload file
The following example shows you how to upload a file.
C# example
using System; using System.IO; using System.Net; using Independentsoft.Share; namespace Sample { class Program { static void Main(string[] args) { try { Service service = new Service("https://independentsoft.sharepoint.com", "username", "password"); //Increase timeout to 600000 milliseconds (10 minutes). Useful when uploading large files. //Default value is 100000 (100 seconds). service.Timeout = 600000; FileStream fileStream = new FileStream("e:\\Test.docx", FileMode.Open); using (fileStream) { service.CreateFile("/Shared Documents/Test.docx", fileStream); } } catch (ServiceException ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Error: " + ex.ErrorCode); Console.WriteLine("Error: " + ex.ErrorString); Console.WriteLine("Error: " + ex.RequestUrl); Console.Read(); } catch (WebException ex) { Console.WriteLine("Error: " + ex.Message); Console.Read(); } } } }
VB example
Imports System Imports System.IO Imports System.Net Imports Independentsoft.Share Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Try Dim service As New Service("https://independentsoft.sharepoint.com", "username", "password") ''Increase timeout to 600000 milliseconds (10 minutes). Useful when uploading large files. ''Default value is 100000 (100 seconds). service.Timeout = 600000 Dim fileStream As New FileStream("e:\\Test.docx", FileMode.Open) Using fileStream service.CreateFile("/Shared Documents/Test.docx", fileStream) End Using Catch ex As ServiceException Console.WriteLine("Error: " + ex.Message) Console.WriteLine("Error: " + ex.ErrorCode) Console.WriteLine("Error: " + ex.ErrorString) Console.WriteLine("Error: " + ex.RequestUrl) Console.Read() Catch ex As WebException Console.WriteLine("Error: " + ex.Message) Console.Read() End Try End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*