Sunday, September 13, 2009

SharePoint Custom Workflow Error (related to Serialization): WinWF Internal Error, terminating workflow

I created a custom workflow using VS 2008 for MOSS 2007.
In my SP site, I created a custom list CONTACTS with following columns:
Region - Single Line Text
Dept1 - Person Group
Dept2 - Person Group
Dept3 - Person Group

In this workflow, I need to retrieve users from CONTACTS list and create tasks for the users included within the groups associated to Dept columns.
I created custom workflow and ran it by associating to another list.
I got following error:
"WinWF Internal Error, terminating workflow Id# d4a5785f-22bf-42e8-bfca-d561bdb44ed7 System.Workflow.Runtime.Hosting.PersistenceException: Type 'Microsoft.SharePoint.SPUserCollection' in Assembly 'Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' is not marked as serializable. ---> System.Runtime.Serialization.SerializationException: Type 'Microsoft.SharePoint.SPUserCollection' in Assembly 'Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' is not marked as serializable. at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() at System.Runtime.Seri... ...alization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) at System.Workflow.ComponentModel.Activity.Save(Stream stream, IFormatter formatter) at System.Workflow.Runtime.Hosting.WorkflowPers... Workflow Infrastructure 98d4 Unexpected ...istenceService.GetDefaultSerializedForm(Activity activity) at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.SaveWorkflowInstanceState(Activity instanceState, Boolean unlock) at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation) --- End of inner exception stack trace --- at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation) at System.Workflow.Runtime.WorkflowExecutor.ProtectedPersist(Boolean unlock)"

What I understood from above exception in the SharePoint Logs:
The exception raised by WF is because of SPUserCollection object is not marked as serializable.
I made following changes to my code:
a. Marked my custom workflow class as serializable as all the objects within WF must be serializable. I did this by placing the attribute on top of the class as below:
[Serializable()]
public partial class SampleWorkflow : SequentialWorkflowActivity
{
}
b. Removed declaration of SPUserCollection objects as these obj are not serializable. To store user information for each department, i created separate hashtable and stored the data while retrieving the user information, instead of storing SPUser or SPUserCollection objects.

Reference Blog Posts, which helped me in solving this problem:
http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/01cde268-5148-4ff7-847e-1d03803c91c2
http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/9bd91cba-558c-456a-8f3c-e0e829145ec6/
http://blogs.msdn.com/sharepoint/archive/2006/11/28/developing-workflows-in-vs-part-5-code-your-workflow.aspx

Friday, September 4, 2009

Building ASP.NET DatePicker

Following link has simple way of creating a datepicker in ASPX pages.
http://www.codedigest.com/Articles/ASPNET/247_DatePicker_Control_in_ASPNet.aspx

Debugging tips for SharePoint

Today, I came across with very good post regarding debugging tips for SharePoint.
http://blog.thekid.me.uk/archive/2007/07/25/debugging-tips-for-sharepoint-and-wss-exceptions.aspx
Most of the tips you may know already but this list has collection of tips.
Enjoy debugging.

Tuesday, August 18, 2009

Looking for answers - SharePoint Questions

Today, I came across with following questions:
a. Alert mail is not sending for new items created in a survey list when branching logic is enabled. But, receiving alert mails for edit & delete items mails when branching logic is enabled. Not sure why? How to resolve this.

b. There is a document library with folders and sub folders. How to create a view targetting to a sub-folder? Ofcourse, we can restrict the users on folder view but want to create a view to display files within a folder.

Please leave a comment if anyone knows answer for above questions.

Wednesday, August 12, 2009

Form based authentication in SharePoint - MUST READ

While I was browsing through MSDN site, I found MUST READ articles for FBA with SharePoint:

SharePoint Integrating with the 2007 Microsoft Office System

Office SharePoint Server 2007 and Windows SharePoint Services 3.0 users who also have the 2007 Microsoft Office system of applications installed enjoy a high level of integration between the 2007 Office system and SharePoint Products and Technologies. Many of those integration features, however, depend on Windows authentication. Without Windows authentication, some integration points do not work, and others are changed considerably. To help minimize user confusion, SharePoint Products and Technologies offer a mode in which certain menu items that require Windows authentication are removed. In the Central Administration Web site, on the Authentication Provider page, this mode is controlled via the Enable Client Integration box.

