Link to home
Start Free TrialLog in
Avatar of Information Services
Information ServicesFlag for United States of America

asked on

How do I push pdfs to a folder in sharepoint online?

We are wanting to push our direct deposit remittance documents to a folder on SharePoint Online for our employees.
Is it possible to connect to SharePoint in C# and transfer those files to a particular folder in SharePoint?
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Avatar of Information Services

ASKER

So Shaun, would the PDFs be part of a list or can I send them as documents within a document library?
You can do both but I recommend document library
So do I create a document library and then just move the objects into it?
Create document library, use C# to read documents as a byte array and submit to the document library via CSOM
public void UploadDocument(string siteURL, string documentListName,
string documentListURL, string documentName,

byte[] documentStream)
{

using (ClientContext clientContext = new ClientContext(siteURL))
{        

//Get Document List
List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);

var fileCreationInformation = new FileCreationInformation();
//Assign to content byte[] i.e. documentStream

fileCreationInformation.Content = documentStream;
//Allow owerwrite of document

fileCreationInformation.Overwrite = true;
//Upload URL

fileCreationInformation.Url = siteURL + documentListURL + documentName;
Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
    fileCreationInformation);

//Update the metadata for a field having name "DocType"
uploadFile.ListItemAllFields["DocType"] = "Favourites";

uploadFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();

}
}

Open in new window

https://stackoverflow.com/questions/9847935/upload-a-document-to-a-sharepoint-list-from-client-side-object-model
Thanks Shaun. Give me a little bit to try things and if all goes as planned, I should be able to award the points and close the question.
Shaun,
I'm having trouble locating the Microsoft.SharePoint dlll to reference in my project. Any tips on finding it?
Yes, for that DLL you need to have SharePoint installed on your dev computer. When I do SharePoint dev, I spin up an SPS cluster in Azure with Visual Studio.
Shaun,
I hate to be so dense, but do you know of an article that shows how to do that?
No problem. Here is an article for 2016 but in it, there is a link to 2013 if you prefer
https://cann0nf0dder.wordpress.com/2016/08/30/building-sharepoint-2016-development-environment-part-1-introduction/
Shaun,
We only have a SharePoint presence online. Is it possible to connect to that instance without a local installation?
ASKER CERTIFIED SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial