InfoPath Form Template stays in “installing” state

0 comments

When I was testing to deploy a solution containing some form templates I got an error. Not very strange, because I was testing it.

The main downside though was one of the templates remained in the installing state. Apparently the easiest way to remove this template is by using some custom code, in this case I just used a console application within my dev box:


static void Main(string[] args)
{
FormsService fs = SPFarm.Local.Services.GetValue("");

foreach (FormTemplate ft in fs.FormTemplates)
{
if (ft.Name.Contains("Blackberry"))
{
ft.Delete();
}
}
}
Tagged , | Leave a comment

Provisioning a Document Set

6 comments

In this post I’ll show you how to create a project in Visual Studio 2010 with the new SharePoint project and item templates to provision a Document Set from a feature.

DISCLAIMER: The examples are build on and tested against a Beta 1 build of SharePoint 2010 and a Beta 1 build of Visual Studio 2010, so there is no guarantee this will work on later versions or even on the Beta 1 build you’re running.

A Document Set is basically a content type just like all the others you can find in SharePoint, it derives from the Folder content type. So the steps you need to take to provision a Document Set content type are not that different as well.

We’ll start out by creating an empty SharePoint project in Visual Studio 2010 and work from there.

First we’ll add a Content Type item to the project. In the elements.xml file we place the following content:

<?xml version="1.0" encoding="utf-8"?>
<elements xmlns="http://schemas.microsoft.com/sharepoint/">
<contentType ID="0x0120D520002228EBDE71841343B23171CE351F7D39" Name="Test Doc Set" Group="Document Set Content Types" Version="2" ProgId="SharePoint.DocumentSet">
<folder TargetName="_cts/Test Doc Set" />
<fieldRefs>
<fieldRef ID="{038d1503-4629-40f6-adaf-b47d1ab2d4fe}" Name="Company" />
</fieldRefs>
<xmlDocuments>
<xmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/events">
<spe:Receivers xmlns:spe="http://schemas.microsoft.com/sharepoint/events">
<receiver>
<name>DocumentSet ItemUpdated</name>
<synchronization>Synchronous</synchronization>
<type>10002</type>
<sequenceNumber>100</sequenceNumber>
<assembly>Microsoft.Office.DocumentManagement, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</assembly>
<class>Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetEventReceiver</class>
<data />
<filter />
</receiver>
<receiver>
<name>DocumentSet ItemAdded</name>
<synchronization>Synchronous</synchronization>
<type>10001</type>
<sequenceNumber>100</sequenceNumber>
<assembly>Microsoft.Office.DocumentManagement, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</assembly>
<class>Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetItemsEventReceiver</class>
<data />
<filter />
</receiver>
</spe:Receivers>
</xmlDocument>
<xmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/allowedcontenttypes">
<act:AllowedContentTypes xmlns:act="http://schemas.microsoft.com/office/documentsets/allowedcontenttypes" LastModified="11/4/2009 3:30:17 PM">
<allowedContentType id="0x0101" />
</act:AllowedContentTypes>
</xmlDocument>
<xmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/sharedfields">
<sf:SharedFields xmlns:sf="http://schemas.microsoft.com/office/documentsets/sharedfields" LastModified="11/4/2009 3:31:50 PM">
<sharedField id="cbb92da4-fd46-4c7d-af6c-3128c2a5576e" />
<sharedField id="038d1503-4629-40f6-adaf-b47d1ab2d4fe" />
</sf:SharedFields>
</xmlDocument>
<xmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/welcomepagefields">
<wpf:AllowedContentTypes xmlns:wpf="http://schemas.microsoft.com/office/documentsets/welcomepagefields" LastModified="11/4/2009 3:31:50 PM">
<welcomePageField id="038d1503-4629-40f6-adaf-b47d1ab2d4fe" />
</wpf:AllowedContentTypes>
</xmlDocument>
<xmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/defaultdocuments">
<dd:DefaultDocuments xmlns:dd="http://schemas.microsoft.com/office/documentsets/defaultdocuments" LastModified="11/5/2009 8:39:24 AM" AddSetName="True">
<defaultDocument name="Enterprise Content Management.docx" idContentType="0x0101" />
<defaultDocument name="Extending Search.docx" idContentType="0x0101" />
</dd:DefaultDocuments>
</xmlDocument>
<xmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<formTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<display>DocSetDisplayForm</display>
<edit>ListForm</edit>
<new>DocSetDisplayForm</new>
</formTemplates>
</xmlDocument>
<xmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
<formUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
<new>_layouts/NewDocSet.aspx</new>
</formUrls>
</xmlDocument>
</xmlDocuments>
</contentType>
</elements>

