0

I have several custom bits of information that I would like to store at the web-level, similar to how project-level properties are stored and accessed, like logo, title, etc on the _layouts/15/prjsetng.aspx page.

I could add these properties to a 1-row custom list, but this seems like a bad practice.

Some details on my implementation:

  • SharePoint-hosted app in SharePoint Online
  • Can use JSOM if necessary
  • No code-behind (No-Code Sandbox Solution)

Is this possible?

3

You can use Sharepoint site property bag to store web level properties like:

function tag() {
    var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
    var appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));

    var clientContext = new SP.ClientContext.get_current();
    var hostContext = new SP.AppContextSite(clientContext, hostweburl);

    var web = hostContext.get_web();
    clientContext.load(web);

    var webProperties = web.get_allProperties();
    clientContext.load(webProperties);

    webProperties.set_item("DirectoryTagged", true);
    web.update();

    clientContext.executeQueryAsync(TaggedSuccess, TaggedFail);
}

function TaggedSuccess(sender, args) {
    $("#results").text("Tagged your site.");
}

function TaggedFail(sender, args) {
    $("#results").text("Tagging failed");
}

http://blogs.realdolmen.com/experts/2013/05/22/building-sharepoint-hosted-apps-reading-and-writing-to-property-bags/

Saving data in Host web list is also a good idea. You can easily make changes to that data.For detailed implementation check:

https://stackoverflow.com/questions/24833053/store-properties-for-a-sharepoint-hosted-app

  • Thank you for describing both options. Based on this and PirateEric's recommend I'll likely go list. – Jim Barntish Sep 25 '14 at 19:03
2

Why would it be bad practice? It makes config changes much easier than having to redeploy code to fix. So long as everyone has read access and the appropriate people have contribute/full control, it works well. I do it for a variety of applications and workflows.

  • I guess maybe "bad practice" is a bit strong. Adding an entire list just to service 3 - 4 bits of data seems like overkill. Just wondering if there was a better/cleaner option. Of course my research isn't turning up many alternatives, so perhaps the list approach is the acceptable alternative. – Jim Barntish Sep 25 '14 at 16:58
  • 1
    I guess it depends on what the data is. I store things like email addresses that can be volatile in lists like this, that way the site admins have control over the information easily and I don't need to deploy code to resolve their config/admin changes. – Eric Alexander Sep 25 '14 at 17:23
  • Excellent point regarding volatility. – Jim Barntish Sep 25 '14 at 19:01

Your Answer

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.