Programmatically creating a Rich Text Field in a SharePoint List

Sounds easy enough, but it wasn't immediately obvious.

The below creates a list, adds a Rich Text field with full HTML and adds it to the default view.

27   SPWeb oWeb = null;

28   oWeb = oSite.RootWeb;

29   Guid gList;

30   SPList oList = null;

31   gList = oWeb.Lists.Add("My List", "Some description", SPListTemplateType.GenericList);

32   oWeb.Update();

33   oList = oWeb.Lists[gList];

34   SPFieldMultiLineText oFldBody = (SPFieldMultiLineText)oList.Fields[oList.Fields.Add("Body", SPFieldType.Note, true)];

35   oFldBody.Description = "Replaceable Parameters: {password}, {userid}, {usergroups}, {usersite}, {siteadmin}";

36   oFldBody.RichText = true;

37   oFldBody.RichTextMode = SPRichTextMode.FullHtml;

38   oFldBody.Update();

39   oList.Update();


41   SPView oView = oList.DefaultView;

42   SPViewFieldCollection oViewFields = oView.ViewFields;

43   oViewFields.Add(oFldBody);

44   oView.Update();


SharePoint Copy list item to multiple sites - Feature

There doesn't seem to be any OOTB solution to copy list items to > 1 other site... so I wrote a quick aspx page and added it to a feature/solution which I would like to share with you.

The APX page just loops through the Web collection and checks for the list and if it's available enables a checkbox so you can copy the item.

The feature adds a context menu to a list item with a link to the page.

There's nothing compiled so it's easy to edit (just open the solution file).

Feature link: Download

To Do: Optimize sorting DataView/DataTable, add Doc Library support, add a FeatureActivated/Deactivated to add ASPX page to sitemap, add option to create list if it doesn't exist and change to a dll/code behind.

Keywords: SPGridView, SPList, SPListItem, Copy, Add, Deploy, Feature, context menu.

Notes: I haven't tested this in a production environment



Filtering SharePoint List Libraries with Web Part Filters

Sometimes you need to filter data (ListViews/DataViews/Other web parts) based on some criteria be it the persons name, their email, a specific date range or from a parameter.

Microsoft provide a number of these Web Parts called filters. The problem is they only provide these in the Enterpri$e ver$ion.

So I made my own and I'm sharing them with you....

ray1.net Web Part Filters feature is comprised of 6 web parts.

  1. ray1.net Content Connector. This is a simple Literal Control that renders the value of a connection, or the text you specify. You can use it with, say the UserFilter and render some text that says "Welcome to my site UserFilter value!"

  2. ray1.net Filter Web Part: Current Page. This web part provides a filter connection that send information about the current page. The page needs to be in a list. You can use this to filter content based on who created the page or the file size or the modified date.

  3. ray1.net Filter Web Part: Date. This web part provides a filter connection that sends information about a selected date or date range. Say you had a DataView web part that sent a parameter to an SQL stored procedure.

  4. ray1.net Filter Web Part: QueryString. This filter accepts a QueryString parameter and connects to another web part. Pretty simple really, name the filter the same as the querystring parameter and your done.

  5. ray1.net Filter Web Part: User Name. This web part provides a User Name connection filter. This web part makes this feature incompatible with WSS v3, as I use the "Microsoft.Office.Server.UserProfiles.UserProfileManager" class.

  6. ray1.net Filter Web Part: Web ID. This web part provides a filter connection that sends the Web ID. Another simple one, but useful... Say you have a bunch of sites using the same template and you wanted to filter an SQL query.

All the filters accept multiple connections, and this is what they look like in edit mode.

This is what they look like normally

Download link: ray1.net Web Part Filters

To do: I could add a Text Filter and maybe change the Content Connector to accept n number of connections.

Keywords: Filter, web part, listview, SPSlicerBaseWebPart, ToolPart, IWebPartField, GetConnectionInterface, Connection Consumer Provider