As you can see, the basics are the same as for any content type. The main difference is in all the XmlDocument elements in there:

  • Some event handlers are hooked up to make sure the metadata gets pushed down into the child documents (plus some other stuff)
  • The content types that users are allowed to add to the set are specified
  • We specify which fields are shared between the documents the set contains
  • The fields that are shown on the welcome page are defined as well
  • We then specify if there’s default content to add when a new Document Set is created

After we’ve created the basic plumbing for the Document Set content type, we’ll need to make sure that the files that are required are created in the right place as well. In order to accomplish this we’ll add a SharePoint Module item to the solution. This module will create the welcome page and default content in the right location in the site collection. The element.xml file will contain the following content:

<?xml version="1.0" encoding="utf-8"?>
<elements xmlns="http://schemas.microsoft.com/sharepoint/">
<module Name="_ctsTest Doc Set_" HyperlinkBaseUrl="http://moss.contoso.com/sites/docsettest" Path="WelcomePages\Files\_cts\Test Doc Set" Url="_cts/Test Doc Set">
<file Url="docsethomepage.aspx" Path="docsethomepage.aspx">
<allUsersWebPart WebPartOrder="0" WebPartZoneID="WebPartZone_TopLeft" ID="g_ae6da3d4_9233_45d6_b9fd_6300815e16c6">
<![CDATA[Content omitted]]>
</allUsersWebPart>
<allUsersWebPart WebPartOrder="0" WebPartZoneID="WebPartZone_CenterMain" ID="g_d8062545_cc87_4e82_9c55_cae80486ffea">
<![CDATA[Content omitted]]>
</allUsersWebPart>
<allUsersWebPart WebPartOrder="0" WebPartZoneID="WebPartZone_Top" ID="g_651be1ba_c8bb_4d29_87b0_87c769cd5179">
<![CDATA[Content omitted]]>
</allUsersWebPart>
</file>
<file Path="Enterprise Content Management.docx" Url="Enterprise Content Management.docx" />
<file Path="Extending Search.docx" Url="Extending Search.docx" />
</module>
</elements>

We see that the page layout for the document set homepage is created in the _cts folder for the content type. The web parts that are placed on the page are configured here as well, so any modifications and additions will be used on the welcome page of all document sets based in this content type. Also the two documents for the default content are placed in the corresponding _cts folder in the site collection.

The final Visual Studio solution will look like this:

image

After deploying the solution and activating the feature, which is very easy to do with the new SharePoint stuff in Visual Studio (just press ctrl + f5), we can see that the _cts folder will be created in the site collection:

image

After we add the content type to a document library and create a new item based on the content type we’ll be presented with the following:

image

You can download the sample solution here: DocSetProvisioning.zip (62,88 KB)

DISCLAIMER: This hasn’t been properly tested, so there’s is no guarantee it will work. If it f***s up your farm, the most you can expect as support from me, is an email wishing you good luck with restoring it.

Tagged , | 6 Comments

Coding against a Document Set

3 comments

I’ve just had a 5 day training on development for SharePoint 2010. We’ve seen some cool stuff, were able to do some Hands on Labs and talk to other SharePoint experts about the new stuff that is coming up.

One of the best things though about this training was the ability to try some stuff out for yourself. The fact that no project managers or customers were bothering me for a week allowed me to finally take the time to look around in the object model, the central admin and the new front end interfaces.

Over the next few week I’ll be publishing some post on the things I’ve tried out.I hope to publish a lot more posts about SP2010 once Beta 2 comes available.

DISCLAIMER: The examples are build on and tested against a Beta 1 build of SharePoint 2010 and a Beta 1 build of Visual Studio 2010, so there is no guarantee this will work on later versions.

One of the things I was eager to try out is the new Document Sets feature. Document Sets allow you to group related documents together and share metadata between those docs. When you view a document set in a library, you are presented with a welcome page that shows the metadata of the set and the contents. The welcome page in itself is something you’re able to customize. So you can add web parts and other controls through the interface or SharePoint Designer to the welcome page.

First let me start by giving you some code you can use to show extra information about
the document set in a web part you can place on the welcome page:

