Wednesday, August 5, 2009

How do you authenticate a user request on a web site?

There are APIs provided in .NET Framework to check the authentication programatically:
System.Web namespace has following class which will help us in authenticating the request,
HttpContext.Current.Request.IsAuthenticated

If a web site is configured for anonymous authentication, then all the users are authenticated by default. For intranet/extranet sites, authentication plays a vital role. Where, we can use above property to check.

SharePoint site collection / site also has methods to authenticate user whether the user has enough access permissions on the site collection or a particular site. For more information, check WSS 3.0 or MOSS 2007 SDK.

Tuesday, August 4, 2009

10 Essential Resources for SharePoint Developers

1. Microsoft Office SharePoint Server (MOSS) SDK and ECM Starter Kit http://www.microsoft.com/downloads/details.aspx?familyid=6D94E307-67D9-41AC-B2D6-0074D6286FA9&displaylang=en

2. Windows SharePoint Services (WSS) SDK and Workflow Starter Kit http://www.microsoft.com/downloads/details.aspx?FamilyID=05e0dd12-8394-402b-8936-a07fe8afaffd&DisplayLang=en

Note: The MOSS SDK includes the WSS SDK documentation and a more robust starter kit

3. Visual Studio Extensions for SharePoint Services (November CTP)http://www.microsoft.com/downloads/details.aspx?familyid=19F21E5E-B715-4F0C-B959-8C6DCBDC1057&displaylang=en

4. Customizing and Branding Web Content Management-Enabled SharePoint Sites

5. MOSS for Content Management Server Developers (Beta)Three papers + an analysis tool:

6. Office Developer Screencasts (applies to all of Office) http://msdn2.microsoft.com/en-us/sharepoint/aa905382.aspx

7. SharePoint Developer Map (also includes InfoPath and 2007 Office System posters)http://www.microsoft.com/downloads/details.aspx?familyid=771aeb45-9d27-4d1f-acd1-9b950637d64e&displaylang=en

8. MOSS and WSS Online Clinics. Online clinics covering SharePoint technology are free for a limited time!!! Check 'em out:

9. MOSS portal on the Office Developer Centerhttp://msdn.microsoft.com/moss
Includes the Upgrade and Migration Center for SharePoint Developers http://msdn2.microsoft.com/en-us/office/aa905505.aspx

10. SharePoint Developer Centerhttp://msdn.microsoft.com/sharepoint

11. 7 Development Projects for SharePoint – online book http://download.microsoft.com/download/0/2/f/02f0f661-88e1-43c2-b523-88d2e9e6802f/7%20development%20projects%20with%20the%202007%20microsoft%20office%20system%20and%20windows%20sharepoint%20services%202007.pdf

12. MSDN Community ContentMSDN Community Content is a way of providing Wiki-style annotations to core Microsoft documentation. For example, you can add code samples, remarks or “gotchas,” translations, or other comments that enhance or supplement the core MSDN documentation.

13. F1 Help from Visual Studio Document ExplorerFollow the steps in this blog post to receive F1 Help directly from your code in Microsoft Visual Studio 2005.

http://blogs.msdn.com/randalli/archive/2006/07/28/sharepoint-development-tip-getting-context-sensitive-f1-help-directly-from-the-msdn-library.aspx

14. Project SDK DownloadI see a lot of questions about SharePoint integration with Project Server, and the Project SDK is also produced by my team. http://www.microsoft.com/downloads/details.aspx?FamilyID=2672f6f9-7028-4b30-99a2-18cb1eed1abe&DisplayLang=en

More from our SharePoint MVPs and Partners
SharePoint MVPs are also producing great lists of resources for SharePoint; here are two examples if you haven’t already seen them.

Note: I got this list from http://blogs.msdn.com/randalli/archive/2007/01/08/10-essential-resources-for-sharepoint-developers.aspx

How do you tell current sharepoint page is in edit/display/other modes?

Microsoft.SharePoint.WebControls.SPControlMode enumeration contains following values:
  • Display
  • Edit
  • Invalid
  • New

With following condition, you can check in which mode you are in:


if (SPContext.Current.FormContext.FormMode == Microsoft.SharePoint.WebControls.SPControlMode.Display)


{
// you are in display mode
}

Monday, August 3, 2009

Issue with workflows: Missing Completed Workflows History

Following blogs talked about the issue:
"I cannot find any workflow histories on approved documents that were approved 2 months or more ago. The document status says its approved but there are no histories showing under "Completed Workflows." Is there some kind of retention policy in MOSS 2007? This is causing a major auditing issue for us. Where can I retrieve this history information from? "

Blogs URLs:
http://social.msdn.microsoft.com/forums/en-US/sharepointworkflow/thread/b15b27e2-3033-418b-9731-968273d7423e/

