Thursday, December 4, 2008

What is a quick way to get a .NET assembly's PublicKeyToken?

The quick and dirty way is to go into the .NET command prompt and type the following:

sn -T MyDotNetAssembly.dll

The above utilizes the strong name utility that comes with the .NET Framework.

Wednesday, November 26, 2008

Download tracking with WSS 3.0

WSS 3.0 does not have a mechanism for tracking who downloads which files with authenticated users. When I got confronted with this task, I decided to create a web user control that reads all the files in a document library and subsequently displays the file names using a series of "LinkButton" controls. I then attached this web user control to a SharePoint WSS 3.0 web page. I decided against using a Hyperlink object in favor of a LinkButton ASP.NET control for the following two reasons:

1) With a HyperLink ASP.NET control, users can right-click on the anchor and choose "Save target as" to save the file. This is not desirable because no event is triggered when that happens. On the other hand, a LinkButton control does not produce a right-click popup in a browser leaving the user with no choice but to click on the link.

2) I needed to put some business logic behind the click event of the LinkButton. The business logic essentially saves statistics along the lines of: timestamp, host address, user ID, and filename.

Wednesday, October 22, 2008

How to programatically delete a SharePoint 2007 field belonging to a list or document library?

Here's the code for deleting a field named "phone" in list "myList" on a site with URL http://mysite/:

try {

using (SPSite sitecollection = new SPSite("http://mysite/")) {

using (SPWeb web = sitecollection.OpenWeb()) {

web.AllowUnsafeUpdates = true;

// Delete Sharepoint SPField



Console.WriteLine("Done deleting column");



} catch (Exception ex) {



Tuesday, October 21, 2008

How do you break up a long SharePoint 2007 survey?

What do you do if you have a long SharePoint 2007 survey and you want to break it up into separate pages such that the user needs to click the "Next" button?


You must use branching on selected questions for this. All branching items would simply point to the next question. That produces a “Next” button.

Thursday, July 24, 2008

How to use built-in SharePoint 2007 engine to send email?

A straightforward way of sending email from within a SharePoint 2007 application is to use the Object Model. Here is some C# code that will do it for you:

bool isAppendHtmlTag = true;
bool isHtmlEncode = false;
string recipient = "";
string title = "This is the title";
string body = "This is the email <strong>body</strong>";


Sunday, July 20, 2008

Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances.

Recently I noticed that many of my ASP.NET applications that work with a SQL Server Express database that resides in the App_Data directory stopped working. The culprit error was "Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances.". I suspect that a SQL Server update went out that disables user instances. I have not been able to substantiate this suspicion yet.


The solution is to enable user instances with the following command:

sp_configure 'user instances enabled','1';

Disable user instances with the following command:

sp_configure 'user instances enabled','0';

Friday, July 18, 2008

How to change the connection string name in a .NET 3.5 LINQ to SQL class?

Here's the scenario:

You developed an application that uses "LINQ to SQL" with a connection string name (say aa-db). In production you want the name to be different (say bb-db). What do you need to do to change the connection string name?

1) Open the *.dbml file in a text editor.

2) Change the "SettingsPropertyName=" property to the new name

3) Open the "*.designer.cs" file that is associated with the LINQ class and change the value of global::System.Configuration.ConfigurationManager.ConnectionStrings[...].

How to edit group on the SharePoint quicklaunch in WSS 3.0 (and MOSS 2007)?

It is always a good idea to lock down SharePoint sites such that users do not see more information than they need to. At the organization where I work, we have a plethora of SharePoint groups. With any new website that gets created, a user with full rights gets to see a list of all the groups by going to "Site Actions / Site Settings / Advanced Permissions". There is always the danger that a user can inadvertently delete or add a user to the wrong group. One simple solution is to remove unneeded groups from the quicklaunch. Here's what you can do:
  • Click on Site Actions / Site Settings / Advanced Permissions
  • Click on any group on the quicklaunch under "Groups"
  • Click on Settings / Edit Group Quick Launch
  • On the "Edit Group Quick Launch" page, highlight any group and hit the delete key on your keyboard


