July 2008 - Posts


I've been using NAnt a lot lately for deploying components to development and integration machines. The common misconception that I've heard from reluctant SharePoint folks around here is that we should be packaging SharePoint solutions in WSP (SharePoint solution files) instead of deploying components with NAnt. That's all great, I'm totally pro-WSP and all, but the thing people don't realize is that whether or not you're using WSP files, NAnt still compliments SharePoint deployments very well.

Even if I'm simply running STSADM commands, I would still use NAnt instead of writing batch files. NAnt can do so much more than WSP files are capable of doing such as: Modifying data in Web.Config files (xmlpeek/xmlpoke), creating Virtual Directories on your IIS site (mkiisdir), copying files (copy), etc.

One use I've found for NAnt is to deploy an InfoPath 2007 form to Central Administration and activate to my site collections, and adding Data Connection Library (.udcx) files to Central Administration. It was always a hassle to do that manually, and batch files are so 1980's.

So here is some NAnt XML that I've written to deploy InfoPath forms and Data Connections:

 

<property name="stsadm.exe" value="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.exe" />

 

<target name="DeployInfoPathForms" description="Deploys the InfoPath forms to SharePoint">

      <property name="formName" value="MyInfoPathForm.xsn" />

      <call target="DeployForm" />

      <exec program="IISRESET" />

</target>

 

<target name="DeployForm" description="Deploys an InfoPath form">

      <exec program="${stsadm.exe}" failonerror="false">

            <arg line="-o deactivateformtemplate" />

            <arg line="-url http://mysharepointsite" />

            <arg line="-filename &quot;.\PublishedForms\${formName}&quot;" />

      </exec>

      <exec program="${stsadm.exe}" failonerror="false">

            <arg line="-o removeformtemplate" />

            <arg line="-filename &quot;.\PublishedForms\${formName}&quot;" />

      </exec>

      <exec program="${stsadm.exe}" failonerror="false">

            <arg line="-o execadmsvcjobs" />

      </exec>

      <exec program="${stsadm.exe}">

            <arg line="-o uploadformtemplate" />

            <arg line="-filename &quot;.PublishedForms\${formName}&quot;" />

      </exec>

      <exec program="${stsadm.exe}">

            <arg line="-o execadmsvcjobs" />

      </exec>

      <exec program="${stsadm.exe}">

            <arg line="-o activateformtemplate" />

            <arg line="-url http://mysharepointsite "/>

            <arg line="-filename &quot;.PublishedForms\${formName}&quot;" />

      </exec>

</target>

 

<target name="DeployDataConnections" description="Deploys Forms Services Data Connection library files">

      <property name="dataConnectionPath" value=".\config\DataConnections" />

      <property name="dataConnectionFile" value="MyDataConnection.udcx" />

      <call target="DeployDataConnection" />

</target>

 

<target name="DeployDataConnection" description="Deploys a single data connection">

      <copy file="${dataConnectionPath}\${dataConnectionFile}" tofile=".\${dataConnectionFile}" />

      <attrib file="${rootPath}\${dataConnectionFile}" readonly="false" />

      <exec program="${stsadm.exe}">

            <arg line="-o adddataconnectionfile" />

            <arg line="-filename &quot;.\${dataConnectionFile}&quot;" />

            <arg line="-overwrite true"/>

      </exec>

      <delete file=".\${dataConnectionFile}" />

</target>

 

You’ll notice I had to make a copy of the data connection before I could deploy it. This is because the file was read only when it’s checked in source control, so I needed to make a copy and take off the read only attribute using the NAnt attrib task before I could upload the file (Otherwise STSADM will complain).

Now you can call NAnt to deploy all of your forms at once, or you could specify an individual form by calling: “nant.bat –DeployForm –D:formName=MyFormName.xsn” or “nant.bat –DeployDataConnection –D:dataConnectionFile=MyDataConnection.udcx”.

Happy NAnting!



In Silverlight 2 Beta 1, storing user settings in IsolatedStorage was almost as much of a pain as storing user settings in Vista Gadgets (Except you can write .NET code to stream the data to file instead of using JavaScript).

With the recent release of Silverlight 2 Beta 2, storing data in IsolatedStorage is as easy as storing and retrieving values from a web.config.

To store business objects into IsolatedStorage, I would recommend creating a Class in your Silverlight project to hold all of the user settings. You also need to set the “DataContract” attribute on any classes that you want to persist to IsolatedStorage as well as the “DataMember” attribute for the properties you’d like to persist. This will allow the class to be serialized into IsolatedStorage.

Here is an example of a simple entity class with some data that I’d like to persist:

using System.Runtime.Serialization;

 

namespace My.Silverlight.Application

{

    [DataContract]

    public class City

    {

        private string _cityName;

 

        [DataMember]

        public string CityName

        {

            get { return _cityName; }

            set { _cityName = value; }

        }

    }

}

 

Next, I’ll store this City object in my “UserSettings” object along with the Silverlight user’s e-mail address.

using System;

using System.Collections.Generic;

 

namespace My.Silverlight.Application

{

    public class UserSettings

    {

        private City _citySetting;

        private string _userEmailAddress;

    }

}

 

Lastly, I’ll clear the IsolatedStorage application settings, then add my UserSettings object and save to IsolatedStorage ApplicationSettings:

IsolatedStorageSettings.ApplicationSettings.Clear();

IsolatedStorageSettings.ApplicationSettings.Add("UserSettings", settings);

 

That’s it!

You could alternatively write string values into IsolatedStorage if you only need to store simple string values. The above examples shows you how to store business objects directly to IsolatedStorage. Keep posted for more articles on developing on Silverlight 2 Beta 2.