If you want to upload a document to a share point library in a online environment 2013, here are the server side code to achieve this requirement.
string Url = "http://mysite/sites";
string libraryName = "My Documents";
string fileName = "c:\\sample.docx";
using (ClientContext clientContext = new ClientContext(Url))
{
SecureString passWord = new SecureString();
foreach (char c in "Password".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("[email protected]", passWord);
List list = clientContext.Web.Lists.GetByTitle(libName);
clientContext.Load(list.RootFolder);
clientContext.ExecuteQuery();
using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, list.RootFolder.ServerRelativeUrl.ToString() + "/" + fileName.Split('\\')[1], fileStream, true);
}
}
Happy SharePointing :-)

mayur panditPosted Dec 31, 2022, 11:38 AM
Https://codinglogic24.blogspot.com/2022/12/upload-file-in-sharepoint-folder-using-c.html
PreetiPosted Jun 24, 2020, 6:37 AM
I Have to bulk upload more than 35K images on my sharepoint site ..How can I do that?
Salana DharmaraoPosted Jul 22, 2019, 6:23 AM
What are the library reference we need to use for this?
umesh chapePosted Feb 18, 2019, 1:36 AM
Hi, I want to upload file with my windows credentials instead of onmicrosoft account. How can I do it?
Preethi SreedharanPosted Feb 7, 2019, 7:00 AM
We have a web portal created using .net and we have a sharepoint also. If a document gets uploaded in our web portal that should get auto upload in sharepoint under document folder also. Could you please help with the steps and code for the same