Jevgeni Borozna's blog

SharePoint, ASP .NET
Workflow ASPX Initiation Form bug in Visual Studio 2010

When you are adding Workflow Initiation Form to your Visual Studio project, then Visual Studio generating aspx page with buttons and code behind with some lines of code.

SharePoint workflow can be associated with list, site or content type. This generated code works fine with workflows associated with List, but if your workflow is associated with list content type, then when you will click Start button – you will get exception.

This error is in method StartListWorkflow() at following line of code:

SPWorkflowAssociation association =
   this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];

Exception will be thrown on next line, because association will null, if workflow was associated with content type.

To solve this problem you can replace this line of code with following code:

SPWorkflowAssociation association =
   this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];

if (association == null)
{
   association = workflowListItem.ContentType.WorkflowAssociations[new Guid(associationGuid)];
}

Now entire method should look like following:

private void StartListWorkflow()
{
   SPWorkflowAssociation association =
      this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];

   if (association == null)
   {
      association = workflowListItem.ContentType.WorkflowAssociations[new Guid(associationGuid)];
   }
   this.Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData());
   SPUtility.Redirect(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource,
      HttpContext.Current);
}
Getting default Workflow History List in SharePoint

When it is needed to add Workflow Association programmatically, then it requires instance of Workflow History List. There is 2 possibilities: list already exists or you should create it.

private static SPList GetHistoryList(SPWeb web)
{
      string historyListName = SPResource.GetString(
            "DefaultWorkflowHistoryListName",
            new object[0]);
      SPList historyList = web.GetListByName(historyListName);
      if (historyList != null)
      {
            return historyList;
      }
      // create list if there is no such list yet
      Guid listGuid = web.Lists.Add(
            historyListName,
            string.Empty,
            SPListTemplateType.WorkflowHistory);
      historyList = web.Lists.GetList(listGuid, false);
      historyList.Hidden = true;
      historyList.Update();
      return historyList;
}

Here is in use extension method for SPWeb which returns null if list not found (default methods throwing Exception in this case). Here is the code of this extension method:

public static SPList GetListByName(this SPWeb web, string listName)
{
     try
     {
         return SPUtility.GetSPListFromName(web, Guid.Empty, null, null,
             listName);
     }
     catch
     {
         return null;
     }
}
Most interesting from SharePoint 2010 Virtual Ignite Training: 4th Day

11 feb 2010: Virtual SharePoint 2010 Ignite Training for Developer

Day topics:

  • Enterprise Content Management
  • Extending SharePoint Search
  • BI and Performance Point Services
  • Sandboxed Solutions

Search

  • Item-level security
  • Control the resulting display URL

REST

  • Access to SharePoint lists and library data
    • …/_vti_bin/listdata.svc
  • Lists and List items map to resources
    • Listdata.svc/Employees(123)

BI Tools in SharePoint 2010

  • Status Indicators
  • Chart Web Parts
  • PerfomancePoint Services
  • Excel Services
  • BI Search
  • Visio Services

Videos:

Extending Search - The Connector Framework

Extending Search - Enhancing the Search UI

Extending Search - Creating Custom Ranking Models

Business Intelligence Primer

Excel Services

Performance Point Services

Introducing Sandboxed Solutions

Executing Code in the Sandbox

Most interesting from SharePoint 2010 Virtual Ignite Training: 3rd Day

10 feb 2010: Virtual SharePoint 2010 Ignite Training for Developer

Day topics:

  • Workflow
  • Services Architecture
  • External Data in SharePoint (BCS)
  • Enterprise Content Management (ECM)

Notes:

"Whats New" for SharePoint 2010 Workflow

  • For the end-user
    • New targets to run a workflow
    • Visio visualization
  • For the power-user
    • Improved nested logic
    • New Task Process designer
    • Customizable OOB workflows
  • For the developer
  • Visual Studio 2010 SharePoint tools
  • Workflow Events
  • Pluggable External Data Exchange Services

SharePoint Designer Improvements for Workflow

  • For Design
    • New declarative workflow designer
    • Advanced task process designer
    • InfoPath forms
    • Visio workflow designer
  • For Development
    • Reusable workflows
    • Visio visualizations
    • Export as WSP

SharePoint 2010 offers new development process:

  1. Envision workflow in Visio
  2. Import into SharePoint Designer
    • Parametrize
  3. Export to Visual Studio 2010
    • Add code

Visio -> SPD -> Visual Studio 2010

What's new in Visual Studio 2010 for Workflows

  • Site Workflows
    • List / Item properties are null
    • No auto-start
  • ASP .NET Form Templates
  • New events
  • External Data Exchange

Workflow Events:

  • Events fired during workflow lifetime
    • Started, Completed…
  • Scenarios
    • Call sub-workflows and wait for completion
    • Provide more elaborate error handling
  • Familiar model for developers
  • SPWorkflowEventReceiver
    • Base class for handling workflow events
    • Register on site / list / content type

Enterprise Content Management

  • Unique Document ID Service
    • New site collection Feature: Document ID
    • Adds unique ID for all documents throughout the site collection
    • Documents can be retrieved regardless of the current of future location on their unique ID
  • Enterprise Content Types
    • Define once for the enterprise, use in multiple site collections in the same or different farms
  • Advanced Routing
    • Advanced routing - users upload to sites
      • Routing rules will determine where the document is saved
      • Routing rules defined by site administrators
    • Adds capability for documents to be sent to Record Center automatically on a schedule

Videos:

Most interesting from SharePoint 2010 Virtual Ignite Training: 2nd Day

9 feb 2010: Virtual SharePoint 2010 Ignite Training for Developer

Notes:

  • Intellisense when editing Wiki-pages and other type of pages and inserting some page property. (When writing “[["…)
  • 4 default Master Pages:
    • v4.master (default for SP 2010)
    • minimal.master
    • simple.master (For error pages or login pages. Not customizable, but pages can be replaced)
    • default.master (Old-style master page, as in SP 2007. Without ribbon and other new things. For supporting SP 2007 projects when migrating them)
  • New Rich Text Editor supports XHTML (source is a valid XHTML)
  • User Custom Action can be scoped to list / site / site-collection
  • Multiple forms per type (many New, Display or Edit or other type of forms per List or Library). On of them must be set as default form for each type (New, Display, etc)
  • Inline adding / editing items in a list (adding / editing items directly from List View, without opening New or Edit form)
  • Rows conditional formatting in list view
  • New properties on SPQuery:
    • SPQuery.Join
    • SPQuery.ProjectedFields
  • Use SPLinq instead of CAML to join lists (Building-time error vs runtime error)
  • Microsoft SharePoint Foundation 4.0 lists can now support 50M items
  • Unique columns must be indexed (automatically configured)
  • List Item Validation (Rule with formula. In SharePoint 2007 was possible to validate fields only)
  • Silverlight Client Object Model
    • The web part can contain custom properties that are sent to Silverlight via the InitParameter property
    • The XAP file can be deployed to LAYOUTS and loaded at run time
    • The Silverlight application can then make use of the Client OM
  • ECMAScript Client Object Model
    • ECMAScript Client OM is easily added to SharePoint ASPX page - reference:
      • _layouts/sp.js
  • SPMetal utility generates Entities for all site things (Lists, fields, etc) for using them with SharePoint Linq
Most interesting from SharePoint 2010 Virtual Ignite Training: 1st Day

8 feb 2010: Virtual SharePoint 2010 Ignite Training for Developer

Notes:

  • Now SharePoint by default has rating and tagging functionality.
  • SharePoint 2010 works in both IE and Firefox.
  • Content Organizing functionality: document going to some sub-folder based on some pre-defined rule(condition). For example, based on some column value.
  • New client-side object model and runtime (working with SharePoint Web services as with SharePoint API directly).
  • Now SPWeb objects are automatically disposable. SPSite not.
  • Server Explorer for SharePoint is extendible. Developer can develop some additional actions for it. For example, “Right Click” menu for Content Type.
  • Code debugging with “F5” – Run from Visual Studio 2010 (deploying code for deploying and automatically attaches to working process).
  • Upgrade Elements in Element-manifests (CustomUpgradeAction, ApplyElementManifest, …)
  • MinimumVersion for Feature  Activation Dependency (will try to upgrade feature to meet minimum version [force])

New events in SharePoint (listed only new events!):

  • Workflow events:
    • WorkflowStarting / WorkflowStarted
    • WorkflowPostponed
    • WorkflowCompleted
  • List events:
    • ListAdding / ListAdded
    • ListDeleting / ListDeleted
  • Site events:
    • WebAdding / WebProvisioned

Workflow Association – now it is possible to associate workflows in Element-manifests (… and based on ContentType too)

Replacement and Improved Framework for STP: Save as Template –> WSP file (which can be opened in Visual Studio 2010)

Solution Framework changes:

  • Two types of solutions: farm solutions and sandboxed solutions
  • Solution dependencies (No Visual Studio 2010 Designer support)
    • Does not deploy dependent solution automatically. Will check only.
  • Application Resources Files
  • Solution Upgrade

Which exams will be available for SharePoint 2010?

  • Exam 70-667 - TS: Microsoft SharePoint 2010, Configuring
  • Exam 70-573 - TS: Microsoft SharePoint 2010, Application Development
  • Exam 70-668 - PRO: SharePoint 2010, Administrator
  • Exam 70-576 - PRO: Designing and Developing Microsoft SharePoint 2010 Applications

* Exams will be available in 2010

Using Resource files in SharePoint 2010 and Visual Studio 2010

To deploy Resource files with SharePoint solution / package, your solution must be not SandBoxed. So if you have choose SandBoxed Solution when you have created your project in Visual Studio, you should change it. To do it complete following steps:

  1. Open Solution Explorer in Visual Studio
  2. Select your SharePoint project
  3. In “Properties” tab set “Sandboxed Solution” to FALSE

image 

Now you should create folder mapped to SharePoint Resources folder.

  1. Right click on your project in Solution Explorer
  2. “Add” –> “SharePoint Mapped Folder …”

    image
  3. Choose “Resources” and click “OK” button

    image
  4. Visual Studio will create folder Resources for you and sub folder inside it with your project title as folder name. You should delete it, because SharePoint doesn’t allow to deploy resource files inside subfolders.
  5. Right click on just created folder –> Add –> New Item
  6. Under “General” tab choose “Resources File”, rename it and click “Add”

Now you can add some entries to new resource file. When you will deploy your solution …

image

… deploying operation will automatically copy it into SharePoint Resources catalog (“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Resources”)

* don’t name resource file with names which have already in SharePoint Resources catalog (otherwise you can loss SharePoint default functionality)

Now you can use your resources files where you need.

Fore example in Field-schema definition you can get value following way:

DisplayName="$Resources:PMS.ContentTypes,Contact_FirstName;"

PMS.ContentTypes is a resource file name
Contact_FirstName is a key inside resource file

Adding GUID generator (guidgen) to Visual Studio 2010

Default Guid generator location for Visual Studio 2010 is:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\guidgen.exe

To add it to Visual Studio Tools menu complete following steps:

  1. Open Visual Studio 2010
  2. Tools –> External Tools
  3. Click on “Add” button
  4. Enter Title for the command (for example “Create GUID”)
  5. In Command box click on browse button named “…” and choose guidgen.exe (C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\guidgen.exe)
  6. Finally click on OK button and now you have possibility to choose “Create GUID” command from your Visual Studio Tools menu

If you can’t find guidgen.exe in this location, you can always download this utility separately. For example here.

* information based on Visual Studio 2010 beta 2

“The project type is not supported by this installation” error when creating any SharePoint project in VS2010

When you are trying to create some SharePoint project based on SharePoint templates in Visual Studio 2010 you can meet some problems.

image

You are creating new project and as a result it returns you error: “The project type is not supported by this installation”. And without any additional information. It is a very strange. Why Visual Studio showing things, what you can’t use?

image

As a result of creating project we have only empty project folder and what is more strange we haven’t .csproj file what Visual Studio trying to open.

I’ve tried to install SharePoint 2010 SDK, but it doesn’t helped. Actual problem was on, that Visual Studio wasn’t installed correctly, but without any error or warning messages.

Solution:
To solve this problem you should run Visual Studio 2010 Repair setup (Repair/Reinstall option).

Long operations on a SharePoint 2007 page

Sometimes you would like to accomplish some task on a Page which takes more time than is set as “timeout” and you are seeing Request timed out in your browser.

This type of error is not so informative for end-user and is not beautiful for a complete solution.

SharePoint default solutions solving this kind of problems with “Operation in Progress” page:

image

SharePoint API proposes SPLongOperation named class to solve this problem the same way in your custom solutions.

MSDN documentation:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splongoperation.aspx

This class provides you two main methods: Begin() and End(); and to properties: LeadingHTML and TrailingHTML, which can be set to show custom text.

Between calling Begin and End methods you can complete long operations. Code example:

// "this" is a Page

using (SPLongOperation longOperation = new SPLongOperation(this))

{

    longOperation.LeadingHTML = "Your operation is in progress.";

    longOperation.TrailingHTML = "Your operation is currently ..";

 

    // start long operation

    longOperation.Begin();

 

    // do nothing 3 minutes

    Thread.Sleep(60000 * 3);

 

    // when operation will be finished

    // user will be redirected to this page

    longOperation.End("/_layouts/settings.aspx");

}

More Posts Next page »