Optimizing recompilation of SharePoint features, removing IE7 login session.

by Daniel Halan 6. August 2007 20:22
When developing new features for SharePoint you have to recompile and reinstall the feature a lot, one of the more time consuming moments are when you reset the IIS and try to restore the login session in an already open IE window, ie. by clicking on various links in the site.

The trick is to remove the old login session variable that is stored as a cookie. 
To remove the cookies you can add this line to your install.bat after "CALL iisreset".
"RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2"

This works only with IE7, if anyone know how to remove cookies on other browsers please drop a line.

How to create a new Form from Template in a Form Library, programmatically.

by Daniel Halan 31. July 2007 03:38

Creating new files in a Document Library is a pretty simple task as copying the template located in the "Forms" folder. But creating a new Form is a bit harder as the template is a binary file, and what we want is a new Xml file.

The template file (with extension XSN) created by InfoPath is actually a CAB archive, that contains your form logic compiled, schemas and your xml template. So what you have to do is extract the CAB file, and copy the "template.xml" file to your Form Library. You can find a CAB extractor at The Code Project.

Here is a example of a method to get the template Xml:

private byte[] GetXmlForm(SPDocumentLibrary list) {
  byte[] data = null;
  SPFile file = list.ParentWeb.GetFile(list.DocumentTemplateUrl);
  Extract cab = new Extract();
  string szFolder = string.Concat(System.IO.Path.GetTempPath(), list.Title, "\\");

  if( !Directory.Exists(szFolder) )
    Directory.CreateDirectory(szFolder);

  cab.ExtractStream(file.OpenBinaryStream(), szFolder);
  FileStream fs = new FileStream(szFolder + "template.xml", FileMode.Open);
  try {
    data = new byte[fs.Length];
    fs.Read(data, 0, data.Length);
  } finally {
    fs.Close();
  }
  return data;
}


There is one more thing that has to be done before saving the template, which is to add a hyperlink to your InfoPath Template. The href should be added in the processing instruction tag "mso-infoPathSolution" ie.
<?mso-infoPathSolution href="http://server/site/library/Forms/myTemplate.xsn" ?>

Here is a snippet on how to do it:

frm.SetTemplateUrl("http://Server/Site/{0}"+list.DocumentTemplateUrl);

public
void SetTemplateUrl(string url) {
  foreach(XmlNode n in m_Doc.ChildNodes) {
    if(n.Name == "mso-infoPathSolution") {
      string szHref = string.Format("href=\"{0}\"", url);
      Regex r = new Regex("href=\".*\"");
      if(r.IsMatch(n.Value))
        n.Value = r.Replace(n.Value, szHref);
      else n.Value = string.Concat(n.Value,szHref,' ');
    }
  }
}


 

Undocumented CAML Field Element types

by Daniel Halan 28. July 2007 23:27

The documentation on MSDN defines 11 different field types, but inside SharePoint administration you can specify more types when creating a column. such as "Person or Group" and "Calculated". These types are not documented but are possible to set in the type attribute. Here is the whole list:

AllDayEvent
Specifies an all day event. 

Attachments
Contains attachments. 

Boolean
Contains Boolean values that are stored in the database as 1 or 0

Calculated
Contains calculated values. 

Choice
Specifies a predetermined set of values that can be used to enter data into the field. 

Computed
Specifies an abstract field type that depends on other fields for its content and definition. 

ContentTypeId
Contains a content type ID.  

Counter
Contains an integer used for internal ID fields. 

CrossProjectLink
Specifies a link between projects in a Meetings Workspace site. 

Currency
Contains currency values formatted based on a specific locale. 

DateTime
Contains date and time values. 

Error
Contains errors. 

File
Contains files. 

GridChoice
Specifies a Choice field for a data sheet. 

Guid
Contains GUIDs. 

Integer
Contains positive or negative integer values. 

Lookup
Contains references to values in other lists. 

MaxItems
Contains the maximum number of items. 

ModStat
Specifies Content Approval status. 

MultiChoice
Contains multiple values per list item. 

Note
Specifies a field that can contain multiple lines of text. 

Number
Contains floating point numbers. 

PageSeparator
Inserts a page break in a survey list. 

Recurrence
Specifies a field used in calendars for recurring events and, like computed fields, an abstract field type that depends on other fields for its content and definition. 

Text
Contains a single line of text. 

ThreadIndex
Contains the ID that indicates the relative position of a message within a conversation thread. 

Threading
Specifies a field that is used in the creation and display of threaded Web discussions. 

URL
Contains hyperlinks. 

User
Specifies users of a SharePoint site. Same as "Person or Group" in STS.

WorkflowEventType
Specifies a workflow event type. 

WorkflowStatus
Specifies workflow status. 

Example:
<Field ID="{04436D2F-67D9-48bd-9B56-B3D27EA6D3EF}"
            Name="Verifiers"
            DisplayName="Verifiers"
            Type="User"
            ...

            />

 


UPDATE: Found a more complete definition of the Field Element (then the one in CAML documentation), in MSDN List Schema documentation.

InfoPath Forms for Workflows, How to Register Forms in SharePoint 2007

by Daniel Halan 17. July 2007 19:28

Microsoft has published a very good Walkthrough on how to create a Workflow for SharePoint 2007 and using InfoPath Forms for custom user interaction.

But they where a bit vague on explaining the configuration surrounding the InfoPath Forms, as they left out how to register the Form in SharePoint. Here are some clarifications.

- The InfoPath Form Template ID that are used in workflow.xml/Elements/MetaData/*_FormURN elements are found in InfoPath, 
File > Properties. The "Properties" menu item exists only when opening InfoPath in Design-mode, todo that right click on the xsn file and select "Design" in the context menu.

- Before installing your feature it's always good to verify that the published form will work correctly in your SharePoint instance using the StsAdm tool:
"stsadm -o verifyformtemplate -filename MyFeature\MyForm.xsn"
If you have created your Workflow project from the Visual Studio 2005 "SharePoint Server Seq. Workflow" project there is an installation .bat file created called PostBuildActions.bat which contains this line, but it's commented. You just need to uncomment it and change the path to your form.

- When installing the feature you should put the Template Form(s) inside your feature folder. (...\web server extensions\12\TEMPLATE\FEATURES\MyFeature\)

- You need to register your InfoPath Forms in SharePoint, which is done thru the feature.xml, by putting a Property element with the "RegisterForms" directive, and the relative path to the form(s) from your feature folder. This example registers all forms in the feature root folder.

<Feature Id="54178F4E-80E6-4c26-835C-2533060FFD74" .... >
 
<Properties>
   
<Property Key="RegisterForms" Value="*.xsn" />
  </
Properties>
</
Feature>

References:
Walkthrough: Creating Office SharePoint Server 2007 Workflows in Visual Studio 2005
MSDN Articles: InfoPath Forms for Workflows

Blog3ngine dot NET 3.0.0.0
Theme by Daniel Halan

About the author

Daniel Halan Daniel Halan, M.Sc., Microsoft Windows Azure Advisor Software Architect and Lead Developer from Sweden, currently in Bangkok.

Working primary with Microsoft .NET, Windows Azure, DDD, CQRS and some Dynamics CRM  Read more...

The content of this site are my own personal opinions and do not represent my employer's view in anyway.

Month List