28 Oct 2010

SharePoint 2010 Static Web Part to read Page Properties

• Create a new page property by creating a new Site Column
• Edit the Page content type and add the new Site column
• Now all pages will have the new property to edit
• Create your web part to read the Page Property, like

if (SPContext.Current.Fields.ContainsField("Your Page Property Name") && SPContext.Current.Item["Your Page Property Name"] != null)
myString = SPContext.Current.Item["Your Page Property Name"].ToString();
catch { }

• Install and Deploy the web part on the server
• Find the public key token of your part by looking it up under c:\windows\assemblies
• Register the web part as static in your masterpage or page layout:

<%@ Register Tagprefix="Applicable" Namespace="ApplicableWebPartLib.TwitterBlock" Assembly="ApplicableWebPartLib, version=,Culture=neutral,PublicKeyToken=2ee629bf628499ee" %>

• Use the web part on your page layout or master page:

<Applicable:TwitterBlock runat="server"></Applicable:TwitterBlock>

27 Oct 2010

Documenting C# ASP,NET Code Projects and Solutions

We all know we should be using ///<summary> and ///<remark> tags in our code to document it properly, right?

The cool thing about that is that you can then generate an XML file from Visual Studio with all your code comments in it.
To do that, right-click on your Project in Solution Explorer and choose the "Build" tab. Check the box marked "XML documentation file" and voila - next time you build, the XML file will be generated too.

Then what? Then, my friend, you can distribute the xml file with your dll, and other developers will be able to see your comments on your class methods and properties.

Also, you can generate a Help file (CHM)! To do that, download and install Sandcastle and the SandCastle Help File Builder (SHFB).

Then in SHFB, you can just drag in your DLL and the XML file will be automatically included.
Build your Help File and a CHM will be generated!
Open it from a local drive (CHMs don't work on a remote drive) and enjoy!

20 Oct 2010

Getting Schema Information from SQL Server

As an aide-memoire to myself and anyone else who cares, here is a (growing, unfinished) list of the various ways you can get schema data and metadata out of SQL Server.




2. sys_objects

3. sp_tables, sp_columns

18 Oct 2010

Sharepoint 2010 Page Properties - Push Changes To Sites and Lists

I'm a bit confused, and it's no wonder. I'm trying to add a custom metadata field to the Page Properties of all the Article Pages on my Publishing Site, and all its subsites. However, when I made the change by creating a Site Column in Sharepoint 2010 Designer, and adding it to the Article Page Content Type column list, the column did not turn up on my subsite pages.

Then I noticed that when editing Content Type columns, there's a button in the ribbon marked "Push Changes to Sites and Lists". I can't find any documentation as to how this button works, or even if it is a button at all, as clicking it seems to make it glow yellow, as if it's a status indicator. Even spookier, at this moment a Google search for "Push Changes to Sites and Lists" comes up with ZERO results!

So, let's open this up for discussion! What is this button for? I *think* it has to be enabled (i.e. glowing yellow) when I make a column change, but BEFORE I press Save, in order for any lists or subsites using the Content Type to register the change.

1 Oct 2010

Delete a User from the ASP.NET membership database

Here's a sweet stored procedure to delete an ASP.NET user by only passing through a UserName, and not the 4 obscure arguments that the aspnet_Users_DeleteUser sproc requires.

CREATE PROCEDURE [dbo].[DeleteUser]
@UserName nvarchar(50)

DECLARE @Error int;
DECLARE @UserGUID uniqueidentifier;


SELECT @UserGUID = UserID FROM aspnet_Users WHERE UserName = @UserName;
DELETE FROM aspnet_Profile WHERE UserID = @UserGUID;
SET @Error = @@ERROR; IF @Error <> 0 GOTO ErrorHandling;
DELETE FROM aspnet_UsersInRoles WHERE UserID = @UserGUID;
SET @Error = @@ERROR; IF @Error <> 0 GOTO ErrorHandling;
DELETE FROM dbo.aspnet_PersonalizationPerUser WHERE UserID = @UserGUID;
SET @Error = @@ERROR; IF @Error <> 0 GOTO ErrorHandling;
DELETE FROM aspnet_Membership WHERE UserID = @UserGUID;
SET @Error = @@ERROR; IF @Error <> 0 GOTO ErrorHandling;
DELETE FROM aspnet_users WHERE UserID = @UserGUID;
SET @Error = @@ERROR; IF @Error <> 0 GOTO ErrorHandling;

GOTO Final


GOTO EndOfProc



SELECT @Error as Result

If I helped you out today, you can buy me a beer below. Cheers!