When you configure a zone to use forms authentication, the Enable Client Integration box is cleared by default. If a zone is configured in this way, the following changes occur in functionality:


  • Support for remote interfaces is turned off. That includes WebDAV, SOAP, and Microsoft Office FrontPage remote procedure calls (RPC). Some functionality is not available, such as Web folders or the Web services for accessing content in that site.
  • Some toolbar items no longer appear:
    • New Document
    • Open in Outlook
    • Open In Windows Explorer
    • Export to Spreadsheet
    • Open with Database Program
    • Explorer View option is hidden.
    • Create an Access View option is hidden.
  • In picture libraries, the following functionality is removed:
    • Upload Multiple
    • Edit Picture
    • Download
    • Send To
  • On the Edit Control Block (ECB) menu, the drop-down menu that appears when you click items in document libraries, the following items are removed:
    • Edit in Word
    • Edit in Excel
    • Edit in PowerPoint
    • Discuss
    • Connect To Outlook
  • In slide libraries the following functionality is removed:
    • Publish Slide
    • Send to PowerPoint

Also, syncing SharePoint data with Microsoft Office Outlook no longer works.

When operating in this mode, users can still work with documents in SharePoint libraries, but they must right-click items and choose to save a copy to disk. They can then edit and update the document, and then upload it and check it back in when they are finished editing.

Some organizations might want to use forms authentication, but also require the same level of integration they get when using Windows authentication. There are a couple of possible workarounds in this scenario, but it is helpful to examine why this limitation exists.

When a user accesses a page on a site protected by forms authentication, the server looks for a valid authentication cookie. If no cookie is found, or if the cookie is not valid, the server redirects the browser to the logon page by using an HTTP 302 status code. At this page, the user is allowed to authenticate by using his or her credentials. After the credentials are validated, the server creates a valid authentication cookie and sends it back to the browser, with the originally requested page. The browser keeps the cookie in memory and sends it back to the server with every subsequent request to that Web server. With each request, the server checks the validity of the cookie to ensure that it is good (that it has not expired or been tampered with), and then processes the request.

Because the authentication cookie is in memory with the browser process, it introduces some limitations:

  • The cookie is retained only as long as the browser is open; when the browser is closed the cookie is destroyed with everything else in memory that the browser was using.
  • The cookie belongs to the browser's application process (such as the .exe file for the browser), and cannot be shared with other processes. Office system applications run in their own processes, for example, msword.exe for Microsoft Office Word. As such, a cookie that a user generated when logging into the site in the browser cannot be shared with Word.

The issues described in this article clarify why the Enable Client Integration option was developed: to help make the end-user experience more uniform and predictable in that environment; however, the user experience is somewhat different for users that are accustomed to SharePoint sites secured with Windows authentication. Even with those restrictions, there are still a few options that can be used to allow for using forms authentication and yet still provide many or all of the deep integration points with Office applications that are available when using Windows authentication.

Reference of above content: http://msdn.microsoft.com/en-us/library/bb977430.aspx#MOSSFBAPart3_IntegratingWithOffice2007

How To: Choose between InfoPath Browser Forms and Custom ASPX Forms

Choosing between InfoPath forms and ASPX pages, depends totally on the nature of the problems we are solving on one side and level of skill set we are investing in solving that problem on the other side. Usually, in most cases, any manager or developer would want to use InfoPath Forms part of Office 2007 because it’s quick and easy. But, as the requirements get more complex and requires more and more customization, one might feel its better to go with ASPX pages and Visual Studio 2005 and SharePoint designer. Technically, InfoPath Forms by itself is incomplete; It needs a container which is again an ASPX web form using the XmlViewer web part. If we go with custom ASPX form, then it has to be designed either using SharePoint designer or Visual Studio leveraging web parts to show the required forms. So for this, developing web parts and its complexity needs to be taken into consideration.
So, to decide on one, we may have to take the decision step by step.

If the requirement is for a single form and showing data from an external data store or from within SharePoint, then going with InfoPath Forms is recommended.

