Development

Development

FYI, SharePoint stores dates in UTC

For the second time in the recent past,  I’ve run into unexpected date results from SharePoint.  The first time it happened with the FAST search engine and yesterday I encountered it on a second project while dealing with a simple list. Basically, when a user submits a date in a SharePoint Date and Time field (think list field), SharePoint stores it in UTC.  If SharePoint handles the rendering of that date then users never notice what happens behind the scene.  However, if we have to do something with that SharePoint DateTime field (like synchronize to a database) and we ask for...

Unable to load unit test - the assembly was not built with any known testing framework

Today, while working on some unit tests I encountered an issue I had not encountered before. After setting up a testing fixture and a base test(s) on a project, the test(s) failed to load in the NUnit GUI Test Runner.   An NUnit dialog stated: Not a Test Assembly The assembly was not built with any known testing framework   At first the thought was that the issue might be with the version of NUnit framework. Perhaps it was a mismatch with the GUI Runner version? This was not the case. This was a new install on a server that had never...

SharePoint ErrorCode 0x81020014 on CAML Update

Recently while working on a client SharePoint project I encountered the following error code and message while executing a CAML update statement against a list: <Results xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"><Result ID=\"1,Update\"> <ErrorCode>0x81020014</ErrorCode> <ErrorText>One or more field types are not installed properly. Go to the list settings page to delete these fields.</ErrorText><z:row ... xmlns:z=\"#RowsetSchema\" /></Result></Results> Frankly, the error message wasn't very helpful and I didn't see the issue right away but then I saw it -- I had used the wrong internal column name. The actual internal name in this case had a trailing 1 at...

Build a control to show the first non-blank field