Wednesday, July 2, 2008

What is an easy way to find out the internal name of a SharePoint 2007 list column?

The internal name of a SharePoint list column can be different from the display name. This could happen if a column name has been renamed to something else. For example, if you rename the "Title" column to, say, "Company Name", the internal name remains as "Title". Also, spaces in the display name are replaced with "_x0020_" in the internal name. The internal name of "Contract_x0020_Type" would be used for display name "Contract Type".

An easy way to discover the internal name without any programming is:

- add the column to a view
- click on the column name to sort the view by that column
- check the URL for the "SortField=" parameter value.

I did this for a column name "Company Name" and got a URL similar to this:

The above URL suggests that the internal field for "Compnay Name" is "Company_x0020_Name".

Note that the URL encoding for the underscore is "%5f".

Sunday, June 15, 2008

.netBC celebrates 5'th birthday and 1500'th member

The .netBC user group celebrated it's 5'th birthday on March 3, 2008. Soon after the group had it's 1500'th member when Hai Wang joined on April 5, 2008.

The Vice President of .netBC, Brian Pidcock, baked a pie for Hai Wang and presented it to him at our regular meeting on Tuesday May 6, 2008. Here is a picture of both Hai Wai and Brian Pidcock taken by a mobile phone:

Unfortunately, our speaker Dana Epp did not show up at that meeting held at BCIT in Burnaby, BC. When I contacted him the next day he said that he forgot about it. In the five years of the existance of our user group we never experienced a no-show by a speaker. I would like to apologize to those who attended for this unfortunate situation. John Bristowe of Microsoft Canada is sending me consolation gifts for those who came to this no-show meeting. These gifts will be delivered during our July 9, 2008 XNA event.

Tuesday, May 20, 2008

How to upgrade SharePoint 2007 web.config file from .NET Framework 3.0 to .NET Framework 3.5 support?

In order to take advantage of some of the great features of .NET Framework 3.5 in your SharePoint 2007, you will need to upgrade the web.config file. Some new features are LINQ, AJAX, and new controls like ListView. Here's a step-by-step task list of what needs to be added. Before we go on, make sure that you have installed the .NET Framework version 3.5 on the server. Also, make a backup copy of your SharePoint 2007 web.config file.
1) Add the following inside of the <configSections> tag block:

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>

<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>




2) Add the following inside of the <httpHandlers> tag block:

<remove verb="*" path="*.asmx" />

<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

3) Add the following inside of the <httpModules> tag block:

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

4) Add the following inside of the <assemblies> tag block:

<add assembly="System.Core, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

<add assembly="System.Data.DataSetExtensions, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Xml.Linq, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

5) Add the following inside of the <pages> tag block:


<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>


6) Add the following right before </configuration>:



<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">

<providerOption name="CompilerVersion" value="v3.5" />

<providerOption name="WarnAsError" value="false" />


<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">

<providerOption name="CompilerVersion" value="v3.5" />

<providerOption name="OptionInfer" value="true" />

<providerOption name="WarnAsError" value="false" />





<validation validateIntegratedModeConfiguration="false" />


<remove name="ScriptModule" />

<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />



<remove name="WebServiceHandlerFactory-Integrated" />

<remove name="ScriptHandlerFactory" />

<remove name="ScriptHandlerFactoryAppServices" />

<remove name="ScriptResource" />

<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />



Wednesday, April 30, 2008

How to get the whole announcement to show up in SharePoint 2007?

  1. Go into the Announcements section by clicking on the title.
  2. Create a new view based on the existing default. I called mine "All items with Body"
  3. Make sure the 'body' column is checked, and select "Newsletter" under Style.
  4. Go back to your main page, and select 'edit shared web part' for the announcements section you're working on.
  5. Change the view to be the new view you just created and click OK.

Tuesday, April 29, 2008