If it’s a single form and needs complex actions, to and fro between the form and the data store, then choosing custom aspx pages is recommended.

If the requirement needs wizard kind of feature i.e. which requires user to go through multiple screens, then custom aspx is the solution.

If the data submitted through the form has to be saved to multiple locations (database, SharePoint, file storage) then InfoPath Forms is a good solution.

If the requirement is for designing numerous forms which are simple enough and well documented, then InfoPath Forms should be considered. InfoPath can help deliver the solution in a short time period.

InfoPath browser based forms has few limitations on the repository of controls one can use. For example: combo box, master/detail view control and many advanced controls are not supported in browser based InfoPath Forms. Depending on these limitations we have to decide on InfoPath or ASPX. ASPX has no such limitations.

InfoPath forms is based on XML. The form is rendered using XSLT stylesheets and the data submitted through the form is available in XML format. The data is well structured to retrieve later on and dump the data/forms in some external system. This in combination with BizTalk server is a perfect architecture for document transition through multiple levels.

InfoPath forms certainly have an edge over ASPX forms as a quick and neat solution. It has some complex out of the box controls, like date picker, file attachment control, repeating sections. InfoPath forms can also have code-behind if needed to manipulate the data on the form or behind the form.

ASPX can have and do everything InfoPath Forms does, with an exception of additional development effort. Apart from it, the deployment process of aspx forms is much better and easier than InfoPath Forms.

Below are some of the excerpts from few blogs I follow which provides some valuable input comparing InfoPath and ASPX forms. Below are the Pros and Cons in using InfoPath Forms:

Pros:
  • Ideal for simple forms
  • Easy to build a form – no coding involved
  • InfoPath form itself is an xml document.
  • Support versioning
  • Works very nicely with SharePoint custom workflows as a workflow association tool.
  • Fully integrated in Microsoft Office 2007 suites like Outlook e-mail messages that can be deployed as Outlook e-mail messages, so colleagues can complete forms without leaving the familiar Outlook environment.
  • Firewall friendly. InfoPath Forms Services make it easy to extend forms solutions beyond firewall because of using many different Web browsers and mobile devices.
  • InfoPath can easily convert Word documents and Excel spreadsheets to forms and build templates to work with.
  • InfoPath provides data integrity and version control for document management purposes, and add structure to information gathering by converting legacy documents to rich InfoPath form templates.
  • Design of a form is much easier in InfoPath forms with a simple drag-and-drop interface and provides support for prebuilt template parts and shared data connections.
  • Creates PDF or XPS and other important document formats and is extensible by addition of a free plug-in to install third party tools and components for document, archival and records management
  • Fully integrated with MOSS 2007 and capable of using integrated workflow management tools in Office 2007
  • Fully Web browsed technology, includes a design checker to help ensure consistency for forms.
  • Support for information rights management to help manage permission control and building a powerful document management team site.
  • Fully centralized for entire organization and enables organizations to centrally

Cons:

  • A web browser-enabled InfoPath form does not support all features of InfoPath client.
  • Inflexible — Difficult or impossible to customize (well, you can argue that you can hack the xsl file of InfoPath)
  • No support for image buttons
  • No support for html
  • No support for tree control
  • Difficult to support Forms Based Authentication
  • By default, InfoPath cannot support SharePoint web services data connections in FBA.
  • Forms Services does not support username() function in FBA. This means that InfoPath form does not recognize the current user.
  • Difficult to perform automated web test against Forms Services.
  • Difficult to support automated deployment. Basically, you have to unzip the xsn file and programmatically modify the manifest.xsf file, and zip back to the xsn file for automated publishing.
  • The way that Forms Services supports deployment of InfoPath forms is quirky – It creates SharePoint solution packages with GUID and creates features with meaningless names on the SharePoint Features folder.

Note: The above content is taken from following link: http://sharenotes.wordpress.com/2008/06/02/how-to-choose-between-infopath-forms-and-custom-aspx-forms/

Below are the blog links which talk more about this topic:
http://www.jyhuh.com/blog/archive/2008/03/02/AspNet_vs_InfoPath_Forms_Services.aspx
http://office12.blogspot.com/2007/06/infopath-web-forms-vs-aspx.html