Monday, August 30, 2010

Basic sharepoint web part in .NET

1     Created a new Windows Class Library project in VS2008
2     Added a reference to System.Web
3     Added the following ‘using’ statements:
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
4     Changed the default class from public class Class1 to public class Hello: WebPart
5     Wrote an override for the “RenderContents” function (I got fancy and stripped off the leading domain portion of the login, and later wrote more code to change the font and add the little % bar)
protected override void RenderContents(HtmlTextWriter writer)
{
 string name = this.Context.User.Identity.Name;
 writer.Write(" You are logged in as " + name + "! ");
}
6     Built the dll in release mode and put it in a shared dir on my machine.
7     Logged onto the mossdev server and copied the dll to the sharepoint server into the web server’s ‘bin’ directory (\Inetpub\wwwroot\wss\VirtualDirectories\80\bin)
8     Added a line to web.config to make the server trust the dll (\Inetpub\wwwroot\wss\VirtualDirectories\80\web.config). In the section of web.config, I added a entity that looked like this:
9     Went onto sharepoint, went to site settings (for the whole site), and chose ‘Web Parts’ under Galleries. Clicked New, found my ‘Hello’ part, and clicked ‘Populate Gallery’ which added it for use on the site.

1    Went to a site and added the part to my front page. Opah!

Tuesday, August 24, 2010

automating silent MSI installs

I had to dig a bit to figure this out, and I know I've done this before so I'm making a note here so I can find this information again the next time I forget about it.

To automate a standard MSI install, run it once and log all the properties to a file:
msiexec /i "My Program Installer.msi" /Lp options.log

Make a note of anything you change during this first run. Then take a look at your options.log file. It should have a lot of items like this:

Property(C): ProgramFilesFolder = C:\Program Files\
Property(C): SourceDir = E:\
Property(C): VersionNT = 501
Property(C): ALLUSERS = 1
Property(C): INSTALLLOCATION = C:\Program Files\Whoever\Whatever
Property(C): Manufacturer = Whoever


You can run a silent install by setting these properties on the command line. The ones in all caps are "public" so they can be set by msiexec:

msiexec /qn /i "My Program Installer.msi" INSTALLLOCATION="C:\MyFolder\Whatever"

That's all there is to it! Find the properties you want, pass them on the command line. I have no idea why I can't seem to remember the steps to do that.