I have created a console application which interacts with Sharepoint Online using Microsoft CSOM and PnP. What I don't understand is how to deploy this code to Sharepoint and run it from Sharepoint. Any help would be greatly appreciated. I have included my code.

static void Main(string[] args)
    string siteUrl = "";
    string userName = "";
    SecureString password = new SecureString();
    string psd = "";
    foreach (char c in psd)

    AuthenticationManager am = new AuthenticationManager();

    using (var cc = am.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
        // Demo 1: Add empty page
        var page = cc.Web.AddClientSidePage();

        var text = new ClientSideText();
        text.Text = "Hello PnP";

        page.AddControl(text, -1);


New contributor
Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

You can't deploy C# code to SharePoint Online. API you're using is called Client Side Object Model. It's meant to be run on SharePoint's client. Now, that doesn't necessarily have to be client computer, it can be another server as well.


Client Side Object Model in SharePoint is meant to be executed on the client machine which can be any system where SharePoint is NOT installed.

Now, if I am not wrong, your CSOM and PnP solution is a console application. Console Applications cannot be deployed. They generate a .exe file which you can run.

If you want to execute CSOM and host it on SharePoint, then you should do it using SharePoint-Hosted Apps (Add-in).


Console Application normally runs in a Client computer or a Server.If you want to trigger this application automatically, you can create a Task Scheduler:

Console Application Using Windows Scheduler

Your Answer

Joel is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.