Wednesday, July 13, 2011

Know CAML Queries executed by SharePoint server–CAML Profiling

Did you ever want to know what CAML queries are executed by SharePoint Server?

Well, for troubleshooting and learning purpose, it is not a bad idea. After all, SQL Profiler has been helping us troubleshoot a lot of issues.

There may be products out there but I figured out a way to do it without spending extra bucks! And here it is…

Following facts helped me think about the solution:

1) SharePoint’s code does a very good job at logging everything it does and everything it encounters (if you are lucky enough to figure it out). The challenge is to figure out under what area and category CAML queries are logged (if at all being logged). Once this is figured out, watching it real time is easy, see next step

2) The ULS Viewer is the tool which allows you to filter the events that you want to watch and watch them real time as they are logged to ULS logs by SharePoint code.

Follow the steps below to see it in action:

1. Go to Central Administration-> Monitoring –> Configure Diagnostic Logging.

Expand the SharePoint Foundation Area and check Monitoring and select Verbose level (selecting anything else would not work)

SNAGHTML924829

image

2. I did IIS Reset after changing the setting. Not sure if that is required though.

3. Download and run ULS Viewer. Select ULS Logs as your data source as shown below:

SNAGHTML98d1a3

4. Now modify the Filter (Access it from Edit –> Modify Filter) to filter messages that contains the CAML word as shown below:

image

And that should be it! Go to any Lists and select a view, since views use CAML behind the scene, you should see and entry and watch the CAML that was executed.

Tuesday, July 12, 2011

Locate SharePoint FEATURE from Title

Many times, I wanted to know elements of a particular FEATURE (any scope) before I hit the Activate button so that I can inspect the elements manifests and understand what the FEATURE would do to the site (or site collection, farm or web application).

SNAGHTML116d43

And I figured out that is no straightforward way to locate the FEATURE on the SharePoint Root. I wish Microsoft had provided a link “Open FEATURE folder” on click of which, it opens the FEATURE’s root directory for me…. At least for the Site Collection Administrators?

Anyways, I needed it desperately, so I had to help myself. I also posted a question on SharePoint Overflow and see if someone has already done that before. I wanted to do it with minimum efforts and finally, came up with following simple PowerShell Script;

Explorer (Get-SPFeature | Where-Object {$_.GetTitle([System.Globalization.CultureInfo]::CurrentCulture) -eq "Content Organizer"}).RootDirectory
What it does is retrieves the FEATURE’s list and then applies filter to select FEATURE which matches my Title. Getting Title was tricky but not as much as you can see above. And finally, I wanted to save few more clicks and keyboard strokes, so I used “Explorer” command and opened the directory in  Windows Explorer!
Hope this helps….