Archives for category: SharePoint 2010

I recently created a custom error pages feature that was scoped to “WebApplication”. I ran the STSADM “addsolution” command then went to Central Administration -> System Settings -> Manage farm solutions -> mySolution.wsp -> Deploy Solution. I noticed that the “Deploy To?” value was set to “This solution deploys globally.” and no configurable options were given. In order to get a list of web application options in the “Deploy To?” setting, I had to add a SafeControl to the package manifest of the solution, in Visual Studio. It was a really simple fix. Here is what I did:

  1. Open your solution in Visual Studio
  2. Solution Explorer -> Package -> (double click) Package.package
  3. Click the “Manifest” button near the bottom of the Package.package window
  4. Click the “+” button next to “Edit Options” to expand the manifest template area
  5. Click the “(Open in XML Editor)” link
  6. Here is what my Package.Template.xml contained before modifications:
    <?xml version=”1.0″ encoding=”utf-8″?>
    <Solution xmlns=””>
  7. Here is what my Package.Template.xml contained after modifying and saving (be sure to change “mySolution.dll“):
    <?xml version=”1.0″ encoding=”utf-8″?>
    <Solution xmlns=””>
    <Assembly Location=”mySolution.dll” DeploymentTarget=”GlobalAssemblyCache”>
    <SafeControl Assembly=”$SharePoint.Project.AssemblyFullName$”
    Namespace=”$SharePoint.Project.FileNameWithoutExtension$” TypeName=”*” Safe=”True”></SafeControl>
  8. Then I did a rebuilt the solution (not sure that it was necessary) and I repackaged the solution. This updates the .wsp file.
  9. Make sure the existing “mySolution.wsp” is removed from Central Administration’s farm solutions gallery.
  10. Run the STSADM “addsolution” command for the updated .wsp file
  11. Central Administration -> System Settings -> Manage farm solutions -> mySolution.wsp -> Deploy Solution
  12. In the “Deploy To?” setting, you should now see “Choose a Web application to deploy this solution:” along with a drop down list of web applications to choose from



I’m using SharePoint 2010. Open the “SharePoint 2010 Management Shell” application. Start -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Management Shell. Then enter the following commands:

$web = Get-SPWeb http://MySiteUrl/MySubsiteUrlIfNecessary

$list = $web.lists[“My List Title”]

$list.AllowDeletion = $true




$list.Dispose() does not work for me, but I saw it in an example, so I do it just for good measure.

I was getting an “Property ‘AllowDeletion’ cannot be found on this object; make sure it exists and is settable.” error when I tried $list.AllowDeletion = $true. That was because the list title I used did not exist in the $web that I specified.

In this post, I will show you how to deploy a Web Part Page with content added to the page, specifically a custom Visual Web Part. This method should work for other web parts, including out of the box SharePoint Web Parts. This post focuses on how to provision the Web Part on a page, it does not explain how to create the Web Part.

Here is a view of the Object Explorer window:


Here is the code for MyWebPartPage.aspx:

<%@ Assembly Name=”$SharePoint.Project.AssemblyFullName$” %>
<%@ Import Namespace=”Microsoft.SharePoint.ApplicationPages” %>
<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”Utilities” Namespace=”Microsoft.SharePoint.Utilities” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”asp” Namespace=”System.Web.UI” Assembly=”System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ %>
<%@ Import Namespace=”Microsoft.SharePoint” %>
<%@ Assembly Name=”Microsoft.Web.CommandUI, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”WebPartPages” Namespace=”Microsoft.SharePoint.WebPartPages” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”MyWebPartPage.aspx.cs” Inherits=”DeployWebPartOnPage.MyWebPartPage.MyWebPartPage” MasterPageFile=”~masterurl/default.master” %>

<asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>
<WebPartPages:WebPartZone runat=”server” ID=”wpzMyZone”>

Here is the code for MyWebPartPage.aspx.cs:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace DeployWebPartOnPage.MyWebPartPage
public partial class MyWebPartPage : WebPartPage
protected void Page_Load(object sender, EventArgs e)

Here is the code for Elements.xml:

    <?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”; >
<Module Name=”MyWebPartPage” Url=”SitePages”>
<File Path=”MyWebPartPage\MyWebPartPage.aspx” Url=”MyWebPartPage.aspx”
Type=”GhostableInLibrary” IgnoreIfAlreadyExists=”FALSE”>
<AllUsersWebPart WebPartOrder =”0″ WebPartZoneID =”wpzMyZone”>
<?xml version=”1.0″ encoding=”utf-8″?>
<webPart xmlns=”″&gt;
<type name=”DeployWebPartOnPage.HelloWorldWP.HelloWorldWP, DeployWebPartOnPage,
Version=, Culture=neutral, PublicKeyToken=00a467d3ecefd6d1″ />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
<property name=”Title” type=”string”>HelloWorldWP</property>
<property name=”Description” type=”string”>HelloWorldWP Description</property>

The only issues that i ran into while deploying this are that i forgot to modify the feature to include the Web Part Page and i did not have the correct assembly info in Elements.xml. I was unable to add the .aspx file directly to the MyWebPartPage module so i had to drag and drop it where i wanted within the Object Explorer window. Then when i deployed i was getting a “cannot find/deploy web part” sort of a message. That is because i had not corrected the namespace value of the Web Part Page after the drag and drop.

In this exercise we will create a custom list with 3 custom columns: FirstApprover, LastApprover, and PercentCompleted. Then we will create a workflow that creates items in the Task list for FirstApprover and LastApprover. The workflow will contain a while loop that keeps assigning a new Task item for LastApprover until he sets the custom lists PercentCompleted column to 100%. Let’s begin…

Start by creating a custom list named “myList” in your SP 2010 site. Leave the default “Title” column, and add the following 3 columns:

  • FirstApprover (Person or Group)
  • LastApprover (Person or Group)
  • PercentCompleted (Number, Number of decimal places: 0, Default value: 0, Show as percentage: checked)
  1. Open SharePoint Designer 2010 (SPD), click “Open Site”, type the URL of the site collection that you just added myList to, click the “Open” button
  2. Within the Site Objects area, click “Workflows”
  3. Click the “List Workflow” icon located near the top left of the SPD window, then select “myList” from the drop down menu that appears
  4. Enter “myWorkflow” in the “Name” textbox, and click the “OK” button
  5. At this point, SPD creates a “Step 1” by default and places the blinking horizontal orange cursor within that step, then click the “Action” icon, the select “Assign a To-do Item” from the drop down menu as shown below
  6. WfWhileLoop01
  7. Click the “a to-do item” link, then click the “Next” button on the popup window.
  8. WfWhileLoop02
  9. Enter the name, description, and then click “Finish”
  10. WfWhileLoop03
  11. Click the “these users” link, then select “Workflow Lookup for a User”, then click the “Add >>” button
  12. WfWhileLoop04
  13. Select the data source, field from source, return field as, and then click “OK” as shown below
  14. WfWhileLoop05
  15. Click the “OK” button
  16. WfWhileLoop06
  17. Click below Step 1 to position the orange cursor, then click the “Step” icon
  18. WfWhileLoop07
  19. Click within Step 2 to position the orange cursor, then click the “Action” icon, then select “Assign a To-do Item” from the drop down menu as shown below
  20. WfWhileLoop08
  21. Repeat the directions for steps 6 through 10, but enter a different name as shown below
  22. WfWhileLoop09
  23. Repeat the directions from steps 11 through 16, but select a different “Field from source” value as shown below
  24. WfWhileLoop10
  25. Repeat the direction from step 17 and 18 in order to create Step 3
  26. Click within Step 3 to position the orange cursor, then click the “Condition” icon
  27. WfWhileLoop11
  28. Select “If current item field equals value” from the condition drop down
  29. WfWhileLoop12
  30. Click on the 3 links and…
  31. WfWhileLoop13
  32. …select the values as shown below
  33. WfWhileLoop14
  34. Click within the area as shown below by “1”, then add a step by clicking the “Step” icon as show below by “2”
  35. WfWhileLoop15
  36. Click on “Step 4” and change the text to “While Statement” as shown below
  37. WfWhileLoop16
  38. Click inside the “While Statement” step to position the oragne cursor, then click the “Action” icon
  39. WfWhileLoop17
  40. Select “Assign a To-do Item” from the Action drop down list
  41. WfWhileLoop18
  42. Repeat steps 21 through 24 to set the values for “a to-do item” and “these users”, but use a different name and description as shown in the second picture below (NOTE THAT “1.00” IS USED INSTEAD OF 100% BECAUSE THAT IS NOW SHAREPOINT HANDLES NUMBER PERCENTAGES)
  43. WfWhileLoop19
  44. WfWhileLoop20
  45. Confirm that your workflow design looks the same as pictured below, then right click the “myWorkflow” tab and select “Save”. EDIT: I believe there is a typo in the screen shot below. “LastAction” should be changed to “LastApprover”.
  46. WfWhileLoop21
  47. Click “All Files” in the Site Objects area on the left of the screen, then “Workflows”, then “myWorkflow”, then right click “myWorkflow.xoml”, then “Open With, then “Notepad”
  48. WfWhileLoop22
  49. Scroll down to the end of the file and change the code in the first picture below to look like the code in the second picture below
  50. WfWhileLoop23
  51. WfWhileLoop24
  52. Select “File” from the top menu bar, then select “Save” from the drop down menu
  53. WfWhileLoop25
  54. Close the Notepad window and return to SharePoint Designer (you should be back at the “myWorkflow” folder tab)
  55. Click the “myWorkflow.xoml” link to open the “myWorkflow” tab as shown below.
  56. Ensure that the values are set as shown below, then click the “Save” button in the top left corner of the SPD window, then click the “Save” icon
  57. WfWhileLoop26A
  58. Due to the manual changes that we made in Notepad, you will be prompted, so click the “No” buttton
  59. WfWhileLoop27
  60. Click the “Publish” icon as shown below
  61. WfWhileLoop26B

EDIT: Thanks to Vincent Seckel for identifying the following omission. You must modify the web.config file of the target SharePoint application since the while activity is disabled by default. Locate the following line of code in the web.config file and change Authorized=”False” to Authorized=”True”:

<authorizedType Assembly=”System.Workflow.Activities, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ Namespace=”System.Workflow.*” TypeName=”WhileActivity” Authorized=”True” />

That’s it! You should now have a workflow with a while loop attached to myList. The workflow should start automatically when a new item is added to myList. Let’s confirm that it is working…

Add a new item to myList. Be sure to set the FirstApprover and LastApprover fields. Also, set the PercentCompleted value to zero.

Browse to your the Task list. You should see a task item assigned to the person that you selected for FirstApprover. Go ahead and edit the task item. Click the “Complete Task” button and the workflow will move to the next workflow step.

Refresh the page to see the new task item that has been assigned to the person you designated as LastApprover. Edit the task item and click the “Complete Task” button.

Refresh the page again and you will see that another task has been assigned to the person that you designated as LastApprover. This is because you did not update the myList item and set PercentCompleted column to 100%.

Go ahead and update the myList item and set PercentCompleted to 100%. Go back to the Task list and edit the task item and click the “Complete Task” button. You should not see any more tasks assigned for this workflow because you met the condition to end the workflow while loop.

If you return to myList, you should see that the “myWorkflow” column is marked as “Completed”.

You can modify the attributes, listed below, within the “Solution Explorer” window of Visual Studio by expanding the “Features” folder and double clicking the name of the feature. Use the “Properties” window to modify the attributes.

  • Auto Activate On Default – “True” by default.
  • Always Force Install – “False” by default.
  • Auto Activate In Central Administration – “False” by default.
  • Creator –
  • Default Resource File –
  • Deployment Path – C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES
  • Description –
  • Feature Id – A new, unique GUID by default.
  • Image Alt Text –
  • Image Url – The file path to the image that you would like the feature to use within the Features Gallery in your website. (click her for details)
  • Is Hidden – “False” by default.
  • Receiver Assembly –
  • Receiver Class –
  • Required Resources – “False” by default.
  • Scope – Specifies at which level the feature will be deployed. “Site” by default.
    • Farm – Activates a feature for an entire server farm.
    • Site – Activates a feature for all web sites in a site collection.
    • Web – Activates a feature for a specific web site.
    • WebApplication – Activates a feature for all web sites in a web application.
  • Solution Id – “00000000-0000-0000-0000-000000000000” by default.
  • Title – The name of the project, followed by a space character, and then “Feature1”. Default value.
  • UIVersion –
  • Upgrade Actions Receiver Assembly –
  • Upgrade Actions Receiver Class –
  • Version –