Question

It it possible to access the Web application/Farm level property bag using jQuery/Javscript/ClientContext? If not, then what are the possible alternatives to access Web Application Farm level property bags using jQuery/Javascript

I will appreciate the code example.

Was it helpful?

Solution

If you are going to get the property bags of your web application or farm OFTEN, you could create a custom HttpHandler to create a dynamic javascript file which will load the properties you want. See my blog post about how to create an httphandler. The idea is partly inspired from loading _spPageContextInfo If you think it is the way to go, I can tell more.

EDIT: I found this question very interesting and I created a simple solution which registers a httphandler. When you add this as script in your site you'll get all web properties. The http handler can be altered to suit different purposes. Details are on my blog.

OTHER TIPS

One thing is for sure that you will not be able to access the WebApplication/Farm scoped property bag from the JavaScript Client Object Model because there are no SPWebApplication or SPFarm objects in it. I think your best bet would be building a custom service as many people here have suggested and then exposing the desired property bag through that service.

You can use this SP WebService to do some of the work, the rest you'll have to use AJAX to do.

I'm not that strong in backend dev. but an example could be something like:

C#

public object JSONizedObject;
[WebMethod]  
public static string GetWebAppPropertyBag()
{
    // Logic goes here
    JSONizedObject = new JavascriptSerializer.Serialize(PropertyBag object);
    return JSONizedObject;
} 

Javascript (jQuery)

<script type="text/javascript">
$.ajax({
    url: "MyWebService.asmx/GetWebAppPropertyBag",
    type: "POST",
    contentType: "json/application; utf-8";
    dataType: "jsonp"
    success: function (xData, jqXHR) {  
        //Handle returned data here
    },
    error: function (jqXHR, responseType, responseText) { 
        //Error handling here 
    }
});
</script>

Hope this helps you :)

You can also dynamically generate javascript on the server side and register the function in code... This could be done through a webpart, usercontrol, or application page so it can be used in many situations...

You can build the javascript via a string builder and then register it...

Check out this example on msdn. Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top