Thursday, November 20, 2008

Filter SharePoint List items based on User context

Filtering the items created by the logged in user can be done by simply modifying the existing View or by adding a new view which has "Created By" value = [Me].

But how to achieve the same thing in Code, Getting a list looping it and filtering the result will do. But sure performance will go down.

Here comes the CAML query for the rescue of SharePoint developer. CAML is having a token which automatically uses the current user context.

So we can write a code snippet as follows to get items created by the current user.



SPList sList=[Get the list to query here];
SPQuery query = new SPQuery();
query.Query = string.Format(
"[Where]"+
+ "[Eq]"
+ "[FieldRef Name='Author' LookupID='TRUE'/]"
+ "[Value Type='User'][UserID /][/Value]"
+ "[/Eq]"
+ "[/Where]");
SPListItemCollection listItems = sList.GetItems(query);


you will get the list items only created by the current user, no iteration, no filteration happens only clean CAML query.

Replace all square brackets[ ] with angle brackets < >. Blogger refused to accept the angle brackets.

Happy coding,

Tuesday, October 21, 2008

Free Microsoft Ebook

Microsoft is celebrating its 25th anniversary by providing some free MS Press e-books



Windows Server® 2008 TCP/IP Protocols and Services
by Joseph Davies
ISBN: 9780735624474



Programming Microsoft Robotics Studio
By Sara Morgan
ISBN: 9780735624320

Woes of IE 8 beta un-Installation

Finally I planned(got some guts) to evaluate IE 8 beta in my local virtual machines. After evaluating I wanted to rollback for IE 7 for SharePoint requirements. Rollback happened like a charm with out any hitches.

But after a few hours I got a crazy error message box, asking me to Abort, Retry & Ignore.



I checked my event viewer, there I found the following error under UserEnv category.

Event Type: Error
Event Source: Userenv
Event Category: None
Event ID: 1041
Date: 10/14/2008
Time: 9:58:30 AM
User: NT AUTHORITY\SYSTEM
Computer: JD1E4K
Description:
Windows cannot query DllName registry entry for {CF7639F3-ABA2-41DB-97F2-81E2C5DBFC5D} and it will not be loaded.
This is most likely caused by a faulty registration.
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

After digging a lot, no resolution was found. Finally I took a backup of Registry and did a quick search using the GUID in the error message. It seems to be in the following location.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions/

Delete the key and quit the Registry. Yeah done finally resolved the issue.

DISCLAIMER (As usual): Editing the registry may cause unpredictable problems in the machine, So take a BACKUP before proceeding.

Sunday, October 5, 2008

How to compact Virtual hard drives?

When we develop in our virtualized dev environment, the virtual hard disk will expand dynamically in size. The problem is they don't compact automatically when we clean-up the VHD's. steps to reduce the VHD in size

1. Remove all unwanted files in temp locations or use CCleaner to remove all unwanted files.
2. Uninstall all programs which are unused in the dev environment.
3. Defrag the disk by using the system defragmenter.
4. select Capture ISO Image from CD menu and browse to the Virtual PC additions
directory
5. Location is %ProgramFiles%\Microsoft Virtual PC\Virtual Machine Additions by default.
6. Mount Virtual Disk Precompactor.iso. The precompactor will start automatically.
7. Once it's done , shut down the Virtual Hard disk.
8. Select the VPC from the Virtual PC console. Click on the settings button and select the Harddisk1 from the left pane.
9. Click over the "Virtual Disk Wizard" button and click next in the wizard.
10. select Edit existing disk, next choose the compact option - this can take a while to complete

For more info KB888760 How to prepare a Virtual Server 2005 virtual hard disk file to send to Microsoft Product Support Services

Friday, September 26, 2008

FireFox easter eggs

Just an easter egg in FireFox 3.0, Type about:robots in its address bar and hit enter



Try about:Mozilla in its address bar you will be presented a red screen with a verse from The Book of Mozilla



hmmm due to the browser wars we got a few easter eggs and many compatibility issues in our web applications.

Thursday, September 25, 2008

Free Sql Server 2008 Ebook - Direct Download

As some of my friends felt bit difficult to make a download of free SQL Server Ebook. I would like to dedicate this direct download link to those who find it difficult to download and those who don't have hotmail ID or Live ID.

Download here:

Tuesday, September 23, 2008

Even Gmail server goes down.

Gmail is no exception from server errors, but it crashed graciously.