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.
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.
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!
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:
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 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:-
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!