try
{
     SPListItem item = SPContext.Current.ListItem;

     DocumentSet set = DocumentSet.GetDocumentSet(item.Folder);

     writer.WriteLine("ContentType: {0}<br/>", item.ContentType.Name);
     writer.WriteLine("Title: {0}<br/>", item.Title);
     writer.WriteLine("WelcomePageUrl: {0}<br/>", set.WelcomePageUrl);
     writer.WriteLine("ItemCount: {0}<br/>", set.Folder.ItemCount);
     writer.WriteLine("Welcomepage Fields:<br/>");
     DocumentSetTemplate template = set.ContentTypeTemplate;
     WelcomePageFieldCollection fields = template.WelcomePageFields;
     foreach (SPField field in fields)
     {
         writer.WriteLine("{0}<br/>", field.Title);
     }
}
catch (Exception)
{ }

First we get a reference to the current List Item through the SPContext. This list item is the main item for the document set that contains the metadata that is pushed into the child documents.

We then can get a reference to the DocumentSet by passing in the SPFolder of the item into a static method of the DocumentSet class. The DocumentSet class is stored in the Microsoft.Office.DocumentManagement.dll in the DocumentSets namespace.

The DocumentSetTemplate in turn contains more information about the fields that are shared or shown on the Welcome page.

In the next post I’ll show you how to provision a document set from a feature. Something that is quite easy to do with the new SharePoint project and item templates for Visual Studio 2010.

Tagged , , | 3 Comments

DateTimeField vs. FieldValue in a publishing page

0 comments

In one of our projects we needed to show the Modified date and time value in publishing page.

Not a big deal you would think. The only issue we had when using a FieldValue control is that the time that would be displayed was 1 or 2 hours later than the actual value.

After I changed this to a DateTimeField the difference was gone.

The only thing you need to add is a ControlMode=”Display” attribute to prevent editors from setting their own value in edit mode.

The difference is in the way the value is rendered. The FieldValue control does a ToString() and HtmlEncode on the value. The DateTimeField actually converts the value to local time by using the TimeZone class.

It’s all in the details!

Tagged | Leave a comment

BadImageFormatException when updating a Dynamics CRM Plug-in

4 comments

Today I was working on a Dynamics CRM 4.0 Plug-in we’ve developed in the past and I needed to update the plug-in on our CRM server.

When I loaded the assembly in the Plug-in Registration tool I got the following exception:

Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
An attempt was made to load a program with an incorrect format.
   at System.Reflection.Assembly._GetExportedTypes()
   at PluginRegistrationTool.AssemblyReader.RetrievePluginsFromAssembly(String path)
   at PluginRegistrationTool.AssemblyReader.RetrievePluginsFromAssembly(String path)
   at PluginRegistrationTool.RegistrationHelper.RetrievePluginsFromAssembly(String pathToAssembly)
   at PluginRegistrationTool.PluginRegistrationForm.btnLoadAssembly_Click(Object sender, EventArgs e)

Appearently this was due to the fact I was working on a 64 bit environment. When you place the tool in the 64bit folder of the sdk\bin folder, the error doesn’t occur anymore and you’ll be able to succesfully update your plug-in.

Tagged | 4 Comments

Silverlight: Multiple animations on one property through Transforms

0 comments

When you create two or more animations that work on the same property of an object, Silverlight will only use the last of the defined animations.

By using transforms you’re able to achieve the same effect anyway. For instance, I’ve got a rectangle that slides up and down by using an animation that works on the Canvas.Top property:

<userControl x:Class="TestAnimationTransform.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<userControl.Resources>
<storyboard x:Name="WaveTop" AutoReverse="True" RepeatBehavior="Forever">
<doubleAnimationUsingKeyFrames x:Name="WaveAnimationTop" BeginTime="00:00:00" Storyboard.TargetName="Rectangle" Storyboard.TargetProperty="(canvas.top)">
<easingDoubleKeyFrame KeyTime="00:00:00" Value="50">
<easingDoubleKeyFrame.EasingFunction>
<sineEase EasingMode="EaseInOut"/>
</easingDoubleKeyFrame.EasingFunction>
</easingDoubleKeyFrame>
<easingDoubleKeyFrame KeyTime="00:00:10" Value="400">
<easingDoubleKeyFrame.EasingFunction>
<sineEase EasingMode="EaseInOut"/>
</easingDoubleKeyFrame.EasingFunction>
</easingDoubleKeyFrame>
</doubleAnimationUsingKeyFrames>
</storyboard>
</userControl.Resources>
<canvas x:Name="LayoutRoot">
<rectangle x:Name="Rectangle" Fill="Blue" Width="50" Height="50" Canvas.Top="240" Canvas.Left="200">
</rectangle>
</canvas>
<userControl>

