How to make DynaTree nodes expand only on clicking the arrows at the corners

In DynaTree sometimes you may want the nodes to not expand when yo click on them –  usually it expands it whether you click on the arrow at the corner or anywhere on the entire node text – so if you don’t want that behavior you need to initialize the tree with clickFolderMode: 1 and that’s it!

For details of how to initialize the DynaTree, check out the sample code in section 4.1 in DynaTree Documentation


How to add memcached to system start-up in Windows Server 2008

I have spent a whole day or two only in trying to make memcached start-up automatically on system restart in Windows 2008 Server system. I was getting this error “memcached.exe exits with Failed to ignore SIGHUP” when I tried to use the -d switch. In the end, it turned out to be pretty simple but trying to do it with Windows NT Resource Kit, PowerShell’s New-Service command, srvany.exe or the likes did NOT work at all for me. What worked for me was this:

  1. You go to Run > “RegEdit” hit enter.
  2. Then you find the key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  3. Add a string value to it, name it whatever you want and put the full path to the memcached.exe file into the value of it.
Add memcached.exe to startup in Registry
Add memcached.exe to startup in Registry in Windows 2008 Server

Now you should be able to see the memcached startup when you reboot the system.

PS: In case you have a dependent service on memcached, change its start-up type to Automatic(delayed)

How to manipulate a Windows Forms control from another thread and get return value via Invoke() method

I was working on a Windows Forms project and I had this requirement to basically do some manipulation on a TreeListView on the parent form (MainForm in this case) for which we already had a developed a method and also to get the return value back from it. To make life even easier, we needed to do this from a BackGroundWorker thread in this case. Now, the problem with Windows Forms controls is that they can’t be manipulated apart from the main thread, so I had to look for a work around of some sort. So here’s a little modified snippet of the code for your understanding:-

if (m.treeListView.InvokeRequired)
ra= (ReportData?)m.treeListView.Invoke(new Func<ReportData?>(
() => m.CreateDataforReport(“Rpt type”, false)));
//m is the main form’s reference!


So what I’ve done is that I passed the main form’s reference to the child form in the constructor and made the TreeListView and the CreateDataforReport public. Notice that I called CreateDataforReport method inside the Func<ReportData?> and not directly. This is what enables you to get the appropriate return value, be it string, integer or any complex type like I have it here.

What’s the difference between a mediocre and successful person’s mindset

The Middle Class competes…the World Class creates.What's the difference between a mediocre and successful mindset

The Middle Class avoids risk…the World Class manages risk.

The Middle Class loves to be comfortable. The World Class is comfortable being uncomfortable.

The Middle Class hungers for security…The World Class doesn’t believe security exists.

The Middle Class sacrifices growth for safety. The World Class sacrifices safety for growth.

The Middle Class focuses on having…The World Class focuses on being.

The Middle Class is frustrated…The World Class is grateful.

The Middle Class has pipe dreams…The World Class has vision.

The Middle Class trades time for money…The World Class trades ideas for money.

The Middle Class is problem oriented…The World Class is solution oriented.

The Middle Class sees itself as a victim. The World Class sees itself as responsible.

The Middle Class thinks it knows enough…The World Class is eager to learn.

The Middle Class chooses fear…The World Class chooses growth.

Taken from: The Secrets of the World Class by Steve Siebold

The type ‘System.IO.Packaging.Package’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘WindowsBase’

While I was working with the Open Office XML SDK 2.0, after I added the reference to the DocumentFormat.OpenXml assembly and tried to build the application I ran into this error message.

The type ‘System.IO.Packaging.Package’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘WindowsBase, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’

Turns out, all you need to do to fix it is to just add another reference to WindowsBase assembly that is found in the .NET Tab.

SharePoint 2010: Unable to see web parts deployment on a seperate server

Okay, we know SharePoint 2010 has a great feature of deployment where you can just press the F5 button to debug or right click and deploy the project on the local server BUT, how about when it comes to deploying the web parts on another server, lets say the production machine?! Well, when I did that for the first time, it was a really tiring and annoying experience. Here’s what happened: I packaged up the web part project, transported it to the other machine, ran the scripts for the deployment – everything was going so smooth until I found out that I just couldn’t see the damn web part anywhere when I tried to Insert them on a page there!!! Naturally, you’d think that okay I’m done deploying the web parts so let’s just add them up on the appropriate page and be done with it. After hours and hours of banging my head with this issue and chat with my friend here in office, Mathias Gustafsson. I finally found out that you need to go and enable the feature first in “The Site Collection Features” section in order to see those web parts. And to make things even worse, I had to to have higher administrative rights to do that, otherwise, you don’t even see the menu given in the screenshot here.

Sharepoint 2010 Site Collection Administration
Sharepoint 2010 Site Collection Administration