Here’s a control that shows the first non-blank SharePoint field. I created it for Solien’s web site when I added the PageTitle field. By using this control, if content authors leave the PageTitle field blank the contents of the Title field are shown instead. By inheriting from Microsoft.SharePoint.WebControls.FormComponent we gain access to the Item property. using System.ComponentModel; using System.Web.UI.WebControls; namespace Solien.SharePoint { ...

SharePoint Development for Beginners: Adding a field to a page layout

Here’s how to add a new field to an existing page layout in Microsoft Office SharePoint Server 2007. Our current page layout uses the Title field both for the HTML title element shown browser’s title bar and for the header shown in the content. We want to separate these so that the HTML title can be different. We’ll be modifying the SolienInnerPage.aspx and SolienInnerPageNoLeftNav.aspx page layouts. Here’s an outline of the work we’ll need to do: Find the associated content type for the page layout Add a new site column...

Using the Test Data Builder Pattern in unit tests

In an application with lots of complex dependencies, writing unit tests that actually test a single unit of code is challenging. A customer has a large application where most of the "unit" tests are actually integration tests that rely on known test data in the database. For new development in this application, I've been moving toward true unit tests where possible. Using mock objects helps. Instead of the external dependencies for the system under test relying on the database, I mock the dependencies with RhinoMocks. Configuring the test data in the mocks is still painful, though, since each...

Creating a fake SMTP service with Tcl

Sometimes it's useful to have an SMTP service that doesn't actually send email. That's easy to do using Tcl. Here's the script to use: package require smtpd catch [wm withdraw .] catch [console show] proc deliver {sender recipients data} { set mail "To: $recipients\nFrom: $sender\nDate: [clock format [clock seconds]]" append mail "\n" [join $data "\n"] puts $mail } ::smtpd::configure -deliver ::deliver ::smtpd::start Here's what sending email from the command line looks like: C:\>telnet localhost 25...

Fun with regular expressions: Adding validators to a DetailsView

For a recent prototype, we needed to add required-field validators to a bunch of fields in asp.net DetailsView controls. We had to convert each BoundField to a TemplateField and add a RequiredFieldValidator. In other words, we needed to transform <asp:BoundField DataField="Country" HeaderText="Country" HeaderStyle-CssClass="importantHeader" /> to <asp:TemplateField HeaderText="Country" HeaderStyle-CssClass="importantHeader"> <ItemTemplate> <%# Eval("Country") %></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Country") %>'></asp:TextBox><asp:RequiredFieldValidator runat="server" Display="Dynamic" ControlToValidate="TextBox3" Text="Required" /></EditItemTemplate> ...

Stand back, I know regular expressions! (Part 2)

Now that we’ve got an asp.net DetailsView control with fields from a SubSonic ObjectDataSource and we’ve set the header text, it’s time to work on the code-behind code needed to update the object. The DetailsView template has the following fields: <asp:BoundField DataField="DirectMarketing" HeaderText="Direct Marketing" SortExpression="DirectMarketing" /> <asp:BoundField DataField="AffiliateMarketing" HeaderText="Affiliate Marketing" SortExpression="AffiliateMarketing" /> [... and lots of other fields] We’ll use Visual Studio 2008’s find and replace to generate the update code. Find what:...

Stand back! I know regular expressions!

Regular expressions in Visual Studio’s find and replace can save a lot of time. For a recent project, we used a DetailsView bound to an ObjectDataSource generated by SubSonic. The bound fields were almost, but not quite, what we needed. They were quickly updated with some regular expression magic. The DetailsView has camel-cased text for the field names and the header text. <Fields> <asp:BoundField DataField="CustomerBase" HeaderText="CustomerBase" SortExpression="CustomerBase" /> ...

Creating a DetailsView for a SubSonic data object

The DetailsView control helps accelerate web application development. For a recent ASP.NET project, we used it in conjunction with SubSonic to create a rapid prototype. The data objects generated by SubSonic make it easy to create and configure a DetailsView control. First, create the necessary controller if needed. Here's the partial class I created for the Share table: using System.ComponentModel; namespace CustomerProject.Data {     public partial class ShareController     {         [DataObjectMethod(DataObjectMethodType.Select,...

SharePoint: A potentially dangerous Request.Form value was detected from the client

Recently, while working on a few new web parts, I encountered an issue with adding these web parts to a page.  I started getting the following error: A potentially dangerous Request.Form value was detected from the client (ctl00$PlaceHolder1$ctl00$ctl00$RichHtmlField="<P align=center> <P..."). I tried removing other web parts and content from the page but it resulted in the same error message pointing to a different control. It turns out that while working on getting the .NET 3.5 working with MOSS 2007, I lost a section of the web.config: ...

Increase Stored Procedure portability with SQL Server Synonyms

Imagine a situation where a database driven application requires that SQL Server stored procedures be moved between development, stage, and production environments. This seems pretty common, right? Just script up the stored procedures and run the script in each environment.  Done.   But what if the stored procedures access multiple databases?  And what if the database names are not consistent across environments?  Although you could find and replace the database names in the stored procedure create script you'd rather not have to.  Ideally, the stored procedure create script would be portable and not specifically reference databases or tables directly. Enter SQL Server...

Why SharePoint Does Not Execute Job Definition Changes

A couple of weeks ago while working on a SharePoint customization it became necessary to use a SharePoint Job Definition.  As the customization progressed I noticed that the job execution was not executing new code modifications made to the job definition. At first I thought the issue had something to do with the development environment since I had previously encountered some odd debugging and build behaviors in the same environment.  I inspected the new custom assembly using Reflector.  The assembly was correct.  Then I inspected the SharePoint Solution to make sure the same custom assembly was being packaged up as expected. ...

Multiple web part connections

One of the MOSS 2007 features that ASP.NET developers often miss when writing a custom solution for WSS 3.0 is the QueryString (URL) Filter web part.  We often use the query string to define the filter for displaying lists or forms.  This web part gives users the flexibility to define the query string key value without affecting the functionality of the solutions.  For some of the custom solutions we have built for WSS 3.0, we have implemented our own QueryString Filter web part to provide similar functionality and flexibility.  With this web part, we can easily pass information from query...