Friday, December 16, 2011

Custom Form deployment in sharepoint 2007

I have faced a problem today... FOr a customer I 'm actually working on sharepoint 2007 (sigh)...

I have to customize fully a huge form (that contains 200 fields) by adding tabs. It's not the topic but I'm doing it doing jquery (and that rocks).

In order to do it,you just have to open your editform.aspx newform.aspx and dispform.aspx, and to replace it with new forms using a feature that copy the new form in the list form folder. The topic of this blog is the content of those aspx file.

To create it, I have simply copied the content of my old EditForm . I have erased everything contained in the PlaceHolderMain .

And I have (in sharepoint Designer) inserted the form content using :
insert > Sharepoint Control > Customize a list form and I have selected my list...

I have added my tabs, everything works fine on sharepoitn designer but...mmm I want to deploy it on 100 sites containing the same list...
Should I do it manually? obviously no... But if you try to do it directly you will face a bug saying
"Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator. "

If you look inside your form you will find :
<ParameterBinding Name="ListID" Location="None" DefaultValue="{ID OF YOUR LIST}"/>That you have to replace by
<ParameterBinding Name="ListName" Location="None" DefaultValue="NAME OF YOUR LIST"/>

<WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{IDOFYOURLIST}" Name="ListID"></WebPartPages:DataFormParameter>

that you have to replace (4times) by

<WebPartPages:DataFormParameter ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="{Name of your list}" Name="ListID"></WebPartPages:DataFormParameter>

And because now you can deploy it manually (because there is no more reference to the list ID (that is different in every site)

Thursday, November 17, 2011

I'm a .net Ranger by Sogeti!

I'm glad to tell you that I have joined the .net Rangers community at Sogeti.

The .net Rangers community is a small amount of Sogeti's Microsoft oriented experts .

Follow us :

ListViewWebpart and XsltListViewWebPart

I have a colleague (Nicolas Corchia - Sogeti) who came into my office with a migration 2007>2010 problem.

The 2007 Codes analysed a webpartpage in order to find the ListViewWebpart included in it in order to modify them...
Well... after the more listViewWebpart were found... He came out with the fact that sharepoint automatically changed the listviewPart by the new XsltListViewWebPart class.

Because nicolas is a good developer ;-) he found out that the problem was wimply a casting problem obliging him to recast the webparts in the code itself!

Find more in :

Thanks to a problem raised by Nicolas Corchia (Sogeti),

Thursday, January 27, 2011

Workflow Action : Attach Document to ListItem

I have been really disapointed when realizing that I couldn't Attach a document to an item when I designed a workflow. So, to me this action was definitly missing. I needed it in a document library list with incoming email feature activated in order to be able to send emails to this library and those emails to be managed to be linked automatically to other items in other lists... For this custom activity, I have been assisted a member of my team: Yassine Hachime.

I won't explain here The principle on How to create Custom Activity on Sharepoint 2010, this topic has already been explained several times on the web : or

My plan is just to give you one more action to add to your SPD.
I will just provide you the code for the action file and the bin. I'll leave you the rest of the job.

Here is the action file :

<?xml version="1.0" encoding="utf-8"?>

<Actions Sequential="then" Parallel="and">
<Action Name="Attach Doc to Item"
Assembly="AttachMailWFActivity, Version=, Culture=neutral, PublicKeyToken=46f60639ee1bfb57"
AppliesTo="all" Category="List Actions">
<RuleDesigner Sentence="Attach %1 to %2">
<FieldBind Text="this document" Field="LibId,DocItem" DesignerType="ChooseDoclibItem" Id="1" />
<FieldBind Text="this item" Field="ListId,ListItem" DesignerType="ChooseListItem" Id="2"/>
<Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In" />
<Parameter Name="LibId" Type="System.String, mscorlib" Direction="In" InitialBinding="__list"/>
<Parameter Name="DocItem" Type="System.Int32, mscorlib" Direction="In" InitialBinding="__item" DesignerType="ListItem" Description="ID of the list item used by this action." />
<Parameter Name="ListId" Type="System.String, mscorlib" Direction="In"/>
<Parameter Name="ListItem" Type="System.Int32, mscorlib" Direction="In" DesignerType="ListItem" Description="ID of the list item used by this action." />