This will create an effect like this:

Install Microsoft Silverlight

If I want to apply an animation that jiggles the rectangle back and forth over the X- and Y-axis, I can’t use the Canvas.Top property anymore. So instead, we’ll add a Transform to the object and animate the properties of the Transform:

<storyboard x:Name="WaveJiggle" AutoReverse="True" RepeatBehavior="Forever">
<doubleAnimationUsingKeyFrames x:Name="XAnimation" BeginTime="00:00:00" Storyboard.TargetName="TranslateTransform" Storyboard.TargetProperty="X">
<easingDoubleKeyFrame KeyTime="00:00:00" Value="20">
<easingDoubleKeyFrame.EasingFunction>
<sineEase EasingMode="EaseInOut"/>
</easingDoubleKeyFrame.EasingFunction>
</easingDoubleKeyFrame>
<easingDoubleKeyFrame KeyTime="00:00:01" Value="80">
<easingDoubleKeyFrame.EasingFunction>
<sineEase EasingMode="EaseInOut"/>
</easingDoubleKeyFrame.EasingFunction>
</easingDoubleKeyFrame>
</doubleAnimationUsingKeyFrames>
<doubleAnimationUsingKeyFrames x:Name="YAnimation" BeginTime="00:00:00" Storyboard.TargetName="TranslateTransform" Storyboard.TargetProperty="Y">
<easingDoubleKeyFrame KeyTime="00:00:00" Value="20">
<easingDoubleKeyFrame.EasingFunction>
<sineEase EasingMode="EaseInOut"/>
</easingDoubleKeyFrame.EasingFunction>
</easingDoubleKeyFrame>
<easingDoubleKeyFrame KeyTime="00:00:01" Value="80">
<easingDoubleKeyFrame.EasingFunction>
<sineEase EasingMode="EaseInOut"/>
</easingDoubleKeyFrame.EasingFunction>
</easingDoubleKeyFrame>
</doubleAnimationUsingKeyFrames>
</storyboard>
<rectangle x:Name="Rectangle" Fill="Blue" Width="50" Height="50" Canvas.Top="240" Canvas.Left="200">
<rectangle.RenderTransform>
<translateTransform X="50" Y="50" x:Name="TranslateTransform"/>
</rectangle.RenderTransform>
</rectangle>

The result of this will look like the following:

Install Microsoft Silverlight
Tagged | Leave a comment

Displaying calendar items in an ItemStyle

0 comments

We frequently get the question to display the next x upcoming events in a rollup webpart. A content query web part is very suitable for this, but you will needa custom ItemStyle. Below you will find the xsl to display events in the following
format:

image

The custom itemstyle checks for the difference between all day events, events that span multiple days and checks for start and end times.

To use this itemstyle you will need to add EventDate and EndDate to the CommonViewFields and reference the ddwrt namespace in the top of your xsl:

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"

And finally here’s the itemstyle:

