I created an alternated notification feature for SharePoint 2010. It’s a demo project for SharePoint 2010. I’ve done it for some practice in SharePoint development and just for fun 🙂
It’s intended to replace the default notification feature of SharePoint 2010 where you can subscribe to notifications list based. – With my feature a user can subscribe to all changes of a SharePoint Web by using a menu entry in the Personal Actions menu.
The notification mail is send to any subscribing user once a day. (Please notice that at the moment there is no security trimming for the notification mail!)
6. If the web feature is active the “Change Log” list will contain a list item for each change in other lists of the web.
A list event receiver recognizes each list level change: Created lists, deleted lists. It adds list item event receivers to each list in the web.
A list item event receiver creates items in the “Change Log” list for each list item action: add, update, delete.
7. If the web scoped feature is deactivated the list event receiver and all list item event receivers are removed. If the feature gets activated the list event receiver and a list item event receiver for each existing list are registered.
8. The farm scoped feature deploys a timer job that scans each web of a specific web application. If the web feature is active in a web the timer job looks for the change log list and for subscribers. If there are at least one subscriber and at least one one change since the last job run the notification mail is send.
9. It’s localized for german and english. The notification mail text is part of a resource file. But the resource file value for the mail text can be replaced by using a Web Property.
10. The notification mail is not security trimmed! That’s important for use in a production environment!
11. It’s tested in both a german and an english SharePoint system with both language packs, with multiple site collections and multiple webs and sub webs. I’d like to hear your experiences. Please report any bug. Feel free to modify it but please send me your improvements!
For development and some related tasks I use PowerShell, of course. – I store the PowerShell scripts in my projects as part of them. They are part of the source code and they are saved in the source control.
If I need to run such a script I start it directly from Solution Explorer in VS2010.
Therefore I’ve set the default “open with…” to “powershell.exe”
If you have done this you can run every “.ps1” script file by double click in Solution Explorer!!
BUT… VS2010 itself is 32bit! – If you start an architecture independend process like “poweshell.exe” from within VS2010 it runs in 32bit environment! But sometimes you need to run a 64 version of PowerShell, e.g. for some SharePoint tasks that need an 64 bit environment.
Therefore I’ve created a little App “StartPS64”:
1. In VS2010 create a new Project of type “Console Application”
2. Open the project’s properties, select the “Build” tab and change “Platform target” to x64.
3. Edit “program.cs” and insert this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace StartPS64
{
class Program
{
static void Main(string[] args)
{
string fullname = System.IO.Path.GetFullPath(args[0]);
if( !System.IO.File.Exists(fullname) )
{
Console.WriteLine("Script does not exist!");
Console.ReadKey();
return;
}
Process.Start(@"c:windowssystem32windowspowershellv1.0powershell.exe", fullname);
}
}
}
4. Compile it.
5. Specify the build “startps64.exe” as new “default application” for “.ps1” files in VS2010 as described above.
6. Now every “.ps1” file started from the Solution Explorer will run in an 64 bit environment and can execute SharePoint cmdlets!
1. Create a new SharePoint 2010 project in Visual Studio 2010. Use the “Empty Project” template. Name the project “ik.SharePoint2010.SPWCFWebServiceDemo”.
2. In the project creation wizard specify the Central Administration address as deployment location. You need to deploy as “Farm Solution”:
3. Now add this Assembly References:
Microsoft.SharePoint.Client
Microsoft.SharePoint.Client.Runtime
Microsoft.SharePoint.Client.ServerRuntime
(You may need to locate this assembly in the file system: “C:WindowsassemblyGAC_MSILMicrosoft.SharePoint.Client.ServerRuntime14.0.0.0__71e9bce111e9429cMicrosoft.SharePoint.Client.ServerRuntime.dll”)
System.Configuration
System.ServiceModel
System.ServiceModel.Web
Now my Assembly Reference tree looks like this:
…
4. Now map the SharePoint hive folder “Layouts” to your project:
a) Right click your project in the Solution Explorer Pane
b) In the context menu open sub menu “Add” and click “SharePoint Mapped Folder”
c) Select this:
d) Click “OK”
5. Create a sub folder named “ik.SharePoint2010.SPWCFWebServiceDemo” in folder “Layouts”
6. Add a new project item of type “Interface” to your project. Name it “ISPWCFSvc.cs”.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.ServiceModel;
using System.ServiceModel.Web;
namespace ik.SharePoint2010.SPWCFWebServiceDemo
{
[ServiceContract(Namespace="http://schemas.microsoft.com/sharepoint/soap/"), Guid("f01e2ff6-c291-4b8b-a154-cd7059ed4900")]
public interface ISPWCFSvc {
[OperationContract, WebInvoke(Method = "GET")]
List<string> GetUsedEmailAliasses();
[OperationContract, WebInvoke(Method = "GET")]
string Ping();
}
}
7. Add a new project item of type “Class” and name it “SPWCFSvc.cs”
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Security;
namespace ik.SharePoint2010.SPWCFWebServiceDemo
{
[Guid("ae428eb5-02d1-4e50-8cee-eb3806f16ffd"),
ServiceBehavior(Namespace = "http://schemas.microsoft.com/sharepoint/soap/"),
AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required),
ClientRequestServiceBehavior,
SharePointPermission(SecurityAction.Demand, ObjectModel = true),
AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public class SPWCFSvc : ISPWCFSvc {
[SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
public List<string> GetUsedEmailAliasses()
{
List<string> l = new List<string>();
SPProcessIdentity pi = SPContext.Current.Site.WebApplication.Farm.TimerService.ProcessIdentity;
string userName = pi.Username;
object configDB = pi.GetType().GetProperty("ConfigurationDatabase", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pi, null);
SPServer server = (SPServer)configDB.GetType().GetProperty("Server").GetValue(configDB, null);
string dbName = (string)configDB.GetType().GetProperty("Name").GetValue(configDB, null);
string serverName = server.Name;
SPSecurity.RunWithElevatedPrivileges(() =>
{
System.Data.SqlClient.SqlConnection s = new System.Data.SqlClient.SqlConnection(new System.Data.SqlClient.SqlConnectionStringBuilder {
DataSource = serverName,
InitialCatalog = dbName,
IntegratedSecurity = true }.ConnectionString);
SPConfigDBDataContext dc = new SPConfigDBDataContext(s);
foreach( var item in dc.EmailEnabledLists )
{
l.Add(item.Alias);
}
});
return l;
}
[SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
public string Ping()
{
return "Pong";
}
}
}
8. Now add a new “Text File” project item and name it “spwcfsvc.svc”
Here we use an existing service factory of SharePoint that will handle the service instanciation for us.
In this file we use the token replacement functionality of Visual Studio 2010 for SharePoint 2010 development. We like to replace the token “$SharePoint.Type.ae428eb5-02d1-4e50-8cee-eb3806f16ffd.AssemblyQualifiedName$” through the “real” full qualified name during package creation.
By default *.svc files will not be processed by the token replacement engine. We need to specify *.svc files for that build step. Therefore we edit the C# project file in notepad. Insert this line as shown in the screenshot:
After deploying the solution you may have a look into the SharePoint hive and look into “spwcfsvc.svc”
9. Now Copy & Paste this file into the you folder in the mapped Layouts folder:
C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14ISAPIweb.config
10. You need to edit this file. Remove the complete “<system.web>” tag and the (four) “location” tags at the beginning of the copied file! – The configuration settings in the copied & modified web.config file will manage the diffrent authentication methods for us. This works by using the class attribute “ClientRequestServiceBehavior” in the code above.
11. Now we add a “Linq to SQL” connection to the SharePoint Configuration database. Be sure only to read this DB!!!
12. Add a new project item of type “Linq to SQL Classes” to the project. Name it “SPConfigDB.dbml”
13. In the Server Explorer of Visual Studio 2010 create a connection to the SharePoint Configuration DB of your development environment. – After that, open the connection, open the “Table” node and select “EmailEnabledLists”.
14. Drag the “EmailEnabledLists” node to the “SPConfigDB.dbml” canvas. – It looks like this:
15. In the Properties Pane set the “Context Namespace” property to “ik.SharePoint2010.SPWCFWebServiceDemo”. (If you do not see this properties like in the screenshot below you need to right click the “SPConfigDB.dbml” project item node in the Solution explorer and click “Properties” in the context menu.
16. Now you should be able to compile and deploy your project.
17. Edit the startup settings. In the “Debug” select “Start browser with URL” and enter there the URL to your webservice: “http://<central-administration-url-and-port>/_layouts/ik.sharepoint2010.spwcfwebservicedemo/spwcf.svc/GetUsedEmailAliasses”
18. Now start the project. You get something like this:
I’ve only one e-mail enabled list or library in my current dev system.
In some projects there was a need to run code on the client machine for interaction with SharePoint. If’ve realized this kind of applications as “ClickOnce” apps. It’s possible to deploy them as “SharePoint Solution Package”. If you do so the ClickOnce files can be deployed to every WFE. Updating the ClickOnce is easy.
Here I want to show you how to deploy a ClickOnce app als SharePoint Solution.
Let’s start.
1. Create your ClickOnce app. – If you have an existing one skip to step 5. – Otherwise continue reading. I’ll show you how to create a very simply ClickOnce.
Open Visual Studio 2010. Create a new project of type “Windows Forms Application” or “WPF Application”. I’ll use the first one and name the project “MyClickOnce”.
Design you app. – I drag 2 Label controls, 2 Checkbox controls and 2 Textbox controls to the surface. I do not change their names but their fonts
In my app I’d like to show the “running context”: locally started EXE or online started ClickOnce. Furthermore I’d like to show the URL if started online.
2. Open the Code view of the form.
First of all you need to add a assembly reference for “System.Web”!
Then insert this code. Maybe you need to correct the name of the controls.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Specialized;
using System.Deployment.Application;
using System.Web;
namespace MyClickonce
{
public partial class Form1 : Form {
public Form1()
{
InitializeComponent();
ParseParams();
checkBox1.Checked = !IsOnline;
checkBox2.Checked = IsOnline;
textBox1.Text = Url;
textBox2.Text = Parameters["Param1"];
}
private bool _isOnline = false;
private NameValueCollection parameters = null;
private string _url = "";
public bool IsOnline
{
get {
return _isOnline;
}
}
public string Url
{
get {
return _url;
}
}
public NameValueCollection Parameters
{
get {
return parameters;
}
}
private void ParseParams()
{
NameValueCollection nameValueTable = new NameValueCollection();
if( ApplicationDeployment.IsNetworkDeployed )
{
_isOnline = true;
_url = ApplicationDeployment.CurrentDeployment.ActivationUri.ToString();
string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
parameters = HttpUtility.ParseQueryString(queryString);
}
else {
_isOnline = false;
parameters = HttpUtility.ParseQueryString(string.Join("&", Environment.GetCommandLineArgs()));
}
}
}
}
The method “ParseParams” will be useful while developing the app and later running the app: This method is able to parse both “command line parameter” sources: URL and native (EXE). During development you maybe need to pass parameters to the app for testing purpose. Than you define this parameters in the “Debug” tab of the project properties.
Here is a screenshot of the app’s debug settings:
You see there is a parameter “Param1” follwed by “=” and it’s value. This is similar to URL style query string parameters. But you do not separate them with “&”! Instead use a single whitespace. – Later in the URL you will use “&” as normal!
Now just run the app!
Nice, isn’t it?
3. Now you need to configure the application to become a ClickOnce.
Open the Project Properties of your Windows Form App project.
Select the “Signing” tab and create a self signed certificate. Or use a valid Code Signature certificate.
Now switch to the “Publish” tab of the project settings.
Here you can change the settings as you need it. – I’ll leave it as is EXCEPT one setting: Click the “Options…” button and select “Manifests”. Check “Allow URL parameters to be passed to application”:
[If you do not set this the app will fail in the following line because “ActivationUri” will be null: “_url = ApplicationDeployment.CurrentDeployment.ActivationUri.ToString(); “]
The other settings:
Click “Publish Now”.
Than the project will be build and stored to the sub folder “Publish” of your project folder in the file system.
4. If you now try to run the app locally you may get this error:
This is caused by your ClickOnce publishing in the step before.
The resolve this open the project settings, select the “Security” tab and clear the checkbox “Enable Clickonce security settings”:
This you need to do after each ClickOnce publishing!
5. Now we create the SharePoint Solution Package.
In the Solution Explorer click on the solution item, click “Add” and click “New project”.
Now chooce “Empty SharePoint Project” and name it “MyClickonceDeployment”.
As local site I use “http://sharepoint.local/sites/clickonce”. It has to be a “Farm Solution”!!
Now create a “Module” project item. Name it “MyClickonce”.
Remove the file “Sample.txt”
6. Now open the solutions path in Windows Explorer.
Go into the folder of the Windows Forms Application. There go into the “Publish” folder.
Select the “.application” file of your ClickOnce app and select the “Application Files” folder. This items you need to copy. Just select “Copy” from the context menu or press Ctrl+C.
No open the folder of “MyClickonceDeployment” and go into the folder “MyClickonce”. There insert (paste) the selected items.
Now you folder should look like this:
In the “Application Files” folder you’ll see another folder “1_0_0_0” or with another version number. This version number will be increased by every ClickOnce publishing if you did not disable this function.
7. Back in the Visual Studio go into the Solution Explorer and click this icon:
This will show you all files in the project folder, not even project items.
Select the “MyClickonce” module project item. Maybe you need to click the icon:
You should see this:
Right click on “MyClickonce.application” and select “Include in project”. Right click on “MyClickonce_1_0_0_0” and select “Include in project”.
Now you need to edit the “Elements.xml” file of you module project item.
First of all add an attribute named “Path” to the “Module” tag. This will define the URL of your ClickOnce app. Select a unique name so that the solution won’t get in conflict with other solutions. You could choose a GUID here or use date and time:
Now you can remove the string “MyClickonce/” of the beginning of every “Path” attribute of the child nodes of the “Module” tag.
After removing the string the file should have this content:
That’s it. – Please let me know if it worked for you!
Of course you could build query strings in JavaScript to pass dynamically generated parameters to the ClickOnce!! This is charming and makes ClickOnce apps to become usefull in SharePoint development. You could create custom Ribbon menu items and call a ClickOnce app on click. As parameters you could pass ListID, Web URL, ItemID, … to the app! Very cool!
Today I got the following error and did not find a clear description and solution for it:
Error message: “Event “OnWorkflowActivated” on interface type “Microsoft.SharePoint.Workflow.ISharePointService” for instance id “<guid>” cannot be delivered.”
The Solution: …in my case was a missing “EventDriven” activity.
My “Initialization” state looks like this:
I’ve added a “StateInitialization” Workflow Activity and added some code to it. But this is a SharePoint Workflow and it needs at least an “OnWorkflowActivated” event driven activity.
Let’s walk through the solution:
1. Drag a “EventDriven” activity to the “Init” state. Its name may defer in your project.
2. Name the EventDriven activity “onWorkflowActivatedHandler”. (You can use an other name too!)
3. Double click the EventDriven activity.
4. Drag a “OnWorkflowActivated” activity from the Toolbox pane into the “onWorkflowActivatedHandler” activity:
5. Add a correlation token to “onWorkflowActivated1”!!
6. Add a binding for “WorkflowProperties” !!!
7. That’s it. Now you can add activities behind “handleExternalEventActivity1”… As you like.
This time a tiny neat walkthrough of how to add an Event Receiver at runtime in SharePoint 2010.
Let’s say you have a SharePoint site that your colleagues already use. In this site you have an existing list. Now you want to add some automation to this existing list. – You cannot deploy the list as List Definition w/ List Instance again in a VS 2010 SharePoint project, because the list exists and the data must not be touched.
One solution is to add an List Event Receiver that is contained in a VS2010 solution package.
1. You create a Empty SharePoint 2010 project in Visual Studio 2010.
2. Now you add an “Event Receiver” project item
3. Now you add the events you want to handle. Select “List Item Events” and “Custom List”.
4. Implement some functionality in the newly created Event Receiver class.
5. Now create or open an Feature Event Receiver for the SharePoint feature that will configure the event receiver. – You have to create a new feature or use an existing feature… If you create a new feature event receiver you have to uncomment the methods “FeatureActivated” and “FeatureDeactivating”.
6. Add this code to the “FeatureActivated” method:
try {
SPWeb web = (SPWeb)properties.Feature.Parent;
SPList l = web.Lists["My SharePoint List"];
if( l != null )
{
bool found = false;
foreach( SPEventReceiverDefinition er in l.EventReceivers )
{
if( er.Class == "Full.Namespace.Qualified.Class.Name.Of.Your.Event.Receiver.Class") {
found = true;
break;
}
}
if( !found )
{
SPEventReceiverDefinition newERD = l.EventReceivers.Add();
//the next line is only valid if the event receiver class is in the same assembly as the feature event receiver!!!
This time it’s not a walkthrough. Only a description of what you have to do. – It’s “experimental”!!!
The need is to deploy a conditional formatting in a list definition that was created in a SharePoint 2010 Visual Studio (2010) project.
1. You need to design the list definition. Create a list instance for the list definition. This instance you can remove later if you want.
2. Deploy the project. It’s without conditional formatting at this point.
3. Create the conditional formatting in SharePoint Designer.
Open the list instance.
Open the list view you want to modify.
Select the cells that should have a conditional formatting.
Create the conditional formatting.
4. Open the “Code” view of the list view page.
5. Look for the “<xsl>” tag of the XsltListViewWebPart that renders the list data.
Copy the content of the <xsl> tag.
6. In Visual Studio open the “Schema.xml” file of the list definition.
7. In the <views> tag look for the view you want to modify. E.g. “AllItems.aspx”. Look for the “Url” attribute of the view tag that contains the Web Part Page name (e.g. “AllItems.aspx”).
8. Before the closing “view” tag add this:
<Xsl>
<![CDATA[
...
]]>
</Xsl>
Replace the “…” through the copied content of the web part pages “xsl” tag content.
9. Deploy the project.
10. It’s done! – BUT: You may be unable to edit the conditional formatting in SharePoint Designer! As I said: It’s experimental.
This is not easy. It took me some days. – Now it works!
Here I’ll show you how to create a List Form for a SharePoint List using InfoPath 2010. Therefore you need SharePoint 2010 Server with Enterprise CALs! – With InfoPath Forms Services it’s possible to render List Forms (“New”, “Edit” and “Display” forms) as browser enabled InfoPath forms. This is really, really cool!
9. Open the site in the browser. Navigate to the “Test List 1”. Select “Edit in SharePoint Designer” from the “Site Actions” menu.
10. In SharePoint Designer 2010 open the “Lists and Libraries” from the “Navigation” pane and open the “Test List 1”.
In the Ribbon you’ll see the command “Design Forms in InfoPath”.
Click the command button and select “List Item” in the drop down menu.
Now InfoPath Designer 2010 opens…
11. In InfoPath Designer 2010 modify the form.
(I will not modify it.)
Press the “Publish” button on the Shortcut Menu:
12. In SharePoint Designer 2010 choose “All Files” from the “Navigation” pane. Click “Lists”.
Click “TestList1”.
Click “Item”.
Right-click “template.xsn”. Select “Properties…” from the context menu.
Select the “Location” from the properties dialog.
Copy the URL and open it in a new browser window. You’ll get a “File Download” dialog.
Save the file to a temporary location, e.g. to the Desktop.
13. Add a new “Module” project item and name it “Form”.
Open a Windows Explorer. Navigate to the Desktop. Drag the file “template.xsn” from the Desktop into the “Form” module inside the Visual Studio project.
Modify the “Elements.xml” file of the “Form” module.
14. Add a new “Module” project item and name it “FormPages”.
Into the “Elements.xml” file of this module enter the following code:
During deployment this creates the form aspx pages that will host the InfoPath Web Part that renders the form at runtime.
In the XML code there are several references to the destination list. All of them have to be set to “Lists/TestList1”. All the code needs to remain unmodified. Don’t change “WPTypeId” attributes! “{b1dc92e2-8558-f555-ae81-35ed9ddf1644}” is the identifier for InfoPath Render Web Part.
BUT change the “ID” attributes of the three “WebPart” tags! Use the “Create GUID” tool from the “Tools” menu of Visual Studio 2010.
15. Now open the “Schema.xml” file of the List Definition project item of “Test List 1”. Add the following code at the before the closing tag of our list content type.
This will define the “template.xsn” to be a “InfoPath Forms Services” file ().
17. Deploy the project.
18. Open the browser and navigate to the “Test List 1”.
Click “Add new item”…
19. HERE WE ARE!
But if you enter values and try to save you get this error:
This is caused by the missing “Title” field inside the form. This field is marked as mandatory so you need to define it or to remove it from the Content Type and modify the form.
We will do the last one now.
20. In Visual Studio modify the “schema.xml” file of the “Test List 1”. Insert the marked line of code inside the “FieldsRefs” tag of the content type with id starting “0x01…”.
Now search for “LinkTitleNoMenu” in the schema.xml file. Replace this “view field reference” with “Edit”.
Now search for “LinkTitle” and replace it with “Edit” too.
21. In Visual Studio look for “template.xsn” in “Form” path in the Solution Explorer. Right-Click the project item and select “Open Containing Folder”.
22. In Windows Explorer right-click the file “template.xsn” and click “Design”. The InfoPath 2010 Designer will open.
23. In InfoPath 2010 you’ll see that “Title” cannot be removed. To remove it you would need the edit the xsn file with Notepad: XSN is a CAB file. So you can rename it to cab, extract it’s content, modify the “manifest.xfs” file and compress the folder as CAB file named “template.xsn”… (If you need assistance on this please post as comment.)
In the “Fields” pane select “Title”.
(This is the “advanced view” !)
Click the arrow behind the element. Click “Properties” in the context menu.
Uncheck “Cannot be blank”. Click the “OK” button. Save the file. Don’t press “Publish” on the upcoming dialog. Just press “Save”!
Quit InfoPath.
Deploy the project.
24. In Internet Explorer refresh you site and add a new item to the “Test List 1”.
You’ll see: the “Title” column is gone. Now we have a “Edit item” column on the list view.
Now add an item.
Save it.
25. HERE WE ARE AGAIN!
It works for me now!
Just for testing purpose select the list item and click “View Item” on the Ribbon.
You will see the list item in a read-only InfoPath browser form!! – If you click “Edit” on the Ribbon, you’ll be able to edit the item.
In this walkthrough I want to show you how to create a Sequential Workflow with Visual Studio 2010 for use in SharePoint 2010. – I will show how to create a custom Task Form for interaction with users. The Task form will be a native SharePoint list form. No InfoPath. There are many InfoPath samples out there but they cannot be used on a SharePoint Foundation 2010 platform. But workflows can be used on SharePoint Foundation 2010 too!
To reproduce the following steps you need to create a SharePoint site. – In the walkthrough I’ll use a Site Collection located at “http://sharepoint.local/sites/workflow”.
The “TemplateType” attribute represents the “Workflow History” list template. It resists on a SharePoint feature with ID “00BFEA71-4EA5-48D4-A4AD-305CF7030140”. It’s a native SharePoint feature.
You can add the attibute “Hidden” to the “ListInstance” tag and set it’s value to “TRUE” to hide the list as it’s done by SharePoint by default for this list. In this case you should also change “OnQuickLaunch” to “FALSE”. For my demo purpose I want to have “Workflow History” visible and on the Quick Launch bar.
5. Now we will create all tools we need for a “Workflow 1”. (May be I’ll create more workflow demos later. So it’s number 1.)
6. We create the SharePoint fields for “Workflow 1”. Therefore we create another “Empty Element” project item named “Workflow 1 Fields”.
I’ll create 3 fields for use in the Task Form we will create: Test1, Test2, Test3. They are all fields of type Text.
This specifies there to store the “Task1Form.aspx” file in the site structure.
9. In the next step we create the task list that will contain our workflow tasks.
First create a “List Definition” project item named “Workflow 1 Tasks”.
Use “Workflow 1 Tasks” as name of the list definition and “Tasks” as base type. Check “Add a list instance…”.
10. Now open “Elements.xml” of the new list definition project item.
We need to change the identifier of the list type we create! – It must be “107”. This is the list template ID for workflow tasks lists in SharePoint. The workflow designer will search for a list with this type inside the site where a new workflow will be created.
Here is the content of “Elements.xml” after our modification:
You see the “FormUrls” tag? Inside this tag we specify our custom form template we created before.
The new content type is derived from the “Workflow Task” content type 0x010801. – In the “FieldRefs” section we add our fields we need inside the workflow.
13. Now we need to add the field definitions of our custom fields to the “Schema.xml”. Copy them from the “Elements.xml” file of project item “Workflow 1 Fields” into the “Fields” tag of “Schema.xml”:
Furthermore you need to add a field definition for the field “Completed”:
Check “Do not prompt…”. Press “Resolve Automatically” – it’s your only option .
15. Have a look into the site using the browser. – We will test our “Edit” form. Remember that we did not specify special “New” form or “Display” form. This you could do the same way as you created the “Edit” form.
We see our lists in the Quick Launch.
Open the “Workflow 1 Tasks” list. On the Ribbon open the “Items” tab. We see our Content Type in the New Item submenu:
Create an item of this type. You see a standard “New” form and on it you see our three “Test” fields:
Enter some data and press “Save”.
Open the item in “Edit” form. Now you should see our custom list form.
If you click “Save As Draft” your changes will be stored in the task item. If you click “Complete Task” two item fields will be changed in addition to the changes made in the form: It sets “Status” to “Tasks_Completed” and “% Complete” to “100”. You can see this in the Code Behind file of the list form.
Test all buttons.
After “Complete Task”:
You see: “% Complete” is set to “100 %”.
So far our projects works as expected.
See Part 2 for the next steps… There I will show you how to create a simple Sequential Workflow that uses our Task Form.