Walkthrough: Creating a simple Sequential Workflow with a custom Task Form in SharePoint 2010 using Visual Studio 2010 (Part 2 of 2)

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”.

This blog post is part 2 of 2. It describes the steps 16 to 27. Read part 1 here: https://blog.kenaro.com/2011/03/30/walkthrough-creating-a-simple-sequential-workflow-with-a-custom-task-form-in-sharepoint-2010-using-visual-studio-2010-part-1-of-2/

You can download – and help to develop – the whole demo project source code at Codeplex: http://spworkflowdemo.codeplex.com/

(If you need assistance for the deployment process because of deployment errors please see this third post of this series: https://blog.kenaro.com/2011/04/22/walkthrough-creating-a-simple-sequential-workflow-with-a-custom-task-form-in-sharepoint-2010-using-visual-studio-2010-part-3-of-21/)

Let’s start (again)…

16. Now we need to add a list that we use to connect a workflow with. We create a “List Definition” project item named “Workflow 1 Host List”.

image

image

We change the “Elements.xml” file of the List Instance project item.

image

We change the Title, URL and Description.

image

17. Deploy the project.

18. Now we start creating a Sequential Workflow.

Create a “Sequential Workflow” project item named “Workflow 1”.

image

Create the workflow as “List Workflow”.

image

You will see all the lists we created in the previous steps. Remember: You have to (successfully) deploy the project before you can use the lists that will be created during deployment. – Without previous deployment the wizard may fail before you see the following dialog page.

In the first dropdown list choose “Workflow 1 Host List”. All other lists should be selected automatically because there is only one usable list of every needed type.

image

Select all “Workflow start” options: “Manually”, “Item Created”, “Item Updated”.

image

You get:

image

19. We will add a “Create Task With Content Type” workflow activity that will use our “Workflow 1 Task 1” we created in the steps 1 to 15 (blog post “part 1”).

Open the “Toolbox” pane and drag “CreateTaskWithContentType” into the Workflow Designer.

image

After you did this you get:

image

Now we need to configure the workflow activity in the “Properties” pane.

Set “correlationToken” to “task1” and the sub element of “correlationToken” named “OwnerActivityName” to “Workflow_1”.

image

Now we need to create code behind properties for some activity properties. As example I’ll show how to create a code behind property for “ContentTypeId”.

Click on the Button “…” at the activity property edit box:

image

In the dialog select the tab “Bind to a new member”. Enter the name “New member name” and select the “Create Property” radio button. Press “OK”.

image

Here are the property bindings you need to create:

  • “ContentTypeId” = “task1ContentTypeId”
  • “TaskId” = “task1Guid”
  • “TaskProperties” = “task1Properties”

In “MethodInvoking” type “createTask1Invoke” and press ENTER. – You’ll be directed to the code editor.

(The activity properties look like this after you finished: image)

In the method we initialize the task1-Properties we created before. The “ContentTypeId” is taken from the “Schema.xml” file of our “Workflow 1 Tasks” list where we created the Content Type “Workflow 1 Task 1”.

After that your method looks like this:

image

20. Back in the workflow designer. We drag a “While” activity from the Toolbox pane into the workflow behind the “Create Task” activity.

image

Into the “While” activity we drag a “Sequence” property from the Toolbox pane. We get:

image

Into the “Sequence” activity we drag a “OnTaskChanged” activity from the Toolbox pane. We get:

image

Now we edit the properties of the created “OnTaskChanged” activity. We have to set the “CorrelationToken” as described above. Additionally we specify new property bindings:

  • “AfterProperties” = “task1Changed1_AfterProperties”
  • “BeforeProperties” = “task1Changed1_BeforeProperties”
  • “TaskId” => Bind to the existing member “task1Guid”!!!
    image

In the “Invoked” property add the method name “task1Changed1Invoke”. – The code editor will be opened.

(The activity properties look like this after you finished: image)

21. In the code we add a property at class level:

image

This property we set inside the “OnWorkflowItemChanged” activity. It will contain the information whether the Workflow Task Item we created before was “Completed” by the assigned user.

In the “task1Changed1Invoke” method we set the “isFinished” property.

image

22. Now we need to specify the condition for the “While” activity. In the workflow designer select this activity. In the “Condition” property select “Code Condition” and expand the property. Enter “while1Invoke” in the subproperty with (the same) name “Condition”.

image

In the code editor enter the code for “while1Invoke” like this:

image

The “e.Result” property has to be “TRUE” as long as the while loop should run. It should not run anymore (“e.Result = false”) if “isFinished” is TRUE.

23. In the workflow designer add a “CompleteTask” activity behind the “While” activity. Drag the “CompleteTask” activity from the Toolbar pane into the workflow designer. We get:

image

Select the “completeTask1” activity and edit it’s properties in the Property pane.

  • Bind “TaskId” to the existing member “task1Guid”
  • Create a new member namend “task1Outcome” for binding to “TaskOutcome”
  • Set the “CorrelationToken” to “task1”

24. Whew! Smile

25. Deploy the project. – It deployed successfully ?! – Congratulations!

26. Open the browser and navigate to “http://sharepoint.local/sites/workflow”. Open the “Workflow 1 Host List”. Add a new item… – The “Workflow 1” should start automatically.

image

image

(After F5 / page refresh:)

image

Click “In Process”. We see the Workflow Status page:

image

In the “Tasks” section open the context menu of the element “(no title)”. – We did not set a title for the created “Task 1”. This could be done in the method “createTask1Invoke”.

image

Click “Edit Item”.

There it is!!! :

image

Just edit a property and click “Save As Draft”.

On the Workflow Status page you see that the workflow is still running but was modified (“Last run”).

image

Then edit the task again. Click “Complete Task”.

After that the workflow is “Completed”:

image

27. We have done it! – Now we could add a “Task 2” for this “Workflow 1” where some other data is requested from users.

With that method you will be able to add custom forms for Workflow Tasks. You could also use forms you create with Silverlight !!!

Thank you for your kind attention!

Error while creating a Enterprise Wiki sub site in SharePoint 2010

A customer of mine had a problem in a it’s SharePoint 2010 farm. An error occurred while creating a sub site of type Enterprise Wiki. The user that tried to create the sub site was not a site collection administrator and did not have Full Control permissions.

Steps:

1. Try to create the sub site:

image

2. Press “Create” button:

image

Error: “An error has occurred while processing your request.”

3. Retry with the same name for the sub site:

image

Error: “The Web site address … is already in use.”

At the same moment a site collection administrator could successfully create a Enterprise Wiki sub site!

I could solve the problem and reproduce it in my testing environment: The security settings of the site collections masterpage catalog had broken inheritance and nobody had any rights on this list. This does not seems to be a problem in most cases but it’s a problem while creating a Enterprise Wiki sub site. – Adding “read” access for “All authenticated users” solved the problem.

Kerberos error in event log on every SharePoint 2010 farm server.

I had an error in the event log on every SharePoint 2010 farm server:

image

A Kerberos Error Message was received:
 on logon session 
 Client Time: 
 Server Time: 13:1:13.0000 3/17/2011 Z
 Error Code: 0x7  KDC_ERR_S_PRINCIPAL_UNKNOWN
 Extended Error: 0xc0000035 KLIN(0)
 Client Realm: 
 Client Name: 
 Server Realm: xxxxx.NET
 Server Name: HTTP/xxxxx.net
 Target Name: HTTP/xxxxx.net@xxxxx.NET
 Error Text: 
 File: 9
 Line: efb
 Error Data is in record data.

This happens after migration of the old MOSS 2007 farm to SharePoint 2010. – On the new farm I used new accounts for the application pools.

I created SPNs on the new Application Pool accounts for the web applications.

BUT I forgot to remove the same SPNs from the old Application Pool accounts!!! – This was the (big) mistake.

ADSIEdit let me create the same SPN on different accounts. Sad smile

After removing the SPNs from the old Application Pool accounts everything works fine!

use SETSPN-Tool to find the accounts:

setspn Q HTTP/xxxx.net

You’ll get a list of all accounts that have the specified SPN “HTTP/xxxxx.net”

Additional Ribbon Sample: Custom Ribbon Tab generated by a delegate control that lists all associated list workflows and allow to start a workflow on a selected list item. (Part 3)

In the last weeks I’ve extended the sample project that I’ve created for “Ribbon Customization”. You find the project source code on Codeplex:

The related articles on my blog are:


I’ve created a new feature for my sample project: With a delegate control a Ribbon tab will be created dynamically on list view pages if there are workflows associated with the list. For every associated workflow a button will be created. -  But only for workflows that can be started manually.

To use the demo follow these steps:

1. Create a sharepoint site http://sharepoint.local/sites/ribbon.

2. Download the project from codeplex and deploy it.

3. Create one ore more workflows on the Shared Documents library at http://sharepoint.local/sites/ribbon using SharePoint Designer 2010. (I just added two list workflows on Shared Documents and added a simple “Add Comment” step to both of them.)

4. Open the document library. Upload at least one document. You get:

image

You see the “Workflows” tab Smile ??

image

OPEN IT!!

The dynamically generated workflow buttons are disabled!

image

NOW SELECT THE DOCUMENT!!

Now the workflow buttons are enabled!

image

CLICK ONE WORKFLOW BUTTON!!

You get a result window:

image

(It can contain an error message if one occurred.)

 

THAT’S ALL.

Next steps:

  • An error occures if the workflow is already associated with the item. It would be possible to create a server request while “enable check” to check on the server whether the workflow is already associated to the item.
  • Tests. Tests. Tests. => It’s not in a stable state!!

Walkthrough: Create a simple BCS connection with SharePoint Designer 2010

First: You need a SharePoint 2010 platform. You can use Foundation because BCS = Business Connectivity Services – former BDC = Business Data Catalog in SharePoint 2007 – included in this “free” edition.

Second: You need a database for the walkthrough. You can use Microsoft’s sample database “AdventureWorks”. You can download them here: http://msftdbprodsamples.codeplex.com – I’ll use the database “AdventureWorksLT2008R2”: This is the lite version of the sample database.

Third: The BCS Application of SharePoint 2010 must be configured. – Create this application in the Central Administration –> Manage Service Applications

Fourth: You need a Site Collection. – In my sample it’s “http://sharepoint.local”

1. Open SharePoint Designer 2010 (“SPD”)

Open the site collection.

image

2. Click “External Content Types” in the Site Objects Navigation.

image

3. Click “External Content Type” in the Group “New” on the Ribbon.

In the “External Content Type Information” group click the text message “New external content type” beside the label “Name”. 

image

Enter “AdventureWorks SalesOrderDetails”.

After that the same text will appear beside “Display Name”.

4. Click on the text message beside “External System”:

image

5. Click “Add Connection”

image

Select “SQL Server” in the drop down “Data Source Type” in the dialog.

image

On the next dialog enter the Database Server Name, Database Name and the Name of the new connection. Select “Connect with User’s Identity”.

image

6. Now the Data Source Explorer view is filled:

image

Scroll down and select the table “SalesOrderDetails” in the tree view.

Right click on “SalesOrderDetails”. Click on “Create All Operations”.

image

7. You get this dialog.

image

Click “Next”.

image

Click “Finish”.

8. Click “Save” or Ctrl+S.

9. After the upload click on “Create Lists & Form”.

image

Now the list will be created:

image

10. Open the browser and navigate to the site collection. You’ll see the previously created list:

image

11. Open the list view.

12. You may get the error “Access denied by Business Data Connectivity”.

image

13. Then open “Central Administration” –> Manage Service Application –> Business Connectivity Service Application

Select the BCS application. Open the context menu. Click “Set Permissions”.

image

On the next dialog add all users that should have access to the BCS app and it’s lists.

image

Click “OK”.

14. Try to open the list on the site collection.

15. You may get the error message “Login failed for user NT AUTHORITYIUSR”.

This means: IUSR account has no rights to access the AdventureWorks database.

Open SQL Server Management Studio. Open “Security” –> “Logins” (at server level).

Add “NT AUTHORITYIUSR” as new login.

image

On the “User Mapping” tab change the security settings:

image

Click “OK”.

 

16. Open the list again.

image

Now it works (for me).

Walkthrough: How to move or copy a SharePoint Designer 2010 List Workflow to another list on the same site or another site.

I had to develop a Holiday Approval Workflow with SharePoint Designer 2010. – I used a “List Workflow”. – Bad mistake! – It’s not possible to copy this kind of workflow to another list on the same site or another site.

I thought I could use the “Export to Visio” functionality with the workflow at my development site and the “Import from Visio” functionality at the destination list. – That’s impossible. You get this message:

image

(“This workflow cannot be imported because it was created in SharePoint Designer for a different site, or the original workflow has been moved or deleted. To move a workflow between sites, use Save as Template (.wsp file) instead of a Visio workflow drawing.”)

You cannot “Save as Template” because it’s a “List Workflow”.

Okay. – I’ve found a workaround.

Let’s do it in detail.

1. Create a site collection “http://sharepoint.local/sites/dev”.

2. Open SharePoint Designer 2010. Open the previously created site.

3. Open the “Workflows” view.

4. On the Ribbon click “List Workflow” and select “Shared Documents”. – We will create a workflow for the list “Shared Documents”.

image

Name the workflow “Workflow 1”. Leave “Description” empty.

image

5. Insert any workflow steps you like.

image

6. Change the workflow settings. Select “Task List” and “History List”.

image

7. Click “Publish” to publish the workflow Winking smile

8. Click “Export to Visio”. Save to Workflow as .vwi file, e.g. on the desktop.

image

9. Let’s test the workflow. – I’ve created a text file “test.txt” on the desktop. Now I upload the file to the “Shared Documents” library of “http://sharepoint.local/sites/dev”.

image

Open the item context menu. Click “Workflow”.

image

Manually start the “Workflow 1”.

*image

Click “Start”.

image

In the list view you see the workflow status.

image

Click on the status. In my case it’s “Completed”.

image

The workflow history says “Workflow executed” as specified in the workflow definition above.

10. Okay. Let’s copy the workflow to the production site “http://sharepoint.local”. – A simple “import” is impossible, because it’s a list workflow… Follow my steps.

11. Start the SharePoint Designer 2010 and open the site “http://sharepoint.local”.

12. On the Ribbon click “List Workflow” and select “Shared Documents”. – We will create a workflow for the list “Shared Documents”.

image

Name the workflow “Workflow 1 Production”. Leave “Description” empty.

image

11. Do not add any workflow step!

12. Click on “Workflow Settings” menu item on the Ribbon.

13. Click “Publish” to publish the (empty) workflow.

14. After publishing click “Export to Visio” and save the file as “workflow 1 production.vwi” on the desktop.

15. Open a Windows Explorer. Select “Desktop”. You see both “.vwi” files.

16. Add the extension “.zip” to both files.

image

 

17. Open both “.vwi.zip” files. You see:

image

18. Copy “workflow.xoml.wfconfig” from “workflow 1 production.vwi.zip” to “workflow 1.vwi.zip”.

image

19. Now remove the “.zip” extension from both files. You’ll get two “.vwi” files.

image

20. In SharePoint Designer 2010 open the site “http://sharepoint.local”.

21. Click “Import from Visio” and select “workflow 1.vwi”

image

image

Click “Next”. (Maybe you get a message: “You must close all views of this workflow before importing this file.” Then stop the import. Close all views of the Workflow and restart from Step 21.)

22. Now you see the this window:

image

That it!

23. Now the workflow designer opens:

image

24. Now you can publish the workflow and test it…

25. Be as happy as me with that !!!

PS: Of course you can use any library as destination. In the sample above it does not have to be “Shared Documents” on “http://sharepoint.local” It could be another list or library as well!

SharePoint Warm Up with PowerShell

Every SharePoint farm needs a warm up Smile – After giving the IIS 7.5 Application Warmup a chance… I had to do it in another way…

I created a warmup script in PowerShell.

Here it is…

[Update 2011/08/03] New script with “timeout” capability: https://blog.kenaro.com/2011/08/03/sharepoint-warm-up-now-with-timeout/

 

$urls= @("http://sharepoint.local", "http://anothersharepoint.local")

New-EventLog -LogName "Application" -Source "SharePoint Warmup Script" -ErrorAction SilentlyContinue | Out-Null

$urls | % {
    $url = $_
    try {
        $wc = New-Object System.Net.WebClient
        $wc.Credentials = [System.Net.CredentialCache]::DefaultCredentials
        $ret = $wc.DownloadString($url)
        if( $ret.Length -gt 0 ) {
            $s = "Last run successful for url ""$($url)"": $([DateTime]::Now.ToString('yyyy.dd.MM HH:mm:ss'))" 
            $filename=((Split-Path ($MyInvocation.MyCommand.Path))+"lastrunlog.txt")
            if( Test-Path $filename -PathType Leaf ) {
                $c = Get-Content $filename
                $cl = $c -split '`n'
                $s = ((@($s) + $cl) | select -First 200)
            }
            Out-File -InputObject ($s -join "`r`n") -FilePath $filename
        }
    } catch {
          Write-EventLog -Source "SharePoint Warmup Script"  -Category 0 -ComputerName "." -EntryType Error -LogName "Application" `
            -Message "SharePoint Warmup failed for url ""$($url)""." -EventId 1001

        $s = "Last run failed for url ""$($url)"": $([DateTime]::Now.ToString('yyyy.dd.MM HH:mm:ss')) : $($_.Exception.Message)" 
        $filename=((Split-Path ($MyInvocation.MyCommand.Path))+"lastrunlog.txt")
        if( Test-Path $filename -PathType Leaf ) {
          $c = Get-Content $filename
          $cl = $c -split '`n'
          $s = ((@($s) + $cl) | select -First 200)
        }
        Out-File -InputObject ($s -join "`r`n") -FilePath $filename
    }
}