How to exclude content in a SharePoint 2007 site from being indexed by the search engine?

There are circumstances whereby content in a specific site needs to be excluded from the SharePoint 2007 search engine indexing process. This can be done at a list level and/or a site level.


 List level:
  • Settings / List Settings
  • Click on "Advanced Settings"
  • At the very botton under "Search" set "Allow items from this list to appear in search results?" to "No"
  • Click "OK" button
Site level:
  • Site Actions / Site Settings
  • under "Site Administration" click on "Search visibility"
  • set "Allow this web to appear in search results?" to "No"
  • Also choose "Never index any ASPX pages on this site" radio button
  • Click "OK" button
Remember to reindex search results in central administration so that these new rules immediately take effect. One way to do this is as follows:
  • On the SharePoint server, get into the "Central Administration" web application
  • Click on the "Shared Services Administration" link on the left-hand-side
  • Select "Open Shared Services Admin Site" from the dropdownlist of the default SSP site
  • Click on "Search settings" link under "Search"
  • Click on the link beside "Content sources:"
  • Select "Start Full Crawl" from the dropdownlist of the content source

Saturday, April 26, 2008

DevTeach & SQLTeach 2008 conference in Toronto

We are only two weeks away from this premier Canadaian technology conference which will be held in Toronto from May 12, 2008 to May 15, 2008. If you are a computer techie living on the eastern part of our North American continent, you must seriously consider attending this conferernce. It is well worth your time and money. There are some real well known heavy weight speakers who will be presenting. Check out the list at And if that is not enough to convince you, here are yet more reasons to be there:

Keynote by Scott Hanselman, Microsoft

