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".