It will write a log file to the same directory as the script itself is stored.

Exceptions will be written to the event log!

Run it as “Scheduled Task” with the farm account credentials. – Check “Run with Highest Priviledges” !!!

Be sure this account can write to the scripts directory (for logging purpose)!

You can use this XML file for quick importing the scheduled task defintion. Therefore the script must be placed in the folder “C:Program FilesSharePoint Warmup”. The script itself must be named “sharepointwarmup.ps1”.

 <?xml version="1.0" encoding="utf-16"?>
 <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
   <RegistrationInfo>
     <Date>2011-01-26T00:00:37.2455395</Date>
     <Author>DOMAIN\ikarstein</Author>
   </RegistrationInfo>
   <Triggers>
     <CalendarTrigger>
       <Repetition>
         <Interval>PT5M</Interval>
         <Duration>P1D</Duration>
         <StopAtDurationEnd>false</StopAtDurationEnd>
       </Repetition>
       <StartBoundary>2011-01-26T00:00:37.2455395</StartBoundary>
       <Enabled>true</Enabled>
       <ScheduleByDay>
         <DaysInterval>1</DaysInterval>
       </ScheduleByDay>
     </CalendarTrigger>
   </Triggers>
   <Principals>
     <Principal id="Author">
       <UserId>DOMAIN\spfarm</UserId>
       <LogonType>Password</LogonType>
       <RunLevel>HighestAvailable</RunLevel>
     </Principal>
   </Principals>
   <Settings>
     <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
     <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
     <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
     <AllowHardTerminate>true</AllowHardTerminate>
     <StartWhenAvailable>false</StartWhenAvailable>
     <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
     <IdleSettings>
       <StopOnIdleEnd>true</StopOnIdleEnd>
       <RestartOnIdle>false</RestartOnIdle>
     </IdleSettings>
     <AllowStartOnDemand>true</AllowStartOnDemand>
     <Enabled>true</Enabled>
     <Hidden>false</Hidden>
     <RunOnlyIfIdle>false</RunOnlyIfIdle>
     <WakeToRun>false</WakeToRun>
     <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
     <Priority>7</Priority>
   </Settings>
   <Actions Context="Author">
     <Exec>
       <Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
       <Arguments>-command ".\SharePointWarmup.ps1"</Arguments>
       <WorkingDirectory>C:\Program Files\SharePoint Warmup</WorkingDirectory>
     </Exec>
   </Actions>
 </Task>
 

1. Copy this XML code to a file, then open the “Scheduled Tasks” management console of Windows.

2. Open the “Task Scheduler Library”, right-click on it’s node. Choose “Import”.

3. Then select the XML file.

4. In the task edit dialog: Change the execution account.

5. Save the task.

6. Now enter the password of the execution account in the credential dialog.

7. Now right-click on the created scheduled task.

8. Choose “Run” to test the task.

9. Have a look into the scripts folder in file system. there must be a file named “lastrunlog.txt” – This file will contain at most 200 lines of loggin informations!

Demo project: Excel Export feature for SharePoint 2010

I’ve uploaded another private demo project. It was planned as part of an SharePoint solution I liked to create but I cannot finalize this project. So I publish this project as “stand alone” project…. You may find it useful.

You are invited to use / develop / update the project! Every help is welcome!

You find the source code here:

http://spexcelexport.codeplex.com/

The project is ALPHA!!!

The intention of the project is to create a possibility to export SharePoint lists to "plain" Excel files. Not the kind of Excel files you can download by using the SharePoint standard functionality: With that you download a "linked" Excel file that contains a permanent connection the SharePoint. It’s a query. – With my project you’ll download a real XLSX file. – And you have the possibility to store an template file that contains formatting instructions.

It’s not finished but it works! – The test project included in the source code demonstrates the feature. Use "Test List 1". (Not "Test List 2".)

Some screenshots:

This is the “Test List 1”:

image

There is a link in the upper right. This you can use to download the Excel file:

image

When you click the link you get the well known download window:

image

Clicking “Open” will open the Excel Viewer – or the “real” Excel (that I do not have on my dev machine).

image

In Excel you can resize the “C” column.

May you have seen it: There is an error in the solution: Date values are not exported correctly. There is a gap of 1 day…

The goal is to implement a Ribbon button.

See the hidden list:

image

Have a look into the single Excel file:

image

Ok… Lots of work to do Smile

Walkthrough: Create custom SharePoint 2010 list form for deployment in a Visual Studio 2010 project – PART 2

This is part 2 of my demo project about “How to create a custom list form…” –

See this post for part one:

https://blog.kenaro.com/2010/12/29/walkthrough-create-custom-sharepoint-2010-list-form-for-deployment-in-a-visual-studio-2010-project/

Here you can download the demo project as source code:

http://spcustomlistformdemo.codeplex.com/

Let’s start…

(See “ListDefinition2” in the demo project source!)

1. Create an new List Definition project item as described in the previous blog post (“Part 1”).

2. In the ASPX file of your list form be sure to add the attribute UseLegacyForm=”True” to your Form-Tag. – Like in this screenshot:

image

3. Then you need to create the field edit controls by yourself. Therefore you have to add some code to the ASPX file.

Here is some demo code. (The “ListDefinition2” based upon “Announcement List Template”…)

1:                 <WebPartPages:WebPartZone  runat="server"  FrameType="None"  ID="Main"  Title="loc:Main" 
2:                     Visible="true"> 
3:                     <ZoneTemplate> 
4:                     </ZoneTemplate> 
5:                 </WebPartPages:WebPartZone> 
6: 
7:                 <!-- ikarstein: Insert such a structure for each field you want to show on you page --> 
8:                 <table  border="0"  width="100%"> 
9:                     <tr> 
10:                         <td  class="ms-toolbar"  nowrap="nowrap"> 
11:                             <SharePoint:FormToolBar  runat="server"  ControlMode="New"  /> 
12:                         </td> 
13:                     </tr> 
14:                     <tr> 
15:                         <td> 
16:                             <span  id="part1">  <!-- ikarstein: This line is important for "Attachments" --> 
17:                                 <table  border="0"  cellspacing="0"  width="100%"> 
18:                                     <!-- ikarstein: Insert such a table row for each field / BEGIN--> 
19:                                     <tr> 
20:                                         <td  width="190px"  valign="top"  class="ms-formlabel"> 
21:                                             <h3  class="ms-standardheader"> 
22:                                                 <nobr> Title<span  class="ms-formvalidation">  *</span></nobr> 
23:                                             </h3> 
24:                                         </td> 
25:                                         <td  width="400px"  valign="top"  class="ms-formbody"> 
26:                                             <SharePoint:FormField  runat="server"  ID="field_Title"  ControlMode="New"  FieldName="Title"  /> 
27:                                             <SharePoint:FieldDescription  runat="server"  ID="field_Title_Description"  FieldName="Title" 
28:                                                 ControlMode="New"  /> 
29:                                         </td> 
30:                                     </tr> 
31:                                     <!-- karstein: END --> 
32:                                     <tr> 
33:                                         <td  width="190px"  valign="top"  class="ms-formlabel"> 
34:                                             <h3  class="ms-standardheader"> 
35:                                                 <nobr> Body</nobr> 
36:                                             </h3> 
37:                                         </td> 
38:                                         <td  width="400px"  valign="top"  class="ms-formbody"> 
39:                                             <SharePoint:FormField  runat="server"  ID="field_Body"  ControlMode="New"  FieldName="Body"  /> 
40:                                             <SharePoint:FieldDescription  runat="server"  ID="field_Body_Description"  FieldName="Body" 
41:                                                 ControlMode="New"  /> 
42:                                         </td> 
43:                                     </tr> 
44:                                     <tr> 
45:                                         <td  width="190px"  valign="top"  class="ms-formlabel"> 
46:                                             <h3  class="ms-standardheader"> 
47:                                                 <nobr> Expires</nobr> 
48:                                             </h3> 
49:                                         </td> 
50:                                         <td  width="400px"  valign="top"  class="ms-formbody"> 
51:                                             <SharePoint:FormField  runat="server"  ID="field_Expires"  ControlMode="New"  FieldName="Expires"  /> 
52:                                             <SharePoint:FieldDescription  runat="server"  ID="field_Expires_Description"  FieldName="Expires" 
53:                                                 ControlMode="New"  /> 
54:                                         </td> 
55:                                     </tr> 
56:                                     <!-- ikarstein: optionally add this table row / BEGIN --> 
57:                                     <tr  id="idAttachmentsRow"> 
58:                                         <td  nowrap="true"  valign="top"  class="ms-formlabel"  width="20%"> 
59:                                             <SharePoint:FieldLabel  ControlMode="New"  FieldName="Attachments"  runat="server"  /> 
60:                                         </td> 
61:                                         <td  valign="top"  class="ms-formbody"  width="80%"> 
62:                                             <SharePoint:FormField  runat="server"  ID="AttachmentsField"  ControlMode="New"  FieldName="Attachments"  /> 
63:                                             <script  language="javascript"  type="text/javascript"> 
64:                                               var  elm = document.getElementById("idAttachmentsTable" );
65:                                               if  (elm == null  || elm.rows.length == 0)
66:                                                 document.getElementById("idAttachmentsRow" ).style.display=< span> ;
67:                                             </script> 
68:                                         </td> 
69:                                     </tr> 
70:                                     <!-- ikarstein: END --> 
71: 
72:                                     <!-- ikarstein: Add this table for "Save" and "Cancel" buttons / BEGIN --> 
73:                                     <table  width="100%"  border="0"  cellspacing="0"> 
74:                                         <tr> 
75:                                             <td  width="99%"  class="ms-toolbar"  nowrap="nowrap"> 
76:                                                 <img  src="/_layouts/images/blank.gif"  width="1"  height="18"  /> 
77:                                             </td> 
78:                                             <td  class="ms-toolbar"  nowrap="nowrap"> 
79:                                                 <SharePoint:SaveButton  runat="server"  ControlMode="New"  ID="savebutton"  /> 
80:                                             </td> 
81:                                             <td  class="ms-separator"> 
82:                                             </td> 
83:                                             <td  class="ms-toolbar"  nowrap="nowrap"  align="right"> 
84:                                                 <SharePoint:GoBackButton  runat="server"  ControlMode="New"  ID="gobackbutton"  /> 
85:                                             </td> 
86:                                         </tr> 
87:                                     </table> 
88:                                     <!-- ikarstein: END --> 
89:                             </span> 
90:                             <SharePoint:AttachmentUpload  runat="server"  ControlMode="New"  /> 
91:                             <SharePoint:ItemHiddenVersion  runat="server"  ControlMode="New"  /> 
92:                         </td> 
93:                     </tr> 
94:                 </table> 
95: 
96: 

(You see my comments inline ?! Not much, I know…)

Behind  the “<WebPartZone>” tag add the HTML code.

You can add input fields by using this snipped:

1:                                     <!-- ikarstein: Insert such a table row for each field / BEGIN--> 
2:                                     <tr> 
3:                                         <td  width="190px"  valign="top"  class="ms-formlabel"> 
4:                                             <h3  class="ms-standardheader"> 
5:                                                 <nobr> Title<span  class="ms-formvalidation">  *</span></nobr> 
6:                                             </h3> 
7:                                         </td> 
8:                                         <td  width="400px"  valign="top"  class="ms-formbody"> 
9:                                             <SharePoint:FormField  runat="server"  ID="field_Title"  ControlMode="New"  FieldName="Title"  /> 
10:                                             <SharePoint:FieldDescription  runat="server"  ID="field_Title_Description"  FieldName="Title" 
11:                                                 ControlMode="New"  /> 
12:                                         </td> 
13:                                     </tr> 
14:                                     <!-- karstein: END -->
15: 

Of course you can change the page design. You only need the tag “<SharePoint:FormField>”, optionally “<SharePoint:FieldDescription>”. In every case the “FieldName” Attribute represents the List field the input field is connected with.

You do not need to create any Code Behind!

Just add "<SharePoint:GoBackupButton>” for cancel and “<SharePoint:SaveButton>” for submit.

Furthermore you have some controls for adding attachments to your List item.

AND: It’s the same for “Edit” list form. You only need to change the attributes “ControlMode” to “Edit”… Totally easy, isn’t it?

4. Deploy it and have a look…

Error while executing the SharePoint 2010 PowerShell cmdlet Mount-SPContentDatabase: “Exception of type ‘Microsoft.SharePoint.Upgrade.SPUpgradeException’ was thrown.”

Mount-SPContentDatabase : Exception of type 'Microsoft.SharePoint.Upgrade.SPUpgradeException' was thrown.
At D:TempAttach_OldContentDBs_DoIt.ps1:63 char:28
+              Mount-SPContentDatabase <<<<  -WebApplication $webapp -Name $thisdb
    + CategoryInfo          : InvalidData: (Microsoft.Share...ContentDatabase:SPCmdletMountContentDatabase) [Mount-SPContentDatabase], SPUpg
   radeException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletMountContentDatabase

Have a look into the SQL Server Management Studio. – The content database is read only. That’s the problem Smile