0

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)
    {
        password.AppendChar(c);
    }

    AuthenticationManager am = new AuthenticationManager();


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


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

        page.AddControl(text, -1);

        page.Save("testpage2.aspx");
        page.DisableComments();
        page.Publish();


    }
}
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.
0

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.

0

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).

0

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.