2

I'm working on a project at work where I am automating a process done in SharePoint 2013 that's currently done manually. The process involves uploading documents, applying properties of those documents to a list, creating wikiPages and then moving documents to a SharePoint site that is in a different site collection.

When I've done custom work for SharePoint in the past I've mostly just used JavaScript and content editor web parts. But in this situation I've ran into the cross-domain call problem when trying to make REST api calls to different sites.

Since I'm fairly new to SharePoint development, what would be the best method to make a program to perform these functions? I wanted to get some input before I get going too far down a path and find limitations I didn't know about.

Thanks for any information.

2 Answers 2

1

Could you not use the SharePoint cross-domain library SP.RequestExecutor.js? If I am not mistaken, it's built for solving that exact problem.

Here are some links to some resources about it..

https://dev.office.com/sharepoint/docs/sp-add-ins/access-sharepoint-data-from-add-ins-using-the-cross-domain-library

https://msdn.microsoft.com/en-us/library/office/dn735924.aspx

Here's a blog post about someone using it with REST and not JSOM:

http://weshackett.com/2014/02/sp-requestexecutor-cross-domain-calls-using-rest-gotcha/

And I'm sure you can find plenty more resources out there...

1

Options:

  • Use Server Side Object Model (SSOM). C#. Synchronous, very fast. Can only run from the SharePoint server
  • Use Client Side Object Model (CSOM). C#. Asynchronous, much slower. Can run from anywhere. I will recommend this approach. You can develop an app without polluting the server with customization. In case of an upgrade to SP2016 your code will keep working. With a few little tweaks it will also work against SharePoint Online in case you decide to move eventually. Example:

    var clientContext = new ClientContext(SITE_URL);
    clientContext.AuthenticationMode = ClientAuthenticationMode.Default; clientContext.Credentials = new DefaultNetworkCredential(USER, PASSWORD.GetSecureString()); Web web = context.Web; context.Load(web); context.ExecuteQuery(); Console.WriteLine("Connected to " + web.Title + " site");

  • You can also use REST to talk to SharePoint 2013. This is only useful if you are not using C#. Or maybe developing for Windows Phone. You will have to get the authentication token and digest yourself.(Example here)

Additional fancy things to do:

  • Instead of using hard-coded login and password, you can register an app with a token and a secret, which you can use to authenticate. But if you've never done it before an used only JavaScript and REST with SharePoint, for simplicity, I would just create a plain-old user AD account that your app will use to authenticate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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