In the beginning I was able to install the web parts being the “Owner” of the site collection BUT NO!! To see those web parts in the SharePoint 2010 site and actually put them to some use, you need to be the “Site Administrator” not just the owner. YEAH RIGHT! Very intuitive!! That thing just cost me some 5-6 hours can you imagine that?! Anyways, I hope it helps relieve the pain of some of you out there.

Install-SPSolution: Admin SVC must be running in order to create deployment timer job

When I was trying to deploy the SharePoint 2010 WSP on another server using PowerShell, I got this error when I tried to run the Install -SPSolution command saying that:
Install-SPSolution: Admin SVC must be running in order to create deployment timer job

So all you need to do is to go to the Services section in Control Panel\System and Security\Administrative Tools and look for the service called SharePoint 2010 Administration, it was on manual start up, changed it to automatic and started it and gotten rid of this error. Simple isn’t it!

Where/How do we place/refer to images in SharePoint 2010 WebParts

Where are the images located in SharePoint project or webpart
The location of images in SharePoint 2010 Project/web part

This one is especially useful for the new bie because when you start with building webparts for SharePoint 2010, you often come to a point where you wanna add a URL somewhere, lets say programatically or in the CSS or may be in the ASCX code and you wonder, hey wait a minute where are the images for SharePoint placed anyway? How do I refer to them? So here’s your answer.

What you do is that you Right Click the Web parts project > Add > SharePoint “Images” Mapped Folder option. Doing that will give you an images folder inside your project directory and you can refer to that like this:


Have fun!

SPGridView’s OnRowDataBound event returning nulls – Unable to FindControls

Earlier today I was just playing around with SharePoint 2010 and thought I should do a simple task with SPGridView, that is to display the data and show an appropriate image in the “Status” column instead of the text. Hmm, sounds quite simple doesn’t it! But no, it turned into a misery. Well, when I started it was quite natural to use the OnRowDataBound event on that to capture the data and do some modifications with the controls (I was using TemplateFields in the SPGridView by the way), so I did that and I tried  doing things like e.Row.FindControl(“xyz”), e.Row.Cells[2] and using RowIndex property which was returning -1 where e refers to an object of GridViewRowEventArgs and there was nothing to get over there. It was nulls all around!

So here’s a sample of the code in the visual webpart that I was writing:-

<SharePoint:SPGridView ID=”spGvWorkOrders”  runat=”server” >
<asp:Label ID=”lbl_workOrderId” Text='<% # Bind(“Id”) %>’  runat=”server”></asp:Label>

<asp:Label ID=”lbl_workOrderTitle”  runat=”server” Text='<% # Bind(“Title”) %>’ ></asp:Label>

<asp:Image ID=”img_status” Width=”10px” ImageUrl='<% #StatusToImage(“\””+ Eval(“Status”)+”\””) %>’ runat=”server” />

And here is the function:-

protected string StatusToImage(string status)
if ( ( rowcount++ % 2) == 0)
return “~/_layouts/Images/WorkOrders/add.png”;
return “~/_layouts/Images/WorkOrders/arrow_up_green.png”;

Notice that I had been using the Bind function earlier but when I tried using it to send the value to StatusToImage function it did not work. Eval is the better option anyway in case you’re just interesting in displaying the data.

So what I did was that instead of using the event I just put the function call inside the ascx code so that whenever a row is created that function is called with the value of Status from the Data Source and with that value sent to a function, we can return back a string to give the path to the image file. The syntax however, is quite tricky and it took me a while to figure that out correctly but it worked in the end. Hope it will save you some time though!

Assignment List Web Part generates an error during configuration of SharePoint Learning Kit

Well, I started working with the SharePoint Learning Kit (SLK) 1.4 in MOSS 2007 and I was following the GettingStarted.pdf document that accompanies the package. So on Page 10 where you’re supposed to add the SLK Assignment List Web Part to a site, as I followed the instruction the site would not show anything, then I went back to the Site Actions –> Site Setting –> Web Parts and clicked on the AssignmentListWebPart.webpart. It showed the following message

“An error occurred. More information may be available in the server event log.”

Now it is important to note that the logs being referred to here are NOT the ones at C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\LOGS because these are the WSS logs.

The logs you need to see are the ones in the Administrative Tools –> Events Viewer. So when I checked that it said

SharePoint Learning Kit Error
System.Data.SqlClient.SqlException: Cannot open database “SharePointLearningKit” requested by the login. The login failed.Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’.

So now I knew that all I need to do is to grant access to the SharePointLearningKit database to the user NT AUTHORITY\NETWORK SERVICE and to do that just fire up SQL Server Management Studio, go to Security node –>Logins –> right click NT Authority\Network Service –> Properties –> User Mappings –> check the database SharePointLearningKit and simply check the db_owner  role for it to give it maximum access for the time being –> Press the OK button and you should be able to see the Web Part now!

%d bloggers like this: