Get query string parameter using javascript

Here is a function for getting the query string parameter values from a current window.

function gup( name )
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
    return results[1];

Eg: var = gup('parameterName');



Delete list items from an SPLIstItemCollection object

I got to delete the list items from a list. This sounds to be an easy task i.e. loop through the list item collection and delete the items. That would be the intuitive way, but then again this is the SharePoint Object Model. Lets see what would be the way to delete items.


     SPList spList = oWeb.Lists.TryGetList("My List");
     SPQuery query = new SPQuery();
     query.Query = string.Format("<Where><Eq><FieldRef Name='{0}'/><Value Type='Text'>{1}</Value></Eq></Where>", "Title", "SharePoint" );

     SPListItemCollection listItemColln = spList.GetItems(query);

     foreach (SPListItem item in listItemColln)

But when you execute the about code, you will go into an error i.e.

 Collection was modified; enumeration operation may not execute.

So to delete a list items from an SPListItemCollection object we need to follow another approach i.e.

SPList spList = oWeb.Lists.TryGetList("My List");
SPQuery query = new SPQuery(); 
query.Query = string.Format("<Where><Eq><FieldRef Name='{0}'/><Value Type='Text'>{1}</Value></Eq></Where>", "Title", "SharePoint"; 
SPListItemCollection listItemColln = spList.GetItems(query); 
int itemCount = listItemColln.Count; 
for (int i=0;i < itemCount;i++) 

And here you go. This way all the items are deleted from the list item collection. Happy Coding… 🙂

Modal dialog boxes in SharePoint 2010

One of the biggest improvements in SharePoint 2010 is the introduction of the Dialog Framework.  The Dialog Framework allows you to open pop-up dialogs inside of your browser window to present things such as forms.

New dialogs can be created using the SP.UI.ModalDialog.showModalDialog method (  The method takes in an options parameter which gives the details for what the dialog should display, such as the URL and the Title for the dialog.


function OpenMyWebPage() { 
    var options = { 
    url: "MySimpleDialog.aspx?isDlg=1", 
    width: 800, 
    height: 600, 

The easiest way to get started using the Dialog Framework is to create a wrapper function for creating your dialogs. Here is a simple wrapper function to use it with JavaScript:

function OpenDialog(url, title) 
    var options = SP.UI.$create_DialogOptions();  
    options.url = url; 
    options.title = title; 

Phone number validation using jQuery

Here is a custom script that I have written to validate a phone number. Hope this might help you 🙂

        function ValidatePhone() {
        var phoneRegExp = /^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/;
        var phoneVal = $("#txtPhone").val();
        var numbers = phoneVal.split("").length;
        if (10 <= numbers && numbers <= 20 && phoneRegExp.test(phoneVal)) {

The above function validates all kinds of generic international phone numbers, including that of the USA, may include () around area code as well as period, dash, space or nothing seperating numbers. International code needs to be seperated from rest by period, space or dash and my be prefixed with plus. Not overly restrictive but limits size and repetition of codes.

Phone number length should be minimum of 10 digits and maximum of 20 digits

Matches: 2155552527|(215) 555 2527|215.555.2527|+1 215-555-2527|+1.215.555.2527

Non-matches: +1215.555.2527|321654|+11+27 215-555-2527

Create a Web application using claims-based authentication

You can create a Web application that uses classic mode authentication or claims-based authentication.

To create a Web application that uses claims-based authentication:

  1. On the Quick Launch, click Application Management.
  2. On the Application Management page, in the Web Applications section, click Manage web applications.
  3. On the Web Applications Management page, on the ribbon, click Create.
  4. On the Create New Web Application page, in the Authentication section, click Claims Based Authentication.
  5. In the IIS Web Site section, click Use an existing Web site to select a Web site that is already created, or leave Create a new IIS web site selected. The Name, Port, and Path boxes are populated with either the existing Web site’s information or with suggested settings for a new Web site. The Host Header setting is optional and may not automatically populate.
  6. In the Security Configuration section:
    1. Under Allow anonymous, select Yes or No. If you choose to allow anonymous access, this enables anonymous access to the Web site using the computer-specific anonymous access account IUSR_<computername>, by default. If you choose not to allow anonymous access, it is disabled for all site collections in this Web application. If you choose to enable anonymous access, you can still disable it at for individual site collections in this Web application.
    2. Under Use Secure Sockets Layer (SSL), select Yes or No. If you choose to enable SSL for the Web site, you must configure SSL by installing an SSL certificate on all Web servers in the farm.

Important More authentication methods are available for Web applications. You can change the type of authentication used by a Web application after it is created. To do this, on the Quick Launch, click Security. Under General Security, select Specify authentication providers, and then select a zone to open the Edit Authentication page.

  1. In the Identity Provider Settings section, configure one or more of the following options:
  • Select the Enable Windows Authentication check box, expand the menu, and then select either Negotiate (Kerberos or NTLM) or NTLM. Select the Basic authentication (password is sent in the clear text) check box if you want to enable basic authentication as a fallback, if Kerberos and NTLM fail.
  • Select the Enable ASP.NET Membership and Role Provider check box. In the Membership provider name box, type the name of the Membership provider that authenticates the user. In the Role manager name box, type the name of the role manager that stores role information and verifies the role or roles of authenticated users.
  • Select the Enable authentication for these Trusted Identity Providers check box, expand the menu, and then select one or more Trusted Identity Providers. This option is not available if no Trusted Identity Providers are defined. To define a Trusted Identify Provider, see Manage trusts.
  1. The Redirection URL section defines the URL of the logon page for users that need to be authenticated. Expand the Default URL menu, and then select one of the default pages. Alternatively, click Custom URL and type in the URL of the logon page.
  2. Under Client Integration, select Enable Client Integration if you want your site to be able to launch applications for users.
  3. In the Public URL section, in the URL box, type the Web server name that users will see in the address bar of their browser for all pages in this Web application. The Zone box is automatically set to Default for a new Web application and cannot be changed from this page. You must extend a Web application to assign a different zone.
  4. In the Application Pool section, you can select Use existing application pool to use an application pool that is already created, or you can choose to leave Create a new application pool selected. To select an existing application pool, expand the list, and then click the application pool that you want to use. To create a new application pool for use by this Web application, click Create new application pool, and then complete the following steps:

.      In the Application pool name box, type a name for the new application pool, or use the suggested name.

  1. Under Select a security account for the application pool:
  • Select Predefined to use a system account, expand the menu, and then select the account.
  • Select Configurable to use an account that is registered as a managed account, expand the menu, and then select the account. Only accounts that are currently registered as managed accounts are listed in the menu. To register another account, click Register new managed account.
  1. In the Database Name and Authentication section, in the Database Server box, type the name of the database server that this Web application will use. In the Database Name box, type the name of the database that you want this Web application to use. Under Database authentication, select Windows authentication (recommended) or SQL authentication. If you select SQL authentication, in the Account box, type a user name of an account that has the credentials needed to connect to the database server, and in the Password box, type the password for that account.
  2. In the Failover Server section, under Failover Database Server box, if SQL Server database mirroring is implemented, type the name of the designated failover database server. This setting may be left blank.
  3. The Search Server section lists the search service that is available to this new Web application. This section is not configurable.
  4. In the Service Application Connections section, expand the Edit the following group of associations menu, and then click the appropriate association. This setting may be left blank.
  5. In the Customer Experience Improvement Program section, click Yes to send program errors and information to Microsoft for use in improving this application. Click No to opt out of this program.
  6. To accept the settings and create the Web application, click OK. This may take a few moments. After the Web application is created, on the Application Created page, click OK to return to the Web Applications Management page.Bottom of Form



Accordion Left Navigation in SharePoint 2010

>For converting the left navigation of a SharePoint site to an Expandable and Collapsible left navigation then complete the below steps
1. Create a custom navigation
2. Updating the master page with JavaScript files

1. Create a custom navigation
– Go to “Site Settings” Click on “Navigation” link under “Look and Feel Section”
– Select “Display the navigation items below the current site” under “Global navigation” section
– Create the Structure of the navigation under Current navigation

NOTE: If we have links under any heading then do not give any URL for the heading.

Updating the master page with JavaScript files
a)Open the Site in SharePoint Designer
b)Include a reference to jquery library in the master page. You can find the jquery library from
c)Now update the master page with the below script

//Starts when DOM is ready

//For each Quick Launch navigation sub menu:
//Find any navigation items under the sub menu that have been selected.
var selectedNavItems = $(this).find(“”);

//Find the corresponding navigation header of the current sub menu being processed
var menuHeader = $(this).parents(“tr:eq(0)”).prev(“tr”).find(“”);

if ($(menuHeader).hasClass(“ms-selectednavheader”) || selectedNavItems.length > 0)
//if the navigation header for this sub menu is selected or if there are any
//selected navigational items in this submenu, show the submenu.
//otherwise, hide the submenu

//When a user clicks a navigation header, the user should be taken directly
//to the site link. The javascript event handler to hide/display the submenus
//should not be triggered.

//When the user hovers over the navigation header, it would be nice
//to have an indicator that they can click on the header. Usually,
//browsers use the hand icon to indicate clickable items.
$(this).css(“cursor”, “hand”);
}, function(e){
$(this).css(“cursor”, “default”);

//Finally, this adds a click event handler for the navigation header table
var subMenu = $(this).parents(“tr:eq(0)”).next(“tr”).find(“”);
if (subMenu.length > 0)
//only if we have a submenu should we hide the other submenus and show the current one.


This completes the changes to be made for achieving an Expandable and Collapsible left navigation control. Now on saving the master page file, left navigation is converted to expand\collapse left nav

SharePoint WebPart Life Cycle


Below is the list of methods that are being called in the Web Part life cycle.

  • protected override void OnInit(EventArgs e)
  • protected override void OnLoad(EventArgs e)
  • protected override void CreateChildControls()
  • protected override void LoadViewState(object savedState)
  • protected override void OnPreRender(EventArgs e)
  • protected override void Render(System.Web.UI.HtmlTextWriter writer)
  • protected override void OnUnload(EventArgs e)
  • public override void Dispose()

– OnInit: Configuration values set using WebBrowsable properties and those in web part task pane are loaded into the web part

– OnLoad: User generated events life button trigger events are loaded into the scope of web part.

– CreateChildControls: All the controls specified are created and added to controls collection.

When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() – It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it

– LoadViewState: The view state of the web part is populated over here

– OnPreRender: Here we can change any of the web part properties before the control output is drawn

– Render: Html Output is generated.

– OnUnload: I think the memory assigned to perform all the above tasks are unloaded here

– Dispose: This will dispose the references of the web part from cache of server as the web part is completely loaded


– LoadViewState only occurs on postback.

– On a button click steps 1, 2, 3 and 4 will be processed before any onClick methods.


Database diagram support objects cannot be installed because this database does not have a valid owner.


Recently I restored a database onto my SQL Server 2008 server. When I tried to create a database diagram for the restored DB then I observed the below mentioned error.

“Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects”

Scenarios 1:
When a DB that that is inherited from previous version of SQL Server having the database owner as a login that has been changed or not having any permission on this new instance
– Change the owner of the DB to SQL Authentication and then start creating DB Diagrams. Go to DB Properties –> Files –> Update Owner field and click OK

Scenario 2:
This error also occurs when the user has initiated the SQL Server Express on top of an MSDE 2000 instance.
– User must check the database compatability level set when it is restored/upgarded on to SQL Express instance
– Change the compatibility of the DB. Go To DB Properties –> Options –> Set Compatibility level as to an earlier version

STSADM.EXE is not a valid Win32 application


I had a strange experience with MOSS 2007. As I’m working in my Virtual MOSS environment using STSADM.EXE utility, a pop up is being displayed with the following text

STSADM.EXE is not a valid win32 application

I was bit confused and started diagnosing the issue:

– Restarted the IIS

– Restarted the server machine

– Navigated to 12 hive bin and started STSADM from that location

None of the above trials are successful.

Finally I found out that STSADM.EXE has been corrupted, its windows icon is lost and the file size is being shown as zero.


Copy and paste the STSADM.EXE from other machine where SharePoint is installed.

Scenarios where in this issue occurs:

– Whenever we try to update and deploy a WSP Package

– When a new site is being created using STSADM utility

Root Cause:

Tried to figure out what has made the stsadm utility to be corrupted but ended up with no information.

If anyone else has encountered this error and/or has been able to reproduce it, please do post a reply