Sharepoint lead is a place where you can read about interesting topics related to sharepoint, and you can also post comments and suggessions.

Monday, May 28, 2012

CAML Designer: Try it now!

When you want to design/test your caml query, most of the time uses U2U CAML Query builder. Sometimes you get problem with connection but most of the time, it was working fine for most of the needs.

Recently, I tried CAML Designer which is really nice tool to try as alternative. WPF UI experience with many additional features may impress you to switch to this new tool.

Let me know your experience while evaluating

Thursday, May 17, 2012

PowerGUI script editor: powershell debugging and intellisense

​​​In this post I am going to show you how to use PowerGUI script editor for executing powershell. There are two main advantages of using PowerGUI:
  1. Dubugging of powershell script
  2. Intellisense support
So, let's start setting up PowerGUI to use with sharepoint 2010:
  1. Download and install latest version of PowerGUI.
  2. Download PowerGUI PowerPack for sharepoint.
  3. Start PowerGUI script editor​ and go to File > Powershell Libraries
  4. Click on "Add Module" and add downloaded "PowerPack for sharepoint" library here
  5. That will add another entry "Microsoft.Sharepoint.PowerShell" into the listing. Check the library to make it enable
  6. Restart PowerGUI script editor and you are ready to get started.

Wednesday, May 16, 2012

Best Practice: Maintaining scripts in your sharepoint project


Branding is the most important part of any sharepoint project. If you are planning to deliver branding in your release, you have to make sure your developer team is proactive to deliver quality branding from early stage of the project. In most of the branding project, jQuery and javascript becomes must-have part. Here we will discuss practices that can be followed to ensure quality deliverables.

  1. Manage script files
    From the very starting stage of your project, split your all javascript code in three files.
    1. jQuery.min.js - This will contain jQuery reference and should be reference first in order.
    2. jQuery.plugins.js - This should contain all custom plugins we used in it.
    3. ProjectName.js - This hsould contain all your custom code written to get your project pages work properly​​
  2. ​Choosing plugins for your project
    1. Download plugin bundle to your local computer
    2. Generally plugin will contain sample html files, jQuery and plugin script files.
    3. First thing to check is, jQuery version you are using in your project and the one which is used in plugin
    4. If they are different, replace their jQuery.min.js with the one we are using
    5. Properly test the sample provided in plugin in all browsers you are planning to support
    6. Once browser and version compability matches paste plugin's min.js at end of jQuery.plugins.js file.
    7. Implement plugin specific mark up wherever applicable
    8. Always use projectName.js to initialize plugin.
    9. Repeat above process when you choose to add any jQuery plugin
  3. Resolving CONFLICTS!
    Another challenging part is jQuery ready not working or custom plugin you are using is disturbing your site's css. Here are thoughts on the same
    1. Aways use _spBodyOnLoadFunctionNames.Push("yourFunctionName") to init your scripts in page load.
    2. Always use only necessary css from what plugin css has proviced and prefix class or ID in css as application. For example if a generic class .clear is used and you are calling plugin using $('#news') you should replace that with #news .clear. Do this for all css you include for the class

Final thoughts
Here I pointed out some of the best practices. Like this post? You like to add/correct something? please provide your feedback on the same.

SP.UI.ModalDialog.showModalDialog not working in chrome

In some version of browser, using will not work due to some reason. I found an alternate method to solve this problem, here is the javascript code:
var dialogSP = null;
if (SP.UI.ModalDialog.showModalDialog) {
    dialogSP = SP.UI.ModalDialog.showModalDialog(options);
} else {
    dialogSP = SP.UI.ModalDialog.commonModalDialogOpen(countryUrl, options, null, {});

jQuery.find not working in IE7 for xml data

As part of troubleshooting a shareoint functionality, we found that jQuery.find not working.
We were using jQuery.ajax to call a sharepoint web service and in success function, finding an element in response xml to render it on div.
We fixed this and there are couple of options to fix this that we found from stackoverflow.
1. add dataType: 'xml​' in jQuery.ajax and that will fix it.
2. in response, check for browser is IE7 and variable that is having data is blank, do it with another method, here is javascript code:
if ($.browser.msie && liHtml == "") {
    xml = new ActiveXObject("Microsoft.XMLDOM");
    xml.async = false;
    liHtml = $("XmlTagNameToFind",xml).text();
I hope this will he you as well.

Creating web application from existing content database

There are situations where you want to propagate one SharePoint web application to some other farm/machine.   I feel the fastest way is to take content database backup and restore it in your destination farm. I have done so in last couple of weeks and I have leaned how to quickly do that.
Here are quick notes from my experience:
I was provided with content database backup and source code. That makes be able to restore site and generate wsps from source code.
Creating  content database from backup:
Go to your database server and do following:
  • Create a blank database that will be used as content database 
  • Restore a database using content database back up from source farm.
Creating a web application:
  • Go to sharepoint central administration and create a new web application
  • While creating a new web application, use existing content database in database section
  • Sometimes if your database is too large, web application creation takes too long and times out. Don't worry at all. web application is still created successfully. It happened to me 4 times out of 5. 
Validating the web application:
  • Go to sharepoint central administration, click on application management. In "Databases" section you will find "Manage content databases"
  • Choose your application and it will show database status and number of site collections. If you are not sure how many site collections are there in backup, anything greater than 0 is good news.
Configure web application to work properly:
we are almost done now. Do following:
  • Go to sharepoint central administration
  • Click on "Application Management"
  • In "Site Collections" section click on "Change site collection administrators"
  • choose your web application set proper data in site admins.
Additional optional steps:
After performing all the above steps, it is still possible that you are not able to access your web application.
  • Last thing to do is to install and deploy wsp by using stsadm or your favorite method. 
It is always challenging to move applications from one farm to another. Specially when they are depending upon other service applications. In spent last two weeks to learn how to properly do that. I hope this will help you at some point during your sharepoint development.

stsadmin -o deploysolution shows access denied error for some files


After firing deploysolution, looking at system settings > farm solutions and the error looks something like "Can not overrite xxxx file, access is denied".


specified file in your error is read only in your web application directory. Most of the time this happens when you are using some source control system that is making the file read only when it is checked in. 


Go to properties of the file and uncheck read only. If you are running a farm and you got multiple application servers, you need to repeate this for each application server.


80% of the developers uses command line to deploy their wsp as it is the convinient way to add or upgraded the solution.


Got the same error? Don't worry try above solution. Didn't worked? Let me know which one worked for you?

Monday, May 14, 2012

using HttpContext.GetGlobalResourceObject in webpart development

I found interesting issue during working with global resource files this week.

Event if we are using HttpContext.GetGlobalResourceObject, web part was rendering data in English even if site language is other than English!

If we switch to edit mode, it was working sometime, but most of the time it was showing English text.

Root cause:
We tried creating a new application page and placed a webpart there, it was strange that it was working properly in the application page.

We finally found that at the time of reading resources through  HttpContext.GetGlobalResourceObject web part was not aware of the current UICulture

   1:  var strLinkText = HttpContext.GetGlobalResourceObject("file", "key");
   1:  var strLinkText = HttpContext.GetGlobalResourceObject("file", "key",SPContext.Current.Web.UICulture);

Finally after passing third argument from SPContext.Current.Web.UICulture it worked properly