http://www.sharepointblogs.com/llowevad/archive/2007/09/21/huge-workflow-issue-what-is-microsoft-thinking.aspx

Workflows: Major Microsoft.Windows.SharePoint.Workflow Objects

The Microsoft.SharePoint.Workflow namespace represents the workflow functionality contained in Windows SharePoint Services.

  • SPWorkflowTemplateCollection object: Represents the workflow templates currently deployed on a site.
  • SPWorkflowTemplate object: Represents a workflow template and contains properties you can use to get or set information about the template, such as the instantiation data and the history and task lists for the template.
  • To associate a workflow to a list or document library, use the AddWorkflowAssociation method of the SPList object.
  • To associate a workflow with a content type, use the AddWorkflowAssociation method of the SPContentType object.
  • To create the appropriate workflow association, use the CreateListAssociation, CreateListContentTypeAssociation, or CreateSiteContentTypeAssociation method of the SPWorkflowAssociation object itself.
  • Use the RemoveWorkflowAssociation method to remove a workflow association from a list.
  • Use the RemoveWorkflowAssociation method to remove a workflow association from a site or list content type.
  • Each SPWorkflowAssociation object represents a workflow template that is associated with a specific list or content type, and that contains properties that return custom information about that workflow's association with the specific list or content type. This information includes whether the workflow is enabled, whether the workflow can be started automatically, and the list or content type with which the workflow has been associated.
  • The SPWorkflowCollection represents the workflow instances that have run or are currently running on a given list item.
  • Each SPWorkflow object contains properties that return information about the workflow instance, such as whether the workflow has completed, its internal state, and its workflow history list.
  • Use the Workflows property to return an SPWorkflowCollection object that represents the workflows currently running for that list item.

Managing Running Workflow Instances Programmatically
Users interact with the workflows running on items individually, through the Windows SharePoint Services user interface. But Windows SharePoint Services provides functionality for you to centrally control the running instances of workflows across your site collection through the object model. Use the SPWorkflowManager object to manage the running instances of workflows across a site collection. The SPWorkflowManager object has no equivalent in the user interface. Use the SPWorkflowManager object to:

  • Start, run, or cancel workflows.
  • Return all the workflows currently running on a specific item.
  • Perform other workflow administration operations.

Workflows: Workflow Association and Initiation Forms [WSS 3.0]

Association and initiation forms are displayed for users to complete before any workflow actually starts. You can use these forms to enable users to set parameters and other information for the workflow in advance. Association forms address how the workflow applies to a specific list, library, or content type; initiation forms address how the workflow applies to a specific SharePoint item.

Association forms are displayed to administrators when they first decide to add—or associate—a workflow with a particular list, document library, or content type. You can use association forms to let an administrator specify parameters, default values, and other information for the workflow as it applies to items on the list, library, or content type with which the administrator is associating it.

Initiation forms are displayed to users when they start a workflow on a specific SharePoint item. You can use initiation forms to let users override or append the association parameters set by administrators, or specify additional parameters or information about the workflow as it applies to the specific SharePoint item. Not all workflows need initiation forms.

The initiation form can be the same form as the association form. For example, using the same form for each workflow form enables you to let administrators set certain default parameters during workflow association, and then let the user who actually starts the workflow instance on a particular item review and overwrite those default parameters.

Specifying Association Forms
You specify a workflow's association form in the workflow template definition XML. To do this, set the value of the AssociationURL attribute of the Workflow element to the custom form page you want to use for workflow association. For example:
AssociationURL="MyWkflAssociationPage.aspx"

Note: Windows SharePoint Services 3.0 supports absolute or server-relative paths in the workflow template definition. You must express all form path URLs in one of these formats. For example, you can use an absolute path, such as "http://site/library/page.aspx", or a server-relative path, such as "/layouts/page.aspx". Windows SharePoint Services does not support link fix-up in workflow template definitions.

Association Form Processing
When an administrator selects a workflow to associate with a given list, library, or content type, Windows SharePoint Services displays the Add a New Workflow page. The administrator can use this page to specify settings common to all workflows, such as the workflow definition and initiation conditions, and whether the workflow runs on items, folders, or both.

When the administrator clicks the Next button on this page, Windows SharePoint Services examines the AssociationURL attribute of the Workflow element, in the workflow template definition, to determine the proper form to load.

To provide custom data to the association form, you can store this information in the AssocationData element. For example, you could use this element to store default values you want to pass to the association form when it is displayed. The AssocationData element can contain any valid XML. Your form can then load that association data from the workflow template.

Because the workflow association is not created until the custom association form is submitted, Windows SharePoint Services also passes the following query parameters to the custom association form:


