web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Upload File – Sharepoint

RockwithNav Profile Picture RockwithNav 8,370 Super User 2025 Season 2

 

Hey Friends,

Many of us might have worked on different storage areas of a specific file and would have worked on several API’s to process a file to a certain location. I got one of the request from my customer where they urge to upload directly onto share-point. So I completed that stuff where they can simply upload the file and the dedicated SharePoint server will receive the file right away. Normally it will take a bit of time in Authenticating the server credentials and all for the first time then from the next time the execution time will somehow reduced. Still I will recommend not to upload directly if it could have an alternate because if it’s a big file then it could make you wait longer.

So here is the set of code which you need  to write

//RWN
ClientContext := ClientContext.ClientContext(‘URL’);
ClientContext.Credentials := NetworkCredential.NetworkCredential(‘Username’,
‘Password’,’Domain’);
FileCreationInformation := FileCreationInformation.FileCreationInformation;
FilePathL := FileManagementL.UploadFile(Text010,”);
FileCreationInformation.Content := FileContent.ReadAllBytes(FilePathL);
FileCreationInformation.Url := FileManagementL.GetFileName(FilePathL);
FileDirectoryL := FileManagementL.GetDirectoryName(FilePathL);
FileExtensionL := FileManagementL.GetExtension(FilePathL);
FileCreationInformation.Overwrite := TRUE;
Web := ClientContext.Web;
MyList := Web.Lists.GetByTitle(‘Library’);
//Folder
FolderName := MyList.RootFolder.Folders.GetByUrl(‘Folder Name’);
FolderName.Files.Add(FileCreationInformation);
//Library
MyList.RootFolder.Files.Add(FileCreationInformation);
ClientContext.ExecuteQuery;
//RWN

ClientContext DotNet

Microsoft.SharePoint.Client.ClientContext.’Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’

FileCreationInformation DotNet

Microsoft.SharePoint.Client.FileCreationInformation.’Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’

FileContent DotNet

System.IO.File.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

MyList DotNet

Microsoft.SharePoint.Client.List.’Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’

Web DotNet

Microsoft.SharePoint.Client.Web.’Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’

NetworkCredential DotNet

System.Net.NetworkCredential.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

FolderName DotNet

Microsoft.SharePoint.Client.Folder.’Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’

SharepointFile DotNet

Microsoft.SharePoint.Client.File.’Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’

FileLink DotNet

System.String.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

CHEERS

 


This was originally posted here.

Comments

*This post is locked for comments