And the code of the
AttachMailWFActivity.AttachDocToItem assembly is :

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Linq;
using System.IO;
using Microsoft.SharePoint;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using Microsoft.SharePoint.WorkflowActions;
using System.Workflow.Activities.Rules;

namespace TSP.AttachMailWFActivity
public partial class AttachDocToItem : Activity


public static DependencyProperty LibIdProperty = DependencyProperty.Register("LibId", typeof(string), typeof(AttachDocToItem));
public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string), typeof(AttachDocToItem));
public static DependencyProperty DocItemProperty = DependencyProperty.Register("DocItem", typeof(Int32), typeof(AttachDocToItem));
public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(Int32), typeof(AttachDocToItem));
public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(AttachDocToItem));

[Description("ID of the document library storing the doc that will be attached to the item")]
public string LibId
get { return ((string)(base.GetValue(AttachDocToItem.LibIdProperty))); }
set { base.SetValue(AttachDocToItem.LibIdProperty, value); }

[Description("ID of the list keeping the item to which the document will be attached to")]
public string ListId
get { return ((string)(base.GetValue(AttachDocToItem.ListIdProperty))); }
set { base.SetValue(AttachDocToItem.ListIdProperty, value); }

[Description("ID of the list item to which the document will be attached to")]
public Int32 ListItem
get { return ((Int32)(base.GetValue(AttachDocToItem.ListItemProperty))); }
set { base.SetValue(AttachDocToItem.ListItemProperty, value); }

[Description("ID of the document item to which the document will be attached to")]
public Int32 DocItem
get { return ((Int32)(base.GetValue(AttachDocToItem.DocItemProperty))); }
set { base.SetValue(AttachDocToItem.DocItemProperty, value); }

public WorkflowContext __Context
get { return ((WorkflowContext)(base.GetValue(__ContextProperty))); }
set { base.SetValue(__ContextProperty, value); }

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

__Context.Web.AllowUnsafeUpdates = true;

Guid id = new Guid(ListId);
SPList list = __Context.Web.Lists[id];
Guid did = new Guid(LibId);
SPList docLib = __Context.Web.Lists[did];
SPListItem sourceItem = docLib.GetItemById(DocItem);
SPFile sourceDoc = sourceItem.File;
byte[] fichierbyte = sourceDoc.OpenBinary();

SPListItem destinationItem = list.GetItemById(ListItem);
destinationItem.Attachments.Add(sourceItem.Name, fichierbyte);
return ActivityExecutionStatus.Closed;

catch (Exception Ex)

return ActivityExecutionStatus.Faulting;
throw new Exception(Ex.Message + "&&&&" + Ex.StackTrace);


return ActivityExecutionStatus.Closed;

public AttachDocToItem()

Now you've got that.
Just :
- Create a sharepoint 2010 empty project
- Create a class and copy the code
- Create an action file and copy the code
- Sign your assembly
- Package your wsp
- Install the wsp on you WFE. Deploy it.
- Add the correct line in the AuthorizedType tag of your web.config.

The result :

(for the capture... it's because my SPD Is in french)

I hope it helps.
Don't hesitate to contact me whether you are in trouble using it !!!

Item Created Workflow won't start with incoming email document uploaded


It's been a while since my last post.
I was not in the mood ;) (or overloaded with work)... I have a few post to write... I hope it will be done in the few next days. I'm planning to explain the last SPD WF Action I have written (Attach Document to Item)....

But right now my post just describes a problem with the library with incoming email feature activated. When you send an email to the library, the automatic workflow launched at item created are simply not raised. It works for the items you add normally though.

Yeess. I found this post

So, you just have to run this command line :

Stsadm -o setproperty -pn declarativeworkflowautostartonemailenabled -pv true

It worked for me !!!