<input type="hidden" name="WorkflowDefinition" value=<% _STSWriteHTML(Request.Form["WorkflowDefinition"]); %>>
<input type="hidden" name="WorkflowName" value=<% _STSWriteHTML(Request.Form["WorkflowName"]); %>>
<input type="hidden" name="AddToStatusMenu" value=<% _STSWriteHTML(Request.Form["AddToStatusMenu"]); %>>
<input type="hidden" name="AllowManual" value=<% _STSWriteHTML(Request.Form["AllowManual"]); %>>
<input type="hidden" name="RoleSelect" value=<% _STSWriteHTML(Request.Form["RoleSelect"]); %>>
<input type="hidden" name="AutoStartCreate" value=<% _STSWriteHTML(Request.Form["AutoStartCreate"]); %>>
<input type="hidden" name="AutoStartChange" value=<% _STSWriteHTML(Request.Form["AutoStartChange"]); %>>
<input type="hidden" name="GuidAssoc" value=<% _STSWriteHTML(Request.Form["GuidAssoc"]); %>>


The workflow developer must program what happens when the administrator submits changes to the form. In general, the custom workflow association form must perform the following actions:



  • Examine the value of the GuidAssoc parameter to determine whether the user is adding a new workflow association or editing an existing workflow association.
  • If the user is adding a new workflow association, call the AddWorkflowAssociation method to create a new workflow association.
  • If the user is editing an existing workflow association, call the UpdateWorkflowAssociation method to update that workflow association.
  • Create the task list for the workflow, if it does not already exist.
  • Use the data collected from the user to set properties of the SPWorkflowAssociation object, as appropriate.
  • Create the workflow history list, if necessary.
Specifying Initiation Forms
If you want your workflow to have an initiation form, you must set the InstantiationURL attribute of the Workflow element in the workflow template definition. Set this element to the form you want to use to collect the workflow initiation data, as shown in the following example.
InstantiationURL="MyWkflInitiationPage.aspx"

Initiation Form Processing

When a user starts a workflow on a specific item, Windows SharePoint Services examines the InstantiationURL attribute of the Workflow element, in the workflow template definition, to determine the proper form to load.

Windows SharePoint Services loads the specified form, passing to it the following query parameters in the URL:

  • List The GUID of the list to which the item belongs.
  • ID The ID of the list item on which the workflow is started.
  • Source The page from which the user started the workflow.
  • TemplateID The GUID of the workflow association.

In addition, you can program your form to load the association form data for this workflow association. This information is contained in the AssociationData property of the SPWorkflowAssociation object that represents the workflow association.

The workflow developer must program what happens when the user submits changes to the page. In general, the form must perform the following actions:

  • Locate the SPWorkflowManager object for the current site.
  • Use the SPWorkflowManager object to invoke the StartWorkflow method, passing the appropriate SPListItem and SPWorkflowAssociation objects. Use the eventData parameter to pass the initiation form data in string format.
  • Return the user to the source page from which he or she started the workflow.

When the M:Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(Microsoft.SharePoint.SPListItem,Microsoft.SharePoint.Workflow.SPWorkflowAssociation,System.String) method is called, the workflow manager creates an instance of the workflow on the SharePoint item. The workflow manager then passes the data gathered using the initiation form to the OnWorkflowActivated event of the workflow itself.

Any Windows SharePoint Services workflow must start with an OnWorkflowActivated activity. The OnWorkflowActivated activity contains a property, WorkflowProperties, that returns an SPWorkflowActivationProperties object. This object represents the initial properties of the workflow as it starts, such as the user who added the workflow and the list and item to which the workflow was added. In addition, the AssociationData property returns a System.Collections.Hashtable object that represents the custom data provided by the workflow initiation form.

[This article is taken from Microsoft's WSS 3.0 SDK for easy access]



Issue/Error: "A 32-bit version of SharePoint Server is not installed. Please install a 32-bit version of SharePoint Server"

When I was trying to create workflow project by using Visual Studio 2008, I faced above issue.

WSS Extensions from Microsoft (released in Feb 2009):
http://www.microsoft.com/downloads/details.aspx?FamilyID=b2c0b628-5cab-48c1-8cae-c34c1ccbdc0a&DisplayLang=en

Note: Installing above extensions didn't work for me. Try your luck.

Alternative Solution: WSPBuilder
Instal WSPBuilder extension for Visual Studio installed (www.codeplex.com/wspbuilder)

  • In Visual Studio 2008, File > New > ProjectSelect WSPBuilder and then Select then WSPBuilder Project with WorkflowClick OK
  • In the Solution Explorer window Right Click on the Projet Name (for example, WSPBuilderProject1)> Add > Sequential Workflow
  • In the add New Item Window that just open, select Workflow categorie and the Sequential Workflow And then , click on the Add button.Witch templates do you prefer : With code separation or with code ?

I hope the issue resolved by now.