Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
hard to give you code without knowing what you want to do. Simply pushing property bag values to a web service is probably not a good idea (it can expose sensitive data). –  Steve B Jun 18 '12 at 12:19
    
I want to get only the property value from a Web Application using client script. Security is not important for me. –  Geek Jun 18 '12 at 12:21
    
I would appreciate any code example of retrieving the Web Application level property using the web service. –  Geek Jun 18 '12 at 12:22
    
Still unclear about your goal. If you want to access a specific set of items in the bag will lead to a different kind of answer that if you want to return all items in the bag. In the former case, I would create a custom DTO class with your very specific data and a custom wcf service to return this data. In the later, if you are ok with the security and privacy impact, I would create a simple OData like service that wrap the property bag. –  Steve B Jun 18 '12 at 12:36
    
Steve, thank you for your concern. I just to want to access key/value pair in my javascript. –  Geek Jun 18 '12 at 13:57
add comment

4 Answers 4

up vote 4 down vote accepted
+50

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.

share|improve this answer
    
+ 1 I think it could be a good start as long as I will be available to acheive my goal. Please go ahead I'm open to your suggestion –  Geek Jun 18 '12 at 13:54
    
I would appreciate the implementation with an example. –  Geek Jun 18 '12 at 14:00
    
I'll try to find some time as soon as possible :) –  Anatoly Mironov Jun 18 '12 at 15:14
    
Here you have a solution for getting web application properties. Just extend further. –  Anatoly Mironov Jun 19 '12 at 21:13
    
Ok, I will test and get back to you. –  Geek Jun 21 '12 at 17:06
add comment

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

share|improve this answer
    
So, I will have to deploy a custom web service? –  Geek Jun 18 '12 at 13:53
    
@SPGeek Yes. This allows you to easily get the propertybag from your codebehind and then send it back to the clientside without having to perform a postback and lose necessary values/info. –  Daniel Ziga Jun 18 '12 at 14:03
    
could you please lay down the development steps? –  Geek Jun 18 '12 at 14:04
add comment

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!

share|improve this answer
add comment

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.

share|improve this answer
    
+1 Thank you for your suggestion. If not then I am looking for an alternative solution. –  Geek Jun 18 '12 at 13:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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