Scott Hanselman is one of the most prolific, renowned and respected blogger ( and podcaster ( about technologies. Scott is a hands-on thinker, a renowned speaker and writer. He has written a few books, most recently with Bill Evjen and Devin Rader on Professional ASP.NET. In July 2007, he joined Microsoft as a Senior Program Manager in the Developer Division. In his new role he'll continue to explore and explain a broad portfolio of technologies, both inside and outside Microsoft. He aims to spread the good word about developing software, most often on the Microsoft stack. Before this he was the Chief Architect at Corillian Corporation, now a part of Checkfree, for 6+ years and before that he was a Principal Consultant at STEP Technology for nearly 7 years.

Silverlight 2.0 workshop

For the first time an independent conference is having a workshop on Building Business Applications with Silverlight 2.0. Join Rod Paddock and Jim Duffy as they give you a head start down the road to developing business-oriented Rich Internet Applications (RIA) with Microsoft Silverlight 2.0. In case you just crawled out from under a rock, Microsoft Silverlight 2.0 is a cross-browser, cross-platform, and cross-device plug-in positioned to revolutionize the way next generation Rich Internet Applications are developed. Microsoft’s commitment to providing an extensive platform for developers and designers to collaborate on creating the next generation of RIAs is very clear and its name is Silverlight 2.0. In this intensive, full-day workshop, Rod and Jim will share their insight and experience building business applications with Silverlight 2.0 including a review of some of the Internet’s more visible Silverlight web applications. This workshop is happening on Friday May 16 at the Hilton Toronto.

Bonus session: .NET Rock host a panel May 14th at 18:00

This year the bonus session (Wednesday May 14 at 18:00) will be a panel of speakers debating the Future of .NET. Where is .NET going? How will new development influence .NET and be influenced by .NET? Join Carl Franklin and Richard Campbell from .NET Rocks as they moderate a discussion on the future directions of .NET. The panellists include individuals who have strong visions of the future of software development and the role that .NET can play in that future. Attend this session and bring your questions to get some insight into the potential future of .NET! This bonus session is free for everyone. Panelists are: Ted Neward,Oren Eini ,Scott Bellware

Party with Palermo, DevTeach Toronto Edition

Jeffrey Palermo (MVP) is hosting Monday May 12th in Toronto is acclaimed "Party with Palermo". This is the official social event kicking off DevTeach Toronto. The event is not just for the attendees of Toronto it’s a free event for everyone. It’s a unique chance for the attendees, speakers and locals to meet and talk with a free beer. The event will be held at the Menage club location and you need to RSVP to attend. Get all the details at this link:

My presentations at this conference are:

Wed May 14, 2008 8:00 AM, SharePoint 101, Room: Lismer

Wed May 14, 2008 11:00 AM, Web parts for SharePoint 2007, Room: Lismer

Thu May 15, 2008 3:00 PM, SharePoint 2007 Advanced Development, Room: Lismer

Friday, February 29, 2008

How to hide View: menu on the right-hand-side of the SharePoint 2007 toolbar?

  • Display the view in a browser
  • Open the source in an editor. This is done by "right-click / view source" in IE
  • Search for "ms-listheaderlabel". It will land on a <td> tag.
  • Right under that <td> tag you will find another <td> tag with an ID like: ctl00_m_g_672c28cb_9a7b_4898_a26c_22eefe71074d_ctl00_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_onetViewSelector
  • Copy the ID into the clipboard.
  • Create a style in an editor as follows and use the ID that you copied into the clipboard:

<style type="text/css">




.ms-listheaderlabel {




  • Click on "Site Actions / Edit Page"
  • Add "Content Editor Web Part" to the page.
  • Cick on "open the tool pane"
  • Click on the "Source Editor ..." button on the far right-hand-side of the page
  • Copy and paste the <script ...> code from your editor into the "Text Entry -- Webpage Dialog"
  • Click "Save" button
  • Click "OK" button
  • Click "Exit Edit Mode" link.

Tuesday, February 19, 2008

DevTeach 2008 Toronto

Yes. I will be delivering three talks on SharePoint at the DevTeach 2008 conference in Toronto May 12-16 2008. I am thrilled to be invited once again after DevTeach Vancouver in November 2007. Check out the conference at
My presentations are:

SharePoint 101

SharePoint 2007 Advanced Development

WebParts for SharePoint 2007

Wednesday, February 13, 2008

How to enable session state in SharePoint WSS 3.0?

Before you can use sessions you first have to enable the session state module in the web.config file in a WSS 3.0 sharepoint site. Just uncomment the following line:

<add name="Session" type="System.Web.SessionState.SessionStateModule"/>

After that you can use the session object like you'll normally do with any ASP.NET web applications.

Sunday, January 13, 2008

How can a web page go to the bottom end as soon as it is loaded?

I needed to get a loaded web page to scroll down to the bottom of a long page. I was able to make that happen using some basic JavaScript. Here's my solution:

1) Place the following HTML at the page loaction where you want to go to automatically:

<a id="bottom" name="bottom"></a>

2) Add the following ASP.NET code that triggers some very basic JavaScript:

StringBuilder sb = new StringBuilder();

sb.Append("<script language='javascript' >");

sb.Append("window.location.href = '#bottom';");


ClientScript.RegisterStartupScript(typeof(Page), "Focus", sb.ToString());

Although thic technique pertains to ASP.NET 2.0, it really can be implemented in any other server-side technology.

Thursday, January 3, 2008

Unable to delete or customize a choice field in WSS 3.0

I needed to customize the HelpDesk template that is freely downloadable from Microsoft. I discovered that it is not possible to add any choice items or even delete the column. Here's what I experienced when I clicked on:
Service Requests ==> Site Settings ==> List Settings ==> Status

You will notice that the "Delete" button is missing and no choice items can be changed.
I discovered that the choice field is sealed in the feature template itself.


1) Open the schema.xml file located in the SharePoint 2007 12-hives directory at:

%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\HelpDeskServiceRequestsList\servicerequest

2) Search for the Status field.

<Field ID="{75AF1E7D-39F1-45db-908A-B7AD3F26531A}"



















3) Change the Sealed attribute value from TRUE to FALSE

4) Save the schema.xml file

5) Restart IIS