Rajesh's profileSharePoint SnippetsBlog Tools Help

SharePoint Snippets

An effort to collect SharePoint snippets

Rajesh Sitaraman

Interests

My MSDN Threads

Loading...Loading...
November 16

Call ASMX Web Service using JQuery in SharePoint

There was query raised in TechNet forums regarding loading the Web Service content in Web part.

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/4dc136e1-7c2c-49ff-bb1b-d81e9037d2f8

I posted below answer for that

Add a Content Editor Web Part and add the below snippet in the source editor.
You have to work on the processResult function for desired presentation of the fetched stock information.

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetQuote xmlns='http://www.webserviceX.NET/'> \
                        <symbol>MSFT</symbol> \
                    </GetQuote> \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: "http://www.webservicex.net/stockquote.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });
    });

    function processResult(xData, status) {
    var liHtml =$(xData.responseXML.text);
     $("#stockUL").append(liHtml);
    }
</script>
<ul id="stockUL"/>
November 07

SharePoint Property Bag

 

Property bag is a feature available in Windows SharePoint Services 3.0. Its nothing but a hash table of Key-Value pairs. It allows to add properties to objects in a SharePoint site.

image

Why to Use SharePoint Property Bag

The Property Bag hash table for a site can store any metadata as Key-Value pairs such as connection strings, server names, file paths, and other settings needed by your SharePoint application. Most of the time we will store the above settings in configuration file, which is common to the entire web application. If there is any setting specific each and individual sites in the web application, then we have maintain that many entries in the config file. To over come the above scenario we can use the SharePoint Property Bag.

There is no specific out of box user interface available to set or to read the property bag settings. In WSS 3.0 property bag values has to set/get using the object model. There is an option available in SharePoint designer to set/get the property bag settings. Go to Site -> Site Settings. click on the Parameters tab.  On this tab, you will be able to manipulate of all of your custom property bag values.

image

image

How to Use

SPSecurity.RunWithElevatedPrivileges(delegate()
        {
        try
        {
            using (SPSite RootSite = new SPSite(URL))
            {
                using (SPWeb SiteCollection = RootSite.OpenWeb())
                {                    
                    try
                    {
                        SiteCollection.AllowUnsafeUpdates = true;
                       // Get connection string from Property bag
                        if (SiteCollection.AllProperties.ContainsKey("ConnectionString"))
                        {
                            ConnectionString = SiteCollection.AllProperties["ConnectionString"].ToString();
                        }                        
                        // Set siteID in the Property bag
                        SiteCollection.Properties["siteID"] = siteID;
                        SiteCollection.Properties.Update();
                        SiteCollection.AllowUnsafeUpdates = false;                        
                    }
                    catch (Exception ex) 
                    { 
                      //Handle Exception  
                    }           
                }
            }
        }
        catch(Exception ex)        
        {            
        }
        });    

SharePoint Property Bag

What is SharePoint Property Bag

Property bags are a new feature of Windows SharePoint Services 3.0. A property bag enables you, as a developer, to add properties to objects in a Windows SharePoint Services site. Property bags are implemented by Windows SharePoint Services as a simple hash table of property names and values.

Why to Use SharePoint Property Bag

The Property Bag Settings can store any metadata as Key-Value pairs such as connection strings, server names, file paths, and other miscellaneous settings needed by your SharePoint application.

How to Use

   1:  SPSecurity.RunWithElevatedPrivileges(delegate()
   2:          {
   3:          try
   4:          {
   5:              using (SPSite RootSite = new SPSite(URL)
   6:              {
   7:                  using (SPWeb SiteCollection = RootSite.OpenWeb())
   8:                  {
   9:                      
  10:                      try
  11:                      {
  12:                          // Get connection string from Property bag
  13:                          ConnectionString = SiteCollection.AllProperties["ConnectionString"].ToString();
  14:                          // Set siteID in the Property bag
  15:                          SiteCollection.AllProperties["siteID"] = siteID;                     
  16:                      }
  17:                      catch (Exception ex) 
  18:                      { 
  19:                        //Handle Exception  
  20:                      }
  21:                      
  22:                      
  23:                  }
  24:              }
  25:          }
  26:          catch(Exception ex)        
  27:          {            
  28:          }
  29:          });        
August 02

Maximum hard limits for SharePoint

I got it from one of the thread in MSDN forums

3 Shared Services Providers per Farm
99 Web Applications per Farm
8 IIS Application Pools per web server
100 Content db's per Web App
50,000 Site Collections per database
50,000 Site Collections per Web App
250,000 Web sites per Site Collection

July 23

Embed JavaScript function to SharePoint page

 

<script>
function MyOnLoad()
{
alert('I will pop here..');
}
_spBodyOnLoadFunctionNames.push("MyOnLoad");

</script>