<xsl:template name="CalendarEvent" match="Row[@Style='CalendarEvent']" mode="itemstyle">
         <xsl:variable name="SafeImageUrl">
            <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
                <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="SafeLinkUrl">
            <xsl:call-template name="OuterTemplate.GetSafeLink">
                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="DisplayTitle">
            <xsl:call-template name="OuterTemplate.GetTitle">
                <xsl:with-param name="Title" select="@Title"/>
                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
            </xsl:call-template>
       </xsl:variable>
          <xsl:variable name="LinkTarget">
             <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
       </xsl:variable>
       <xsl:variable name="MultiDayEvent">
           <xsl:choose>
               <xsl:when test="starts-with(@EndDate,substring(@EventDate, 0, 11))">
                   0
               </xsl:when>
               <xsl:otherwise>
                   1
               </xsl:otherwise>
           </xsl:choose>
       </xsl:variable>
       <xsl:variable name="StartTimeIsEndTime">
           <xsl:choose>
               <xsl:when test="contains(@EndDate,substring(@EventDate, 11, 9))">
                   1
               </xsl:when>
               <xsl:otherwise>
                   0
               </xsl:otherwise>
           </xsl:choose>
       </xsl:variable>
       <xsl:variable name="DisplayDate">
           <xsl:choose>
               <xsl:when test="$MultiDayEvent = 0">
                   <xsl:choose>
                       <xsl:when test="@fAllDayEvent = 0">
                        <xsl:choose>
                               <xsl:when test="$StartTimeIsEndTime = 1">
                                   <xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate) ,1043 ,'dd-MM-yyyy H:mm')" />
                               </xsl:when>
                               <xsl:otherwise>
                                   <xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate) ,1043 ,'dd-MM-yyyy H:mm')" /> - <xsl:value-of select="ddwrt:FormatDateTime(string(@EndDate) ,1043 ,'H:mm')" />
                               </xsl:otherwise>
                           </xsl:choose>
                       </xsl:when>
                       <xsl:otherwise>
                        <xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate) ,1043 ,'dd-MM-yyyy')" />
                    </xsl:otherwise>
                   </xsl:choose>
               </xsl:when>
               <xsl:otherwise>
                   <xsl:choose>
                       <xsl:when test="@fAllDayEvent = 0">
                           <xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate) ,1043 ,'dd-MM-yyyy H:mm')" /> - <xsl:value-of select="ddwrt:FormatDateTime(string(@EndDate) ,1043 ,'dd-MM-yyyy H:mm')" />
                       </xsl:when>
                       <xsl:otherwise>
                           <xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate) ,1043 ,'dd-MM-yyyy')" /> - <xsl:value-of select="ddwrt:FormatDateTime(string(@EndDate) ,1043 ,'dd-MM-yyyy')" />
                       </xsl:otherwise>
                   </xsl:choose>
               </xsl:otherwise>
           </xsl:choose>
       </xsl:variable>
       <a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">
            <xsl:value-of select="$DisplayTitle"/>
        </a>
        <xsl:text> - </xsl:text><xsl:value-of select="$DisplayDate"/><br/>
    </xsl:template>
Tagged , | Leave a comment

What ASP.Net developers should know about jQuery

1 comments

Dave Ward has published a very good article about jQuery for ASP.Net developers on the MIX site. I found the part about unobtrusive JavaScript particularly useful.

With the recent improvements in ASP.Net for JSON and the ease of jQuery, all ASP.Net developers should embrace JavaScript for creating better user interfaces.

You can find the article here: http://visitmix.com/Opinions/What-ASPNET-Developers-Should-Know-About-jQuery

Tagged , | 1 Comment

Enhancements to Office client integration with Forms Based Authentication on SharePoint

0 comments

Recently Steve Peschka of the SharePoint Team blogged about improvements in Office client integration when you’re using Forms Based Authentication.

After installing an update for the Office Clients you are now prompted with a login box when you edit an Office document on a SharePoint site that uses FBA:

image

When you have a customized login page this will be shown instead, so users won’t be (or will be less) confused when they get a login form with your company’s branding applied.

Read more about it here:
http://blogs.msdn.com/sharepoint/archive/2009/05/13/update-on-sharepoint-forms-based-authentication-fba-and-office-client.aspx

Tagged , | Leave a comment

Useful SharePoint classes

0 comments

I just found out that the object model includes some very useful classes to speed up your coding efforts.

SPUtilty

Contains methods for redirecting users to the error page, access denied page or a custom url. You can get Full name and email adres of a user by passing in the logginname, send an email from the web context or determine if an lcid is an East-Asian lcid.

More information here:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.aspx

SPBuiltinFieldId

Contains variables for all the Guids of the built in fields. No need to worry about the difference between dutch and english MOSS sites.

SPBuiltInContentTypeId

Contains variables for all the Guids of the built-in contenttypes.

SPDiffUtilty

Shows the differences between two strings in Html format. So comparing “This is an initial string” with “This” returns the following: “This is an initial string

SPContentTypeId (structure)

Provides methods to determine the relationships between two contenttypes.

SPContentTypeUsage

Allows you to determine where contenttypes are used within the sitecollection. Here’s a useful post that shows code to audit the contenttype hierarchy:
http://soerennielsen.wordpress.com/2008/03/06/audit-your-content-type-hierarchy/

SPChangeQuery

Allows you to query your sitecollection for objects that have changed. This way you can audit changes in access rights for instance.

Tagged | Leave a comment