Posts tonen met het label Sharepoint 2007. Alle posts tonen
Posts tonen met het label Sharepoint 2007. Alle posts tonen

zondag, augustus 19, 2007

Query DataConnection in Infopath Web-enabled Form when selecting value of dropdownlost (with Managed Code)

You don't always need to load your dataconnection before the form is loaded (performance reasons), sometimes you want to load a different dataconnection when a certain value is selected. I use the example of a dropdownlist, and every value of the dropdownlist will load an other dataconnection into another dropdownlist.



Add the 2 dropdownlists, the second dropdownlist must have a connection with a datasource (I use an embedded Xml file dc.xml). When creating this dataconnection, please deselect the setting "Automatically retrieve dat when form is opened".




What you will need after you created the controls in infopath, open VSTA (alt+shift+F12). Add following code fragment into the InternalStartup method:

this.EventManager.XmlEvents["/my:myFields/my:Type"].Changed += new XmlChangedEventHandler(TypeChanged);

You also need to add the TypeChanged methods:

void TypeChanged(object sender,XmlEventArgs e)
{
string type = e.NewValue; //the selected value of the type dropdownlist

//I just added one dataconnection called dc (value when you select POST)
//You need to put here code (switch) for all the values in the type ddl
DataSource ds = this.DataSources[type];
DataConnection dc = ds.QueryConnection;

dc.Execute();
}


When you use the Execute method of a dataconnection, you must change following setting (it is like the ASP.NET AutoPostBack setting), otherwise your dataconnection will not be loaded!! (when you just changed a value of another field, you don't need to change this setting).




Change the standard option (postback settings): "Only when necessary for correct rendering of the form (recommended)" to "Always"


Remarks:
When you use Mananged Code in web-enabled form, uou must publish it as an administrator approved template (check out blogpost http://spsfactory.blogspot.com/2007/01/walkthrough-publishing-administrator.html )

maandag, juni 25, 2007

Microsoft .NET Magazine #17: Legends never die on the front ?!

Today I spotted myself on the cover of the new Microsoft .NET Magazine....



I will post some more info when I have got the time for it....
Notice that JOPX has a nice cool earring.... ;)

Microsoft .NET Magazine:
http://www.microsoft.com/netherlands/msdn/netmagazine/default.aspx

vrijdag, maart 02, 2007

Working with the Replicator in Sharepoint Workflows, some serialize issues & tricks

Before reading this post:

Keep in mind: A replicator is just a "workflow foreach".


When initializing a replicator you need to pass initiation data (like the foreach collection data). So if you want to pass a Contact for each replicated activity, you will set the initiationChildData (must implement IList) with Contact objects:
adding contacts like this: replicatorInitialChildData.Add(contact);

Sometimes you want the add your own classes to the List. You would except that this wouldn't be difficult, in fact it isn't:

Create the initiation data list with objects of your custom class:
IList replicatorInitialChildData = new List();
/ fill the list with the ApproverFlow objects
replicatorInitialChildData.Add(appFlowObj1);
replicatorInitialChildData.Add(appFlowObj2);


The code will compile, the workflow will succeed sometimes (when the replicator is used in Parallel execution), sometimes not (when the replicator is used in Sequence execution), after a while you will notice this kind of errors:

(in the log folder in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS)

Workflow Infrastructure 72eo Unexpected DehydrateInstance: System.Runtime.Serialization.SerializationException: End of
Stream encountered before parsing was completed. at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck,
Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean
fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream) at
System.Workflow.ComponentModel.Activity.Load(Stream stream,...

02/27/2007 14:50:31.00* w3wp.exe (0x0A98) 0x1700 Windows SharePoint Services Workflow Infrastructure
72eo Unexpected ... Activity outerActivity, IFormatter formatter) at
System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity) at
System.Workflow.Runtime.Hosting.WorkflowPersistenceService.RestoreFromDefaultSerializedForm(Byte[] activityBytes, Activity outerActivity)
at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.LoadWorkflowInstanceState(Guid instanceId) at
System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor,
WorkflowInstance workflowInstance) at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context,
WorkflowInstance workflowInstance) at System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId) at
Microsoft.SharePoint.Workflow.SPWinO...

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
System.InvalidOperationException: The platform does not know how to deserialize an object of type OfficialMail.Common.ApproverFlow+Approver.
The platform can deserialize primitive types such as strings, integers, and GUIDs; other
SPPersistedObjects or SPAutoserializingObjects; or collections of any of the above.
Consider redesigning your objects to store values in
one of these supported formats, or contact your software vendor for support.



You will notice the deserialize stuff.... If you think further, ..... whole the workflow idea is that every instance can be serialized or deserialized, because a workflow can wait for some other stuff, so objects will be saved somewhere (not in memory) when workflow is waiting.

When the replicator starts in parallel execution, no (de)serialize will occur because the workflow doens't need to serialize the objects, the replicator executes everything at once.
But when the replicator executes in sequence, it does need (de)serializing because the workflow will pause before executing the next step (so state is saved:(de)serializing occurs).


So when you want to add your own classes, keep in mind that your own class must be serializable.

Which types are serializable?
The platform can deserialize primitive types such as strings, integers, and GUIDs; other SPPersistedObjects or SPAutoserializingObjects; or collections of any of the above.

In one of the next blog posts, I will explain how to add/change data when the replicator is already running ...

maandag, januari 15, 2007

Handle the InfoPath Forms Services by yourself (in a Custom WebPart to view a web-enabled Infopath 2007 Form)

To understand this post well, please go through this post first:
- Hosting the InfoPath 2007 Form Editing Environment in a Custom Web Form

Sometimes you don't want to popup an error by InfoPath Forms Services (it will log this also in the EventLog), see image below. You want to catch the error in code and do some custom logging (or other stuff)


I will use the example when a dataconnection (webservices) in the form gives a time-out.

Preceding:
First keep in mind that we will bind the dataconnection-webservice to its control in code, so you have to deselect - Automatically retrieve data when form is opened (when adding a data-connection in InfoPath). Also don't forget to link the control with the dataconnection in infopath designer

What we gonna do in code:
- Add a handler that will get you into the Initialize methods of the XmlFormView
- Get the right dataconnection, execute it (so it will get the data and bind to the control)
- Add a "try/catch" block around this code

The code:


void viewform_Initialize(object sender, InitializeEventArgs e)
{
try
{
DataConnection dc = _viewform.XmlForm.DataSources["GetGAL"].QueryConnection;
dc.Execute();
}
catch (System.Net.WebException webEx)
{
WarmUpWebService();
ReloadWebPart();
//Log, ...
}
catch (Exception ex)
{
Logger.Log(ex, ...);
}
}


Some other InfoPath blogs: