segunda-feira, 22 de junho de 2009

Editor XAML bacana

Eai galera demorei mais to ai firme e forte essa semana tava procurando um editor pra brincar um pouco com o silverlight e encontrei uns bacanas vou colocar aqui o link.

Página oficial e download do KaXAML 1.0 ou 1.5 beta.
nesse vídeo veja como usa-lo.

sexta-feira, 5 de junho de 2009

DVD SilverLight

Durante a conferência da Microsoft MIX08, foi disponibilizado um DVD inteiro com referência, tutoriais e demos sobre o Microsoft Siliverlight. São mais de 2 GB de informações disponíveis para download aqui. Vale a pena para quem está começando.

quinta-feira, 4 de junho de 2009

Meu Apredizado - RampUp

Pra quem quer aprender um pouco mais de Dev para SharePoint segue mais alguns tutoriais muito bom pra aprendizado.

Clique aqui

segunda-feira, 1 de junho de 2009

Videos Sharepoint para download

* 2007 Office System Video: Windows SharePoint Services Platform
* Windows SharePoint Services 3.0 Video: Blog and Wiki Support
* Demo: Tour a SharePoint site
* SharePoint Screencasts (Video Tutorials)
* Office SharePoint Server 2007 Video: Web Content Management in Office SharePoint Server 2007
* Video demos for Office SharePoint Server 2007
* Demo: Tour a Windows SharePoint Services 3.0 site
* 2007 Office System Video: Enterprise Content Management
* 2007 Office System Video: Portals
* 2007 Office System: How Do I Screencasts
* SharePoint Designer 2007 Business Administrator Training
* Microsoft Office SharePoint Server 2007 demo
* White papers for Office SharePoint Server 2007
* Microsoft Office SharePoint Server 2007
* 2007 Office System Video: Client Development
* Office 2007 in action

Blog Event Handler + CAML Query

Blogs sobre Event Handler e CAML Query

Writing a Filter Consumer Web Part for Windows SharePoint Services 3.0 Using Excel Services

O artigo sobre Writing a Filter Consumer Web Part for Windows SharePoint Services 3.0 Using Excel Services

Building Master Pages for Windows SharePoint Services 3.0 using Site Definitions in Visual Studio 2005

Building Master Pages for Windows SharePoint Services 3.0 using Site Definitions in Visual Studio 2005

To illustrate how to build a SharePoint site definition with a custom master page, this section walks through five key steps:

  1. Creating a SharePoint Team Site Definition project in Visual Studio.

  2. Adding a custom master page to the site definition project.

  3. Editing the custom master page.

  4. Editing the site definition's onet.xml file to use the custom master page.

  5. Building and deploying the site definition to a SharePoint site.

Create a Team Site Definition Project in Visual Studio 2005

Begin by creating a Team Site Definition project in Visual Studio 2005.

To create a SharePoint Team Site Definition project

  1. Start Visual Studio.

  2. On the File menu, click New, and then click Project. The New Project dialog box appears.

  3. In the Project types pane, click Visual C#, and then select the SharePoint category.

  4. In the Templates pane, select Team Site Definition. Specify a Name and Location for the project, and click OK. Visual Studio creates the project and opens the generated onet.xml file.

Add a Custom Master Page to the Site Definition

If the default.master page already meets most needs and only a few changes are required, a good option for creating a new master page is to copy default.master and then modify the copy. This is the approach illustrated by this Visual How To.

By default, the default.master page is located in the following folder on the drive to which Windows SharePoint Services 3.0 was installed:

drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL

To add a copy of the default.master file to the project

  1. Copy the default.master file into the Site Definition folder under the site definition project folder that was created by Visual Studio. (The Site Definition folder contains the default.aspx and onet.xml files generated by Visual Studio.)

  2. Rename the copy of the master page to mydefault.master.

  3. In Visual Studio, click the Project menu, and then click Add Existing Item. Visual Studio displays the Add Existing Item dialog box.

  4. Navigate to the Site Definition folder that contains the mydefault.master file. In the Files of type list, select All Files (*.*). Select the mydefault.master file, and then click Add.

Edit the Custom Master Page

After you add the new master page to the project, you can customize it in Visual Studio. Open the master page from the Visual Studio Solution Explorer, and edit the page to make the needed changes. Save the changes to the master page.

ImportantImportant:

When editing the master page, be careful not to delete any of the ContentPlaceHolder controls that are on the page by default. They are required for the collaboration features of Windows SharePoint Services 3.0, such as SharePoint lists and libraries. Deleting those controls can break other SharePoint pages that rely on the presence of the named content regions.

Edit the Site Definition's onet.xml File

When Visual Studio created the Team Site Definition project, it generated a default onet.xml file that was configured to use the site and system defaults for master pages. You need to change the onet.xml file to use the custom master page.

To edit the onet.xml file to use the custom master page for the site definition

  1. In the Visual Studio Solution Explorer, open the onet.xml file. Figure 1 shows the changes you make in the following steps.

    Figure 1. Editing the onet.xml file
    Building Master Pages using Site Definitions
  2. Locate the Configuration element that has an ID of "0" and add the following attributes:

    CustomMasterUrl="_catalogs/masterpage/mydefault.master"
    
    MasterUrl="_catalogs/masterpage/mydefault.master"
  3. Windows SharePoint Services defines two types of master pages: the System Master Page and the Site Master Page. Forms and views pages use the System Master Page; publishing pages use the Site Master Page. The CustomMasterUrl attribute tells Windows SharePoint Services which page to use for the Site Master Page. The MasterUrl attribute tells Windows SharePoint Services which page to use for the System Master Page.

  4. Locate the Modules child element within the Configuration element and add the following Module element:

    <Module Name="MyDefaultMaster" />
    
  5. Locate the Modules element outside the Configuration element and add the following Module and File elements:

    <Module Name="MyDefaultMaster" Url="_catalogs/masterpage">
    
    <File Url="mydefault.master" Type="GhostableInLibrary" />
    Module>
  6. Save the changes to the onet.xml file.

Building and Deploying the Site Definition

At this point the site definition project is ready to be built and deployed.

To build and deploy the site definition project

  • In Visual Studio, click Build, and then click Deploy Solution. Visual Studio builds the assembly for the site definition and generates the necessary configuration files for deployment of the solution. It then deploys the solution to the SharePoint site.

You can test the new site definition by creating a new SharePoint site that is based on the site definition. All pages on the site will use the custom master page.

Read It

This article illustrated how to build SharePoint Services 3.0 site definitions with a custom master page using Microsoft Visual Studio 2005 with Extensions for Windows SharePoint Services 3.0. The key steps include:

  1. Creating a SharePoint Team Site Definition project in Visual Studio.

  2. Adding a custom master page to the site definition project.

  3. Editing the custom master page.

  4. Editing the site definition's onet.xml file to use the custom master page.

  5. Building and deploying the site definition to a SharePoint site.


Debugando um (Event Handler) Evento para Project Server 2007

Code It

This section walks through eight key steps to write and debug event handlers for Project Server 2007. The key steps are:

  1. Creating a class library project in Microsoft Visual Studio 2005.

  2. Adding references to the required assemblies to the Visual Studio project.

  3. Signing the class library assembly with a strong name.

  4. Adding the code that implements an event handler for the project publishing event.

  5. Deploying the event handler assembly to the computer running Office Project Server.

  6. Registering the event handler with Project Server by using Project Web Access.

  7. Testing the event handler.

  8. Debugging the event handler.

Creating a Class Library Project in Visual Studio 2005

To create a class library project in Visual Studio 2005, use the following procedure.

To create a class library project in Visual Studio 2005

  1. Start Visual Studio.

  2. On the File menu, point to New, and then click Project.

  3. In the New Project dialog box, in the Project Types pane, click Visual C# or Visual Basic, and then select the Windows category.

  4. In the Templates pane, click Class Library.

  5. For the project Name, type TestEventHandler.

  6. Specify a location for the project, and then click OK.

    Visual Studio generates a class library project with a single source file in it named Class1.cs or Class1.vb, depending on which language you selected in Step 3.

  7. In Solution Explorer, right-click the source file, and then click Rename. Rename the Class1.cs or Class1.vb source file to PublishingEventHandler.cs or PublishingEventHandler.vb, depending on which language you are using.

Adding References to the Required Assemblies

The event handler described in this article uses both Project Server classes and Windows SharePoint Services classes. To enable these classes to be used in the project, add references to the required Project Server and SharePoint assemblies.

To add references to the required assemblies

  1. If you are running Visual Studio on a computer that has Project Server 2007 installed, do the following:

    1. With the TestEventHandler project open in Visual Studio, on the Project menu, click Add Reference.

    2. By default, the Project Server assemblies are not visible on the .NET tab in the Visual Studio Add Reference dialog box. However, you can browse for the assembly files. In the Add Reference dialog box, click the Browse tab, and then navigate to the \Bin folder in the following path:

      %Program Files%\Microsoft Office Servers\12.0\Bin

    3. Locate the Microsoft.Office.Project.Server.Events.Receivers.dll file and the Microsoft.Office.Project.Server.Library.dll file, press and hold the CTRL key, and select both files.

    4. Click OK to add the references.

    5. On the Visual Studio Project menu, click Add Reference.

    6. In the Add Reference dialog box, on the .NET tab, locate and select the Windows SharePoint Services component (Microsoft.SharePoint.dll).

    7. Click OK to add the reference.

    If you are running Visual Studio on a computer that does not have Project Server 2007 installed, do the following:

    1. On a computer that does have Project Server installed, locate the \Bin folder in the following path:

      %Program Files%\Microsoft Office Servers\12.0\Bin

    2. Copy Microsoft.Office.Project.Server.Events.Receivers.dll and Microsoft.Office.Project.Server.Library.dll from the \Bin folder to a local project folder on the development computer. These two files are required to create the event handler,

    3. The sample event handler also requires the SharePoint assembly. On a computer that has Windows SharePoint Services 3.0 installed, locate the ISAPI folder in the following path:

      %Program Files%\Common Files\Microsoft Shared\web server extensions\12\ISAPI

    4. Copy Microsoft.SharePoint.dll from this path to the same local project folder on the development computer.

  2. After you make local copies of the Office Project Server and SharePoint assemblies, you can add references to them by browsing for the local files. To add references to local copies of the assemblies, do the following:

    1. On the Project menu, click Add Reference.

    2. In the Add Reference dialog box, click the Browse tab, and then navigate to the local folder that contains the copies of the assemblies.

    3. Press and hold the CTRL key, and select the following files: Microsoft.Office.Project.Server.Events.Receivers.dll, Microsoft.Office.Project.Server.Library.dll, and Microsoft.SharePoint.dll.

    4. Click OK to add the references.

    NoteNote:

    Applications or components that use the Microsoft.SharePoint.dll assembly must run on the computer where Office Project Server or Project Web Access (with Windows SharePoint Services) is installed. Because you will later copy the TestEventHandler.dll assembly and run it on the computer running Office Project Server, you can develop it on a different computer.

Signing the Class Library Assembly with a Strong Name

You can deploy the event handler assembly either to a special event handler directory or to the global assembly cache. To allow the event handler assembly to be installed in the global assembly cache, it must be signed with a strong name. A strong name consists of the assembly's identity—its simple text name, version number, and culture information (if provided)—plus a public key and a digital signature.

To assign a strong name to the event handler assembly in Visual Studio

  1. With the TestEventHandler project open in Visual Studio, on the Project menu, click TestEventHandler Properties.

  2. On the project properties page, click the Signing tab.

  3. Select the Sign the assembly check box.

  4. In the Choose a strong name key file list, click New.

  5. In the Create Strong Name Key dialog box, type keyfile as the key file name, and then clear the Protect my key file with a password check box.

  6. Close the project properties page.

Adding the Code That Implements the Event Handler

To add the code that implements the event handler, use the following procedure.

To add the code

  1. Add the following Imports or using statements to the top of the PublishingEventHandler.cs or PublishingEventHandler.vb source file. For PublishingEventHandler.cs, add the using statements after the using statements that were generated by Visual Studio when the project was created.

    Visual Basic
    Imports System.Diagnostics
    Imports System.Net
    Imports System.Text
    Imports Microsoft.Office.Project.Server.Events
    Imports Microsoft.Office.Project.Server.Library
    Imports WSS = Microsoft.SharePoint

    using System.Diagnostics;
    using System.Net;
    using Microsoft.Office.Project.Server.Events;
    using Microsoft.Office.Project.Server.Library;
    using WSS = Microsoft.SharePoint;

    The Imports or using statements make it possible to use the classes and types defined in the referenced namespaces without needing to use fully qualified namespace paths.

  2. Add the code for the class that implements the event handler. The sample event handler writes an entry to the Application event log when a project publishing event occurs. Replace the Visual Studio–generated code for the PublishingEventHandler class with the following code.

    Visual Basic
    Public Class PublishingEventHandler
    Inherits ProjectEventReceiver

    Public Overrides Sub OnPublishing( _
    ByVal contextInfo As PSContextInfo, _
    ByVal e As ProjectPrePublishEventArgs)

    MyBase.OnPublishing(contextInfo, e)


    Dim myLog As EventLog = New EventLog()
    myLog.Source = "Project Server"

    ' Get information from the event arguments, and
    ' write an entry to the Application event log.

    Dim userName As String = contextInfo.UserName.ToString()
    Dim projectName As String = e.ProjectName.ToString()
    Dim siteGuid As Guid = contextInfo.SiteGuid
    Dim pwaUrl As String = New WSS.SPSite(siteGuid).Url
    Dim eventId As Integer = 7692
    Dim logEntry As String = String.Empty

    e.Cancel = False

    If (projectName.Substring(0, 3).Equals("Prj")) Then
    logEntry = vbCrLf + "User: " + userName + _
    vbCrLf + "Project: " + projectName + _
    vbCrLf + "Site ID: " + siteGuid.ToString() + _
    vbCrLf + "PWA Instance: " + pwaUrl + _
    vbCrLf + "The project name is valid. Publishing..."

    myLog.WriteEntry(logEntry, EventLogEntryType.Information, _
    eventId)
    Else
    logEntry = vbCrLf + "User: " + userName + _
    vbCrLf + "Invalid project name: " + projectName + _
    vbCrLf + "Site ID: " + siteGuid.ToString() + _
    vbCrLf + "PWA Instance: " + pwaUrl + vbCrLf + _
    "To be published, the project name must start with " + _
    "'Prj'."

    myLog.WriteEntry(logEntry, EventLogEntryType.Warning, _
    eventId)

    e.Cancel = True
    e.CancelReason = "Invalid Project Name."
    End If
    End Sub
    End Class

    public class PublishingEventHandler : ProjectEventReceiver
    {
    public override void OnPublishing(PSContextInfo contextInfo,
    ProjectPrePublishEventArgs e)
    {
    base.OnPublishing(contextInfo, e);


    EventLog myLog = new EventLog();
    myLog.Source = "Project Server";

    // Get information from the event arguments, and
    // write an entry to the Application event log.

    string userName = contextInfo.UserName.ToString();
    string projectName = e.ProjectName.ToString();
    Guid siteGuid = contextInfo.SiteGuid;
    string pwaUrl = new WSS.SPSite(siteGuid).Url;
    int eventId = 7692;
    string logEntry;

    e.Cancel = false;

    if (projectName.Substring(0, 3).Equals("Prj"))
    {
    logEntry = "\nUser: " + userName +
    "\nProject: " + projectName +
    "\nSite ID: " + siteGuid.ToString() +
    "\nPWA Instance: " + pwaUrl +
    "\nThe project name is valid. Publishing...";

    myLog.WriteEntry(logEntry, EventLogEntryType.Information,
    eventId);
    }
    else
    {
    logEntry = "\nUser: " + userName +
    "\nInvalid project name: " + projectName +
    "\nSite ID: " + siteGuid.ToString() +
    "\nPWA Instance: " + pwaUrl +
    "\nTo be published, the project name must start with " +
    "'Prj'.";

    myLog.WriteEntry(logEntry, EventLogEntryType.Warning,
    eventId);

    e.Cancel = true;
    e.CancelReason = "Invalid Project Name.";
    }
    }
    }
  3. Build the TestEventHandler project.

Deploying the Event Handler

You can deploy the event handler assembly in two ways. On a computer running Office Project Server, either copy the assembly to a special event handler directory, or register the assembly in the global assembly cache.

To deploy the event handler

  • To copy the event handler assembly to the Office Project Server event handler directory, copy TestEventHandler.dll to the path %ProgramFiles%\Microsoft Office Servers\12.0\Bin\ProjectServerEventHandlers.

  • To register the TestEventHandler.dll assembly in the global assembly cache, either drag the assembly into the global assembly cache on the computer running Office Project Server, or use the gacgutil.exe tool that is included with Visual Studio. To open the global assembly cache, on the Windows Start menu, click Run, and then type assembly in the Run dialog box.

Registering the Event Handler in Project Server

Use the following procedure to register the event handler in Office Project Server through Project Web Access.

To register the event handler in Project Server

  1. In Project Web Access, in the left pane, click Server Settings.

    Figure 1. Server Settings page


    Server Settings page
  2. On the Server Settings page, in the Operational Policies section, click Server-Side Event Handler Configuration.

    Figure 2. Events page


    Events page
  3. On the Events page, in the Events list, click the Project link for the Publishing event. In the Event Handlers grid, click the New Event Handler link.

    Figure 3. Event Handler page


    Event Handler page
  4. On the Event Handler page, type the values shown in Table 1 for the various fields.

    Table 1. Values for Event Handler page fields
    Field Value

    Name

    Test Project Publishing Event Handler

    Description

    Value that ensures project names begin with "Prj"

    Assembly Name

    TestEventHandler,Version=1.0.0.0,Culture=Neutral,

    PublicKeyToken=PublicKeyTokenForTheAssembly

    Class Name

    TestEventHandler.PublishingEventHandler

    Order

    1

  5. Replace the PublicKeyTokenForTheAssembly placeholder in the Assembly Name field with the actual public key token of the assembly. You can use the strong name tool, sn.exe, to determine the public key token of the event handler assembly by doing the following:

    1. In Visual Studio, open a Command Prompt window.

    2. Navigate to the folder that contains the TestEventHandler.dll assembly, and then type the following command at the command prompt:

      sn -T TestEventHandler.dll

    The strong name tool displays the public key token of the assembly.

  6. Click Save to save the event handler settings.

    Office Project Server displays a message that explains that event registration is asynchronous and might take a few minutes to complete. Event registration uses the Shared Services Provider (SSP) and Windows SharePoint Services timer processes. If the timer interval is one minute, it can take up to two minutes to register the event handler with Office Project Server.

  7. Click OK to close the message box.

  8. Refresh the Events page to see the registered Project Publishing event handler displayed in the Event Handlers grid.

    Figure 4. Events page with registered event handler


    Events page with registered event handler

Testing the Event Handler

Use Project Web Access to test the project publishing event handler.

To use Project Web Access to test the project publishing event handler

  1. On the Project Web Access home page, in Quick Launch, under the Projects section, click Proposals and Activities.

  2. On the Proposals and Activities page, click New, and then click Proposal in the list.

  3. On the New Proposal page, complete the required information fields, ensuring that the proposal name does not start with "Prj", and then click Save.

  4. When saving is complete, click Save and Publish on the proposal page. Office Project Server attempts to publish the proposal.

  5. Open the Event Viewer on the computer running Office Project Server, click the Application events, and double-click the Warning event with the source of Project Server. The Event Properties dialog box appears showing information logged by the event handler.

    Figure 5. Event Properties dialog box


    Event Properties dialog box
    NoteNote:

    The Proposals and Activities page in Project Web Access still shows the project. The Published field shows No and the information icon for the project shows it is a draft project. That is, Office Project Server saved the proposal only in the Draft database.

  6. To check the case where the name is correct, click the project name on the Proposals and Activities page, click Summary Information on the project details page, and then change the project name so that it begins with "Prj". Click Save and Publish; the project is published. The Event Viewer shows an Information event (instead of a Warning event) with the details logged by the event handler.

Debugging the Event Handler

Registered event handlers run on the Office Project Server computer and are called by the Project Server Eventing service. To debug an event handler, use Visual Studio 2005 and attach the debugger to the Project Server Eventing process.

To debug a Project Server event handler

  1. Register and test the event handler as described previously.

  2. If you are debugging from a remote computer, install and run the Microsoft Visual Studio Remote Debugging Monitor on the computer running Office Project Server.

  3. In Visual Studio, open the event handler project that you registered, and then on the Debug menu, click Attach to Process.

  4. In the Attach to Process dialog box, select the Default transport and browse to the name of the computer running Office Project Server for the Qualifier. Click Select, and then in the Attach to options, select only the Managed check box.

    Figure 6. Attach to Process dialog box


    Attach to Process dialog box
  5. Select both Show processes from all users and Show processes in all sessions.

  6. To put Visual Studio into debug mode, in the Available Processes list, click Microsoft.Office.Project.Server.Eventing.exe, and then click Attach.

  7. On the Tools menu, click Options. Expand the Debugging node in the options list, and then click Symbols. Click the folder icon and copy the TestEventHandler project debug build directory path in the new symbol file location. Select Load symbols using the updated settings when this dialog is closed to load the TestEventHandler.pdb symbol file, and then click OK.

  8. In the code window for PublishingEventHandler.cs or PublishingEventHandler.vb, place a breakpoint at the beginning of the OnPublishing method. If the breakpoint shows only a red outline with a yellow warning symbol, the TestEventHandler.pdb symbol file is not loaded.

  9. Trigger the Publishing event by publishing a project, and step through the OnPublishing event handler in Visual Studio.

  10. Debugging cannot work if the event handler code is changed and recompiled after registering the event handler with Office Project Server. If the event handler is recompiled, you must re-register it by using the following steps:

    1. Unregister the event handler in Office Project Server.

    2. Remove the old event handler assembly from the global assembly cache or delete it from the path %ProgramFiles%\Microsoft Office Servers\12.0\Bin\ProjectServerEventHandlers.

    3. Register the recompiled event handler in the global assembly cache, or copy it to the %ProgramFiles%\Microsoft Office Servers\12.0\Bin\ProjectServerEventHandlers path.

    4. Re-register the event handler in Office Project Server.

Read It

This article shows how to write and debug event handlers for Project Server 2007. The key steps include:

  1. Creating a Class Library project in Visual Studio 2005.

  2. Adding references to the required assemblies to the Visual Studio project.

  3. Signing the class library assembly with a strong name.

  4. Adding the code that implements an event handler for the project publishing event.

  5. Deploying the event handler assembly to the computer running Office Project Server.

  6. Registering the event handler with Office Project Server through Project Web Access.

  7. Testing the event handler.

  8. Debugging the event handler.

Create a Custom Expiration Formula Based On Metadata in SharePoint Server 2007

Create a Custom Expiration Formula Based On Metadata in SharePoint Server 2007 (Part 1 of 2)

Create a Custom Expiration Formula Based On Metadata in SharePoint Server 2007 (Part 2 of 2)

SharePoint + InfoPath+Workflow

Download and install the Visual Studio 2005 Extensions for .NET Framework 3.0.

Once you have downloaded and installed those components you'll be able to create Workflow type projects but we need the SharePoint workflow templates. To get these, download and install the Microsoft Office SharePoint Server 2007 SDK which also includes the Enterprise Starter Kit.

Now that we have these two things installed in the Create New Project box in VS 2005 you should be able to create a SharePoint Sequential Workflow and a SharePoint State Machine Workflow.

So that's the setup done, now lets just recap what it is we'd like our workflow to do. This is copied from the original workflow article:

We want to allow our workflow to be associated with a list or document library. When a document is created or changed (this is a setting chosen upon binding the workflow to the list/library), a person specified will have a task created for them, with some pre-defined instructions and comments. When clicking the task the user will have a designed form where they will have instructions present, and can decide whether to complete the task with a checkbox.

From the above we’re going to need 2 InfoPath forms. Number 1 is used when binding our workflow to a list/library where we’ll enter the user who’ll get the task, and a few instructions and a comment. The second form is when the user clicks on the task. In this form they can add comments and click a checkbox to complete the workflow.

This project is basically the HelloWorldSequential workflow from the ECM starter kit, but it's a nice walk through of how to put it together yourself!

Lets go and create our workflow project in Visual Studio 2005. We're going to be using a sequential workflow template, and lets give it a name of NicksWorkflow

Once the project is created you'll see in the Solution Explorer that there's a new folder called Deployment Files. This is where you'll now find feature.xml and workflow.xml. We'll dig into how to deploy our workflow in the next blog post so don't worry about these for now.

As with the previous article, before we start writing any code we want to create our two InfoPath 2007 forms. We want to do it this way as we're going to generate a C# class from one of our forms to help with the passing of data to and from it. The first form we are going to create is the initiation form. This captures information such as who we want the task to be assigned to, a field for instructions to them and a comments textbox.

Initiation Form

1, Open up InfoPath 2007 and from the first form select 'Design a form template...'

2, Click OK to create a blank form template...

3, From the top menu bar click Insert->Layout Table... and then select your table to have 2 columns and 4 rows...

4, Add three textboxes and a button to the columns in the right, and a description in the cells to the left of each textbox. We need to also give each textbox a proper name, do this by double clicking on it, and entering the new name into Field Name

Once you've renamed your textboxes and given the button a Label value of submit, your InfoPath form should look something like this:

5, Data from InfoPath forms is represented by XML. To make it easier for us to get our hands on the XML data we require we can give the XmlElement that holds these control values a better name. From the Design Tasks toolbar click on Data Source...

Double click on myFields

And in the following form that opens up enter InitForm as the Name value...

Click OK to close that.

6, Now we need to configure what happens when people click on the submit button. Double click on the submit button to bring up it's properties, from the General tab click on the Rules button

In the following form, click Add to create a new rule. Click 'Add Action', and from the following form chose 'Submit using a data connection' from the drop down, then click the Add button just below:

In the next wizzard chose the following options to submit your data:

and then the hosting environment as the destination

Leave the name as Submit and click Finish. And then OK on the 'Add Action Form'

Now we want to add another action, so back in the Rule form click 'Add Action...' This time the action 'Close this form' and make sure the checkbox is not selected...

Clicking OK takes us back to our Rules form. That's the two actions we want to add for our Submit button. With them both together they should look like this:

Click OK to close this form.

7, Now we need to ensure our form can be viewed in a browser as this is how InitForm will be used when setting up a workflow.

Go back to our Design Tasks toolbar, and click 'Design Checker'

From the Design Checker pane chose 'Change Compatibility Settings...'

Click the checkbox to allow our form to be opened in a browser, also enter the url for MOSS 2007 to help verify compatibility...

While you are in this form, click on the Browser category, and ensure the language selected is infact a language pack that you have installed on your MOSS server...

One final step is to go to the 'Security and Trust' category. In here untick to automatically determine the level of security, and select Domain...

Click OK to close the 'Form Options' form. Now we need to save our form. Save it directly to the C:\ as DemoInitiation.xsn. Once saved we can publish it by going File->Publish, chose to publish it 'To a network location' and then chose the location of your VS 2005 project, and the "Deployment Files/Feature Files" folder.

Click Next, remove the path as the alternate access location. You will get a warning when clicking next on that form but that is ok. If you do not remove the alternate access path you will have problems when publishing your form to work with workflow. Finally Publish and Close.

When we submit our forum to SharePoint we need to be able to get the data from the submitted form to be able to use in our workflow. To help do this we can generate a class using xsd.exe based off the form schema file. First we need to save our InfoPath form as Source Files. File -> Save as Source Files. Browse to the location you want to save the file (c: is a nice easy place), and click OK. By default the source files are saved as filename myschema.xsd. Once saved close InfoPath.

Now open up a Visual Studio 2005 command prompt and navigate to where you saved myschema.xsd. From the prompt type xsd myschema.xsd /c

this generates a c# class file called myschema.cs. Rename the file to InitForm.cs, and add it to you VS 2005 workflow project. If you take a look inside the classes code you’ll see the name of the class is the same that we gave to the forms field collection.

Edit Task Form

Now we need to jump back into InfoPath 2007 so we can create our form that enables users to edit the task they get assigned to complete the workflow.

1, Open InfoPath 2007 again and create a blank form as we did before. On this form we’re going to want an instructions textbox where we’ll place the instructions entered when we bound the workflow to a list/library, a checkbox to check to say the workflow is complete, and an ok button. Lay it all out and rename the fields to something like below...


Underneath the isFinished tooltip is simply some text of 'Completed'.

2, Add the same rules to the OK button as you did to the submit button for the DemoInitiation form (ie submit to a hosted environment, and then close).

3, When this Edit form opens we’re going to want to pass some data to it (ie the instructions), we do this by creating a task schema and adding it as a secondary data source.

Open up notepad and add the following:

In this file we need to define every property that we are going to pass to the Task Edit form. To do this, add an attribute comprised of the prefix ows_ and the name of the task property. Set the attribute equal to an empty string. So to pass the instructions to the Task Edit form that were added when we bound the workflow to the list/library we add the following attribute:
ows_instruction=””

So your finished notepad text should be:

It doesn't matter where you save the file, just make sure it's called ItemMetadata.xml (yes it does matter about the case with this).

4, Now we need to add the task schema to our Edit Task form as a secondary data source. Back in InfoPath, in the Design Tasks pane select Data Source, and then click 'Manage Data Connection'.

In the form that opens you'll see there is a Submit data connection already. On the form Click Add to create a new data connection. On the wizzard form that opens click so the new connection receives data...

Select XML Document as the data source to receive data from...

Then browse and select the ItemMetadata.xml file you created in Notepad in step 3...

Leave the option selected to include this file as a data source...

Click Next, and then Finish. The data connections form should now look as below:

Click Close to get that job done!

5, Now we need to bind the data that we are receiving from our new data connection to the necessary fields. Double click the instructions textbox and on the Data tab, under Default Value, click the formula button (underlined in red)...

On the Insert Formula dialog box, click Insert a Field or Group. In the Select a Field or Group dialog box, select your ItemMetadata data connection from the drop down menu. Select the ows_MetaInfo_instructions element.

Click OK. On the Insert Formula dialog box, click OK. On the Properties dialog box, click OK.

6, Now we need to do the same things as we did with the initiation form, set the form as browser enabled also entering the url of our MOSS server, check the language setting of the form, and also set the Trust Level as Domain.

Save the form to c:\ again (or whever you saved it), and publish it to your VS workflow project, "Deployment Files\Feature Files" directory again.

And that's it for InfoPath, our forms are created and ready to use!!!

Back to Visual Studio 2005

Now we can get down to some coding! In the solution explorer double click on Workflow1.cs and up will open the workflow designer view. If you open up the toolbox you'll see three new groups of components, SharePoint - Workflow Tasks, SharePoint - Workflow, and Windows Workflow.

As you can see on the Workflow1.cs design surface it already creates the first workflow step for us with a onWorkFlowActivated action. This will always be the first Workflow action of any workflow. Below this action is an arrow and a kind of stop sign. We can drag and drop any new workflow actions from the tool box and place them on the arrow. Before we do that though there are a few properties we can check before we get going. If you go into the code view of Workflow1.cs you’ll see

public sealed partial class Workflow1: SharePointSequentialWorkflowActivity
{
public Workflow1()
{
InitializeComponent();
}

public Guid workflowId = default(System.Guid);
public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties workflowProperties = new Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();
}

This is all created for you because you used a template project. If you view the properties of work onWorkflowActivated1 you’ll see the following important properties set for you:
CorrelationToken : workflowToken
OwnerActivityName : Workflow1
WorkflowProperties – expand this
Name : Workflow1
Path : workflowProperties – again this is a variable that was created for us and set from the code above.

We also get an event for this control. When this fires we’ll want to setup any initial variable values that are required for the workflow. Type into the Invoked space onWorkflowActivated and press enter. You’ll see it goes to the code view and creates our event handler for us with the correct interface. We’ll come back to this later.

Now to add our first workflow control. Now that the workflow has actually started the first thing we want to do is create a task for the person who’s been set to complete it. Remember we defined this when attaching the workflow to an actual list in SharePoint. To do this drag and drop a CreateTask control just below our onWorkflowActivated1 control.

We need to set a few properties for this control. First type in the Correlation Token as taskToken. Upon pressing enter you’ll see that you can expand this property to reveal OwnerActivityName which once again should be set as Workflow1.
Next we’ll set the TaskId and TaskProperties which can be accomplished in a couple of ways. First method is to click on the default value of TaskId (0000–0000…. or something) and you’ll see three ellipses on a button appear. Click on this and it’ll open a dialogue box for you. Click on the ‘Bind to a new member’ tab and click the 'Create Field' radio button.

Click OK. In the propeties window of createTask1 you’ll see now that not only have 2 pairs of name and values gone into the TaskId property, but you can expand them out to set them seperately. Also if you switch to code view, you’ll see that a variable called createTask1_TaskId1 (the name that was entered in the 'new member name' textbox) has been added to our code for us.

Follow the same procedure for TaskProperties. Switch back to the code view again and you’ll see the variable created for us. If you go back to the createTask1 properties view and click the ellipses for TaskProperties again, you can see in the ‘Bind to an existing member’ that this property is bound to taskProps in our Workflow1 class. So as well as using this dialog box and the ‘Bind to a new member’ tab, we could have gone into our code view, created the createTask1_TaskId1 and createTask2_TaskProperties1 variables ourselves, and then used the Bind to an existing member view to set the values of the properties. Final thing to do is create the event that fires when this activity executes. In the Method Invoking field enter createTask and click enter. Again is creates our event handler and interface for us. Again we’ll come back to this is a little while. Finally we need to set the CorrelationToken as taskToken (just type it in). The same token name will be used in other task activities that we drag onto our workflow. Using the same token ensures we are working with the same task. Here is how the properties window for createTask1 should be looking:

Now that our task has been created for the assigned user, we need to add some waiting functionality to enable the workflow to wait for the task to be completed by the user. We do this using the While workflow component.

Drag and drop a While component from the Windows Workflow section in the toolbox between the createTask1 and the end of the workflow. In the properties window select Code Condition as the Condition property's value and then expand the field. Then type notFinished into the extra field presented and press enter. This will create an event handler for you in code where you check whether the While condition has been met (ie has the user completed their task).

Now we want to add an activity to the centre of our While loop. Here we’ll place an onTaskChanged. This basically means that the While loop will execute and check our code condition, every time our task is edited. It won’t be able to exit out of the While loop until our method notFinished returns false (which means it is finished!). Drag an onTaskChanged component and drop it in the middle of our While loop.

You’ll see in the properties window there are quite a few things we need to set:
AfterProperties = click the ellipses and bind to a new Field member
BeforeProperties = click the ellipses and bind to a new Field member
CorrelationToken = select taskToken from the drop down
Invoked = onTaskChanged. When you’ve typed it in press enter to create the event handler for you.
TaskId = click the ellipses and bind to the existing member called createTask1_TaskId1

The properties window for onTaskChanged should now look as below, make sure you set the Correlation Token:

The final component we want to add to our workflow is the CompleteTask activity. Drag and drop a CompleteTask component between the While component and the stop workflow activity. In the properties set the Correlation Token to taskToken from the drop down. Again with the TaskId click the elipses and bind it to createdTask1_TaskId1.

Now we’ve added all the components to our workflow. Our workflow designer should look as below:

Now we’ve got all our components added, and event handlers and methods created, we need to add some code to Workflow1.cs.
Right click on Workflow1.cs and click View Code. The first bit of code we need to add declares a few variables we are going to need in our workflow. Just above the onWorkflowActivated method add:

private String assignee = default(String);
private String instructions = default(String);
private String comments = default(String);

These three values are ones that we are going to get from our DemoInitiation form. These properties are passed to the workflow as an XML string represented by the InitiationData property of the SPWorkflowActivationProperties object. To access these properties we need to parse this XML string. This is where we make use of the generated class based on the schema of our initiation form that we did in step 4 and added to our project as InitForm.cs. To get these values add the following code to the onWorkflowActivated method:

workflowId = workflowProperties.WorkflowId;
XmlSerializer serializer = new XmlSerializer(typeof(InitForm));
XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(workflowProperties.InitiationData));
InitForm initform = (InitForm) serializer.Deserialize(reader);
assignee = initform.assignee;
instructions = initform.instructions;
comments = initform.comments;

The next method we need to add some code to is createTask Method. Here we want to set some properties of a task as this method fires just before the task does actually get created. Here’s the code:

createTask1_TaskId1 = Guid.NewGuid();
createTask1_TaskProperties1.Title = "Demo Task";
createTask1_TaskProperties1.AssignedTo = assignee;
createTask1_TaskProperties1.Description = instructions;
createTask1_TaskProperties1.ExtendedProperties["comments"] = comments;
createTask1_TaskProperties1.ExtendedProperties["instructions"] = instructions;

as you can see there are a predefined properties such as Title and AssignedTo to use, and if there’s any other properties you want to name and create yourself you can use the ExtendedProperties. This is a hash table so you can name things as you like.

The final bit of code we need to add is probably the most complex to get our heads around. We need to add a private Boolean variable called isFinished. Place this just above the notFinished method:

private bool isFinished;

Now our While loop calls the notFinished method. One of the objects passed in is ConditionalEventArgs which has a property called result. If result is set to false, the while loop will end, if result is set to true, the while loop continues. As you should be able to work out, the variable above we created isFinished will be true once the task has been finished. Therefore we have to negate it to set it’s value to the ConditionalEventArgs result property. In the notFinished method type the following code:

e.Result = !isFinished;

The last thing we need to do is actually set isFinished when our task gets edited ie when onTaskChanged event files. In here we just need to parse out the isFinished value from our onTaskChanged1_AfterProperties1 object. At the code below to the onTaskChanged method:

isFinished = bool.Parse(onTaskChanged1_AfterProperties1.ExtendedProperties["isFinished"].ToString());

And that’s it. Build your solutions, and hopefully everything compiles succesfully. Now I was also going to include instructions on how to deploy this workflow, but I’m going to save that for a few days time.