SharePoint: RegistrationId List Template Type IDs

Reference: http://techtrainingnotes.blogspot.com.au/2008/01/sharepoint-registrationid-list-template.html

Below is a list of RegistrationIDs for use with API code and CustomAction Features (for user created list types) and any other list types I have found.

In this article you will find:

  • A table of all of the codes I have found.
  • A C# routine to dump the standard enumeration of SPListTemplateTypes.
  • A PowerShell script to dump the standard enumeration of SPListTemplateTypes.

For more info on CustomAction see: http://msdn.microsoft.com/en-us/library/ms460194.aspx

For a list of the CustomActions Rights values see: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx

 

The Table

“ “ = WSS 3.0, “M” = MOSS 2007 only list type, “E” = MOSS 2007 Enterprise, 2010 = 2010!

0 = list, 1 = library, (4 used for surveys only???)

Fourth column contains notes, names as displayed in SharePoint or in the SQL content database and best guesses 😉

“not in SPListTemplateType”: Most, but not all of the IDs are in an API enumeration named SPListTemplateType

-1 InvalidType (not used)
100 GenericList 0 (see note below)
Also used for “Import Spreadsheet”
Also: (and I’m sure more…)
Relationships List
Reusable Content
Quick Deploy Items
Variation Labels
Long Running Operation Status
Notification List
Reporting Metadata
Cache Profiles
Content and Structure Reports
Reporting Metadata
Suggested Content Browser Locations

From Central Admin:
Content Deployment Jobs
Content Deployment Paths

From Central Admin 2010:
Job Reports
Reporting Metadata

101 DocumentLibrary 1 all kinds of libraries:

From 2010:
cache
Customized Reports
Form Templates
Reporting Templates
Shared Documents
Site Assets
Style Library

102 Survey 4
103 Links 0
104 Announcements 0
105 Contacts 0
106 Events 0 Calendar
107 Tasks 0 Task lists in general, including “Workflow tasks”
108 DiscussionBoard 0 Example: “Team Discussion”
109 PictureLibrary 1
110 DataSources 1 (fpdatasources = FrontPage Data Sources???)
111 WebTemplateCatalog 1 “Site Template Gallery”
112 UserInformation 0 “User Information List” (all people)
113 WebPartCatalog 1 “Web Part Gallery”
114 ListTemplateCatalog 1 “List Template Gallery”
115 XMLForm 1 “Form Library” InfoPath Forms Library
116 MasterPageCatalog 1 “Master Page Gallery”
117 NoCodeWorkflows 1 “Workflows”
118 WorkflowProcess
119 WebPageLibrary 1 “Wiki Library” (also “Site Pages” in 2010)
120 CustomGrid 0 “Custom List in Datasheet View”
121 SolutionCatalog 0 2010 “Solution Gallery”
122 NoCodePublic 0 2010 No Code Public Workflows
123 ThemeCatalog 0 2010 “Theme Gallery”
124 DesignCatalog 2013
125 AppDataCatalog 2013
130 DataConnectionLibrary 1 M “Data Connection Library”
140 WorkflowHistory 0 “Workflow History”  (“Macros” in 2010’s CharitableContributions template)
150 GanttTasks 0 “Project Tasks” task list
151 HelpLibrary Product Help (Central Admin only?)
160 AccessRequest 0 2013
171 TasksWithTimelineAndHierarchy 0 2013
175 MaintenanceLogs 2013
200 Meetings 0 Meeting templates – “Meeting Series”
201 Agenda 0 Meeting templates – “Agenda”
202 MeetingUser 0 Meeting templates – “Attendees”
204 Decision Meeting templates
207 MeetingObjective 0 Meeting templates – “Objectives”
210 TextBox 0 Meeting templates – “Directions” (“Use this list to insert custom text into your meeting.”)
211 ThingsToBring 0 Meeting templates – “Things To Bring”
212 HomePageLibrary 1 Meeting templates – “Workspace Pages”
300 Sites 0 M Sites list in Publishing templates (not in SPListTemplateType)
301 Posts 0 Used in blogs (also appears to be used for Search tabs)
302 Comments 0 Used in blogs
303 Categories 0 Used in blogs
398 0 2010 Access Services Application Log
399 0 2010 Access Services System Objects
402 Facility 0 2010 Resources
“Use the Resources list to document shared assets, such as cameras and vehicles. Users can reserve and track listed resources in Group Calendar.” (used in the new Group Work Site template)
403 Whereabouts 0 2010 Whereabouts
“Use this list to quickly and easily track the location of individuals throughout the day.” (used in the new Group Work Site template)
404 CallTrack 0 2010 Phone Call Memo
(used in the new Group Work Site template)
405 Circulation 0 2010 Circulations
“Use this list to inform team members and request confirmation stamps.”  (used in the new Group Work Site template)
420 Timecard 0 2010
421 Holidays 0 2010
432 0 E “Sample KPIs” (not in SPListTemplateType)
433 1 E “Reports Library”(not in SPListTemplateType)
434 1 E “Reference Library”(not in SPListTemplateType)
499 IMEDic 0 2010 IME Dictionary (Input Method Editor: http://office.microsoft.com/en-us/powerpoint/HP030900551033.aspx)
544 2013 Micro Feed / Published Feed (also 2010?)
600 ExternalList 0 2010 External List
700 MySiteDocumentLibrary 2013
850 Pages 1 M Used with publishing templates
(thanks to Anders Jacobsen for this one) (not in SPListTemplateType)
851 1 M, 2010 “Images”, “Site Collection Images”  “This system library was created by the Publishing feature to store images that are used on pages in this site.” (not in SPListTemplateType)  Also: “Asset Libary” in 2010
1100 IssueTracking 0 “Issue Tracking” task list
1200 AdminTasks 0 used in Central Administration
1220 HealthRules 0 2010 used in Central Administration
1221 HealthReports 0 2010 used in Central Administration
1230 DeveloperSiteDraftApps 1 2013 Draft Apps library in Developer Site
1300 Translation Management Library 1 M (thanks to Dennis for this one) (not in SPListTemplateType)
1301 Languages & Translations 0 M “Translators” Created with a 1300
(thanks to Dennis for this one) (not in SPListTemplateType)
2100 1 M PowerPoint Slide Library (not in SPListTemplateType)
10102 Converted Forms 1 “List of user browser-enabled form templates on this site collection” (not in SPListTemplateType)

 

Note: 100 is used for any custom listed create from Site Actions -> Create -> Custom List. If you created and deployed the custom lists using a SharePoint Feature then the RegistrationID is the same as the list “Type” ID you used in your list’s feature manifest file. Here is some more info: http://sharepointinsight.com/blog/Lists/Posts/Post.aspx?ID=33 Please let me know if there are more IDs for this list? For example: 203?

 

Want to see the IDs used in your site collection?

Note that direct queries of the SharePoint content databases is never a good practice and my invalidate your support agreements! Try the following only on a test or dev server.

USE WSS_Content (database for your application)
SELECT tp_Title, tp_BaseType, tp_ServerTemplate, tp_Description
FROM AllLists
ORDER BY tp_ServerTemplate, tp_Title

 

Want to see all of the IDs listed in the API enumerations using C#?

Create a Console Application and set a reference to Microsoft.SharePoint for your version (12, 14, etc).

using System;
using Microsoft.SharePoint;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      int i = 0;
      foreach (string enumName in Enum.GetNames(typeof(SPListTemplateType)))
      {
        i++;
        Console.Write(i);
        Console.Write(String.Format(": {0,-23} ", enumName));
        Console.Write((int)(Enum.Parse(typeof(SPListTemplateType), enumName)));
        Console.WriteLine();
      }
      Console.ReadLine();

    }
  }
}

 

Want to see all of the IDs listed in the API enumerations using PowerShell?

PS C:\> $SPtt = [Microsoft.SharePoint.SPListTemplateType]
PS C:\> [System.Enum]::GetNames($SPtt) |  select {[int][System.Enum]::Parse($SPtt, $_)}, {$_} 

.

Posted in SharePoint 2010, Visual Studio 2010 | Leave a comment

Create Custom Ribbon Actions in Visual Studio

This example creates an “Email to Someone” custom action in the Ribbon of lists and libraries.

emailtosomeone

  1. Create a new SharePoint empty project (Sandbox solution);
  2. Add a new item >> Empty Element;
  3. Sample code for Elements.xml
    <?xml version=”1.0″ encoding=”utf-8″ ?>
    <Elements xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
    <CustomAction
    Id=”CAAlertRibbonButton”
    RegistrationId=”100″
    RegistrationType=”List”
    Location=”CommandUI.Ribbon.ListView”
    Sequence=”5″
    Title=”Alert Ribbon Button”>
    <CommandUIExtension>
    <CommandUIDefinitions>
    <CommandUIDefinition
    Location=”Ribbon.ListItem.Groups._children”>
    <Group
    Id=”MiTek.ListItem”
    Sequence=”80″
    Description=”MiTek group”
    Title=”MiTek Custom”
    Template=”Ribbon.Templates.Flexible2″>
    <Controls Id=”MiTek.SharePoint.Administration.Application.Group.Controls”>
    <Button
    Id=”MiTek.Ribbon.ListItem.EmailSomeone”
    Command=”CMDRibbonButton”
    Image32by32=”/Style%20Library/Custom%20Images/emailIcon.png”
    LabelText=”Email To Someone”
    TemplateAlias=”o2″
    Sequence=”20″ />
    </Controls>
    </Group>
    </CommandUIDefinition>
    <CommandUIDefinition
    Location=”Ribbon.ListItem.Scaling._children”>
    <MaxSize
    Id=”MiTek.Ribbon.ListItem.MaxSize”
    Sequence=”15″
    GroupId=”MiTek.ListItem”
    Size=”LargeLarge” />
    </CommandUIDefinition>
    <!– Put in the Actions Group –>
    <!–CommandUIDefinition Location=”Ribbon.ListItem.Actions.Controls._children”>
    <Button
    Id=”Ribbon.ListItem.Actions.Controls.EmailButton”
    Alt=”Alert Ribbon Button”
    Sequence=”5″
    Command=”CMDAlertRibbonButton”
    Image32by32=”/_layouts/images/menulistsettings.gif”
    Image16by16=”/_layouts/images/itdcl.gif”
    LabelText=”Email To Someone”
    TemplateAlias=”o1″ />
    </CommandUIDefinition–>
    </CommandUIDefinitions>
    <CommandUIHandlers>
    <CommandUIHandler
    Command=”CMDRibbonButton”
    CommandAction=”javascript:
    function resultCallback(result, value)
    {
    SP.UI.Notify.addNotification(‘Success!’);
    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
    }var ctx = SP.ClientContext.get_current();
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var myItems = ”;
    var i;for (i in items)
    {
    myItems += ‘|’ + items[i].id;
    }

    if(myItems != ”)
    {
    var options = {
    url: ‘{SiteUrl}/Pages/Page-to-Test-List.aspx?Items=’ + myItems + ‘&amp;ListType=100&amp;ListId={SelectedListId}&amp;Source={Source}’,
    tite: ‘My Page’,
    allowMaximize: false,
    showClose: true,
    width: 500,
    height: 500,
    dialogReturnValueCallback: resultCallback };

    SP.UI.ModalDialog.showModalDialog(options);
    } else {
    alert(‘Please select at lease one item’);
    }

    ” />
    </CommandUIHandlers>
    </CommandUIExtension>
    </CustomAction>

    <CustomAction
    Id=”CAAlertRibbonButton”
    RegistrationId=”101″
    RegistrationType=”List”
    Location=”CommandUI.Ribbon”
    Sequence=”5″
    Title=”Alert Ribbon Button”>
    <CommandUIExtension>
    <CommandUIDefinitions>
    <CommandUIDefinition
    Location=”Ribbon.Documents.Groups._children”>
    <Group
    Id=”MiTek.Documents”
    Sequence=”80″
    Description=”MiTek group”
    Title=”MiTek Custom”
    Template=”Ribbon.Templates.Flexible2″>
    <Controls Id=”MiTek.SharePoint.Administration.Application.Group.Controls”>
    <Button
    Id=”MiTek.Ribbon.Documents.EmailSomeone”
    Command=”CMDRibbonButton”
    Image32by32=”/Style%20Library/Custom%20Images/emailIcon.png”
    LabelText=”Email To Someone”
    TemplateAlias=”o2″
    Sequence=”20″ />
    </Controls>
    </Group>
    </CommandUIDefinition>
    <CommandUIDefinition
    Location=”Ribbon.Documents.Scaling._children”>
    <MaxSize
    Id=”MiTek.Ribbon.Documents.MaxSize”
    Sequence=”15″
    GroupId=”MiTek.Documents”
    Size=”LargeLarge” />
    </CommandUIDefinition>
    <!– Put in the Actions Group –>
    <!–CommandUIDefinition Location=”Ribbon.ListItem.Actions.Controls._children”>
    <Button
    Id=”Ribbon.ListItem.Actions.Controls.EmailButton”
    Alt=”Alert Ribbon Button”
    Sequence=”5″
    Command=”CMDAlertRibbonButton”
    Image32by32=”/_layouts/images/menulistsettings.gif”
    Image16by16=”/_layouts/images/itdcl.gif”
    LabelText=”Email To Someone”
    TemplateAlias=”o1″ />
    </CommandUIDefinition–>
    </CommandUIDefinitions>
    <CommandUIHandlers>
    <CommandUIHandler
    Command=”CMDRibbonButton”
    CommandAction=”javascript:
    function resultCallback(result, value)
    {
    SP.UI.Notify.addNotification(‘Success!’);
    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
    }

    var ctx = SP.ClientContext.get_current();
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var myItems = ”;
    var i;

    for (i in items)
    {
    myItems += ‘|’ + items[i].id;
    }

    if(myItems != ”)
    {
    var options = {
    url: ‘{SiteUrl}/Pages/Page-to-Test-List.aspx?Items=’ + myItems + ‘&amp;ListType=101&amp;ListId={SelectedListId}&amp;Source={Source}’,
    tite: ‘My Page’,
    allowMaximize: false,
    showClose: true,
    width: 500,
    height: 500,
    dialogReturnValueCallback: resultCallback };

    SP.UI.ModalDialog.showModalDialog(options);
    } else {
    alert(‘Please select at lease one item’);
    }

    ” />
    </CommandUIHandlers>
    </CommandUIExtension>
    </CustomAction>

    </Elements>

  4. Deploy the project
Posted in SharePoint 2010, Visual Studio 2010 | Leave a comment

SPUtility.SendEmail adds spaces and new lines to email body

Problem:

When using SPUtility.SendEmail  to send emails, sometimes it adds spaces and new lines to the email body automatically, or sometimes it even removes some characters, or change < to <.

Solution:

Add “\n” at the end of each paragraph or at the end of each row of your HTML table.

For example:

string emailBody = "<div>Hello,<br /><br />Just letting you know that the CityLink invoice/travel details have been reviewed by all the e-Tag holders.<br /><br />\n";
emailBody += "This is the library and you can view the workflow details here:<br /><br />\n";
emailBody += "<table><tr><th>Name</th><th>ID</th><th>Details</th><th>Date</th></tr>\n";

Posted in SharePoint 2010, Visual Studio 2010 | Leave a comment

Create SharePoint Sequential Workflow with multiple tasks in Visual Studio 2010

What I wanted to Achieve:

  1. CityLink sends us an invoice (along with a csv file for travel details) every month. Before we made the payment, we need all e-Tag holders to review their travel details in the invoice and make sure they are correct.
  2. User uploads the TravelDetails.csv file into a document library.
  3. It triggers the workflow and creates tasks for e-Tag holders to review their travel details (These people are listed in a list called “e-Tag Holders”. This list contains people’s names in the TravelDetails.csv file and their corresponding user account in SharePoint)
  4. The workflow reads all the lines in the csv file and send diffrent part of the travel details to diffrent people via Emails. It also creates task for them so after they have reviewed their part of travel details, they can mark the task as complete.
  5. Once all tasks have been completed, it sends an email to a SharePoint group “CityLink Invoice Notification” telling them it is completed.

How I achived it:

Create a new project:

vswf1

Drag activities into the designer and it looks like this:

2015-09-18 10_50_10-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

This is the properties of onWorkflowActivated1:

2015-09-18 10_52_56-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

Properties of replicatorActivity1:

2015-09-18 10_55_53-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

Properties of createTask1:

2015-09-18 10_58_22-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

When binding the ListItemId, TaskId and TaskProperties, click the little … button on the right, and then click “Bind to a new member”, select “Create Field”:

2015-09-18 12_10_38-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

Properties of onTaskCreated1 (This activity does nothing, but deleting it made my workflow not working for some unknown reason):

2015-09-18 10_59_07-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

CodeAcitivity1:

2015-09-18 11_00_35-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

whileActivity1:

2015-09-18 11_01_52-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

onTaskChanged1:

2015-09-18 11_02_58-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

completeTask1:

2015-09-18 11_04_16-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

codeActivity2:

2015-09-18 11_05_09-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

Code Behind:

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using System.Text;
using System.IO;
using System.Data;
using Microsoft.SharePoint.Utilities;
using System.Collections.Specialized;

namespace Workflow_CityLink_Invoices.Workflow1
{
public sealed partial class Workflow1 : SequentialWorkflowActivity
{
public Workflow1()
{
InitializeComponent();
}

public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
int countTask = 0;
int countCompletedTask = 0;
int counter = 0;

string invoicePeriod = “”;

ArrayList assignees = null;
DataTable dtInvoice = new DataTable();
DataTable dtETagHolders = new DataTable();

public Guid createTask1_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties createTask1_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public String taskOutcome = default(System.String);
private bool isFinished = false;

public Int32 createTask1_ListItemId1 = default(System.Int32);

private void LogComment(string logMessage, string outcome)
{
SPWorkflow.CreateHistoryEvent(workflowProperties.Web, this.WorkflowInstanceId, 0, workflowProperties.Web.CurrentUser, new TimeSpan(), outcome, logMessage, string.Empty);
}

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
// Initialisation
countTask = 0;
countCompletedTask = 0;
counter = 0;
workflowId = Guid.NewGuid();

dtInvoice.Columns.Add(“Name”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“LicencePlate”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“eTag”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“TravelDetails”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“StartDate”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“StartTime”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“FinishDate”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“FinishTime”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“GST”, Type.GetType(“System.String”));
dtInvoice.Columns.Add(“Amount”, Type.GetType(“System.String”));

dtETagHolders.Columns.Add(“NameInCSV”, Type.GetType(“System.String”));
dtETagHolders.Columns.Add(“loginName”, Type.GetType(“System.String”));
dtETagHolders.Columns.Add(“travelDetails”, Type.GetType(“System.String”));
dtETagHolders.Columns.Add(“userEmail”, Type.GetType(“System.String”));
dtETagHolders.Columns.Add(“userID”, Type.GetType(“System.Int32”));
dtETagHolders.Columns.Add(“emailSent”, Type.GetType(“System.String”));

// Create a set of assignees for task.
assignees = new ArrayList();

SPList eTagHoldersList = workflowProperties.Web.Lists[“e-Tag Holders”];
SPListItemCollection listItems = eTagHoldersList.Items;
foreach (SPListItem item in listItems)
{
string nameInCSV = item[“Title”].ToString();
int userID = Convert.ToInt32(item[“Account Name”].ToString().Substring(0, item[“Account Name”].ToString().IndexOf(“;#”)));
SPUser theUser = workflowProperties.Web.SiteUsers.GetByID(userID);
string loginName = theUser.LoginName;
string email = theUser.Email;
assignees.Add(loginName);

DataRow dr = dtETagHolders.NewRow();
dr[0] = nameInCSV;
dr[1] = loginName;
dr[3] = email;
dr[4] = userID;
dtETagHolders.Rows.Add(dr);
}

SPListItem currentItem = workflowProperties.Item;

try
{
string contents = string.Empty;
string filePath = currentItem.Url;
SPFile spfile = workflowProperties.Web.GetFile(filePath);
if (spfile.Exists)
{

StreamReader file = new StreamReader(spfile.OpenBinaryStream());
string line;
int index = 0;
int flag = 1000;
while ((line = file.ReadLine()) != null)
{
char[] splitter = { ‘,’ };
String[] arrLine = line.ToString().Split(splitter);

if (arrLine[0] == “Invoice period”)
{
invoicePeriod = Convert.ToString(arrLine[1]);
}

if (arrLine[0] == “Fleet identifier”)
{
flag = index;
}
if (index > flag + 2)
{
if (!String.IsNullOrEmpty(Convert.ToString(arrLine[0])))
{
DataRow dr = dtInvoice.NewRow();
dr[0] = arrLine[0];
dr[1] = arrLine[1];
dr[2] = arrLine[2];
dr[3] = arrLine[3];
dr[4] = arrLine[4];
dr[5] = arrLine[5];
dr[6] = arrLine[6];
dr[7] = arrLine[7];
dr[8] = arrLine[8];
dr[9] = arrLine[9];
dtInvoice.Rows.Add(dr);
}
}

index++;
}

}

}
catch (Exception ex)
{
LogComment(ex.ToString(), “Error”);
}

}

private void replicateTasks_Initialized(object sender, EventArgs e)
{

replicatorActivity1.InitialChildData = assignees;
}

private string checkNameInCSV(string loginName)
{
string result = “”;
foreach (DataRow dr in dtETagHolders.Rows)
{
string nameInCSV = Convert.ToString(dr[0]);
string loginName2 = Convert.ToString(dr[1]);
if (loginName.ToUpper() == loginName2.ToUpper())
{
result = nameInCSV.ToUpper();
break;
}
}
return result;
}

private void createTask1_MethodInvoking(object sender, EventArgs e)
{
// Triggered When creating a new task

// Initialisation
isFinished = false;

createTask1_TaskProperties1 = new SPWorkflowTaskProperties();
createTask1_TaskId1 = Guid.NewGuid();
createTask1_TaskProperties1.Title = “Please review CityLink travel details ” + invoicePeriod;

string assignedTo = replicatorActivity1.InitialChildData[countTask].ToString();
string html = “”;
string nameInCSV = checkNameInCSV(assignedTo);

foreach (DataRow dr1 in dtInvoice.Rows)
{
bool matched = false;
if (Convert.ToString(dr1[0]).ToUpper() == nameInCSV)
{
matched = true;
}

if (matched)
{
html += “<tr><td>” + dr1[0] + “</td><td>” + dr1[1] + “</td><td>” + dr1[2] + “</td><td>” + dr1[3] + “</td><td>” + dr1[4] + ” ” + dr1[5] + “</td><td>” + dr1[6] + ” ” + dr1[7] + “</td><td>” + dr1[9] + “</td></tr>”;

}
}

foreach (DataRow dr1 in dtETagHolders.Rows)
{
if (Convert.ToString(dr1[1]).ToUpper() == assignedTo.ToUpper())
{
dr1[2] = html;
}
}

createTask1_TaskProperties1.AssignedTo = assignedTo;
createTask1_TaskProperties1.Description = “”;

countTask++;
}

private void codeActivity1_method(object sender, EventArgs e)
{
try
{
if (counter == 0) // only happen once
{
string currentFileName = workflowProperties.Item.Name;

SPListItemCollection listItems = workflowProperties.TaskList.Items;

foreach (SPListItem item in listItems) // check all items in the Task list
{
string relatedContent1 = Convert.ToString(item[“Related Content”]);
string status = item[“Status”].ToString();

if (relatedContent1 != null && relatedContent1 != “”)
{
relatedContent1 = relatedContent1.Substring(relatedContent1.LastIndexOf(“,”) + 2) + “.CSV”;

if (relatedContent1.ToUpper() == currentFileName.ToUpper() && status != “Completed”) // only if the tasks’ related item is current file
{
string theID = item[“ID”].ToString();
string assignedTo = item[“Assigned To”].ToString();
string taskTitle = Convert.ToString(item[“Title”]);
string relatedContent = item[“Related Content”].ToString();

string currentTaskURL = “http://sharepoint.xxxxx.com.au&#8221; + workflowProperties.TaskListUrl + “/EditForm.aspx?ID=” + theID;
int key = Convert.ToInt32(theID) * 3 + 4;
string completeTaskLink = “mailto:au.sharepoint@xxxxx.com.au?subject=MarkAsComplete**SPEmail**” + theID + “**” + key.ToString() + “**http://sharepoint.xxxxx.com.au/hr/**2fa6e7a8-23ab-46f3-96d9-d3bf24fd743e**” + taskTitle;
currentTaskURL = currentTaskURL.Replace(“/lits/”, “/lists/”);
foreach (DataRow dr1 in dtETagHolders.Rows) // check through all items in the “e-Tag Holders” DataTable
{
string name = Convert.ToString(dr1[0]);
string firstname = name .Substring(0, name .IndexOf(” “));

string loginName = Convert.ToString(dr1[1]);
string travelDetails = Convert.ToString(dr1[2]);

string userEmail = Convert.ToString(dr1[3]);
int userID = Convert.ToInt32(dr1[4]);
string emailSent = Convert.ToString(dr1[5]);

// If the email hasn’t been sent for this person AND the “assigned to” for the Task is the same as the userID
if (emailSent != “1” && userID.ToString() == assignedTo.Substring(0, assignedTo.IndexOf(“;”)))
{

string emailBody = “<style type=\”text/css\”>body, div, span { font-family:arial; font-size:10pt;} table.GridView { font-family:arial; margin:0; font-size: 8pt; width: 100%; text-align: left; border-left:1px solid #dddddd; border-top:1px solid #dddddd; } table.GridView tr th { border:0; border-right:1px solid #dddddd; border-bottom:1px solid #dddddd; background-color:#333333; color:white; padding:10px; } table.GridView tr td { font-size: 8pt; padding: 8px 6px; border:0; border-right:1px solid #dddddd; border-bottom:1px solid #dddddd; } .donotprint { display:none; } a, a:visited {     color:#0072bc;     text-decoration:none;} h2 { font-size:14pt; } .theGrid tr td { padding:8px; } div#tabs { position:relative; padding:0; } div#tabs span.number { display:none; } div#tabs a, div#tabs a:link, div#tabs a:visited { display:none; } div#tabs a.current, div#tabs a.currentHover { border:1px solid #cccccc; color:#333333; float:left; text-align:center; border-bottom:0;  display:block; padding:8px; color:#000000; background-color:#ffffff; text-decoration:none;border-radius:3px 10px 0px 0px; } div#tabs a.hidden {display:none;} div.panel { padding:15px; border:1px solid #cccccc; background-color:#ffffff;display:block; border-collapse:separate;border-radius:0 10px 10px 10px; box-shadow: 2px 2px 2px #cccccc;} div.detailsAreaHidden {display:none; } img { display:none; } table.tableForm tr th,table.tableForm tr td { text-align:left; font-size: 10pt; } table.tableForm tr.alt th, table.tableForm tr.alt td { background-color:#f6f6f6; } .clearall {clear:both;} .left { float:left; } .doNotEmail { display:none; } </style>”;
emailBody += ”

Hi ” + firstname + “,

A CityLink invoice with travel details has been uploaded to SharePoint. Please review the following CityLink travel details:

“;
emailBody += ”

“; emailBody += “”;string emailBody2 = ”

Name Licence Plate e-Tag Travel Details Start Date/Time Finish Date/Time Cost

If the travel details above are correct, please click here to open the task, change the status to \”Completed\”, and then click \”Save\”.

“;
emailBody2 += “Complete the task via Email:

“;
emailBody2 += “If you are not on the company’s network (i.e., you are not in the office or connected via VPN), you can complete this task via email.

“;
emailBody2 += “Click on one of the following links and it will open a new email window. Make sure you leave the email subject unchanged.

“;
emailBody2 += ”    > Approve via Email

“;
emailBody2 += “SharePoint will send you an email once it has received your email and completed the task for you (this may takes a few minutes).

“;
emailBody2 += “If you found any errors please notify the HR manager.

Kind regards,
SharePoint
Sent from Workflow developed in VS2010

“;

StringDictionary headers = new StringDictionary();
headers.Add(“to”, userEmail);
headers.Add(“cc”, “”);
headers.Add(“bcc”, “”);
headers.Add(“subject”, “Please review CityLink travel details ” + invoicePeriod);
headers.Add(“content-type”, “text/html”);
SPUtility.SendEmail(workflowProperties.Web, headers, emailBody + travelDetails + emailBody2);

//SPUtility.SendEmail(workflowProperties.Web, true, false, userEmail, “Please review CityLink travel details”, emailBody);
dr1[5] = “1”;

break; // found the person, stop the loop
}

}
}
}
}

counter++;
}
}
catch (Exception ex)
{
LogComment(ex.ToString(), “Error”);
}
}

private void codeActivity2_method(object sender, EventArgs e)
{
try
{
string to = “”;
foreach (SPGroup spg in workflowProperties.Web.SiteGroups)
{
if (spg.Name == “CityLink Invoice Notification”)
{
foreach (SPUser user in spg.Users)
{
to += user.Email + “;”;
}
break;
}
}

string emailBody = “<style type=\”text/css\”>body, div, span { font-family:arial; font-size:10pt;} table.GridView { font-family:arial; margin:0; font-size: 8pt; width: 100%; text-align: left; border-left:1px solid #dddddd; border-top:1px solid #dddddd; } table.GridView tr th { border:0; border-right:1px solid #dddddd; border-bottom:1px solid #dddddd; background-color:#333333; color:white; padding:10px; } table.GridView tr td { font-size: 8pt; padding: 8px 6px; border:0; border-right:1px solid #dddddd; border-bottom:1px solid #dddddd; } .donotprint { display:none; } a, a:visited {     color:#0072bc;     text-decoration:none;} h2 { font-size:14pt; } .theGrid tr td { padding:8px; } div#tabs { position:relative; padding:0; } div#tabs span.number { display:none; } div#tabs a, div#tabs a:link, div#tabs a:visited { display:none; } div#tabs a.current, div#tabs a.currentHover { border:1px solid #cccccc; color:#333333; float:left; text-align:center; border-bottom:0;  display:block; padding:8px; color:#000000; background-color:#ffffff; text-decoration:none;border-radius:3px 10px 0px 0px; } div#tabs a.hidden {display:none;} div.panel { padding:15px; border:1px solid #cccccc; background-color:#ffffff;display:block; border-collapse:separate;border-radius:0 10px 10px 10px; box-shadow: 2px 2px 2px #cccccc;} div.detailsAreaHidden {display:none; } img { display:none; } table.tableForm tr th,table.tableForm tr td { text-align:left; font-size: 10pt; } table.tableForm tr.alt th, table.tableForm tr.alt td { background-color:#f6f6f6; } .clearall {clear:both;} .left { float:left; } .doNotEmail { display:none; } </style>”;
emailBody += ”

Hello,

Just letting you know that this CityLink invoice/travel details ” + invoicePeriod + “ have been reviewed by all the e-Tag holders:

“;
//emailBody += “Click here to view workflow history

“;
emailBody += “Kind regards,
SharePoint
Sent from Workflow developed in VS2010

“;

StringDictionary headers = new StringDictionary();
headers.Add(“to”, to);
headers.Add(“cc”, “”);
headers.Add(“bcc”, “”);
headers.Add(“subject”, “CityLink travel details has been reviewed by all e-Tag holders”);
headers.Add(“content-type”, “text/html”);
SPUtility.SendEmail(workflowProperties.Web, headers, emailBody);
LogComment(“Workflow completed. Notification sent to ” + to, “Log”);
}
catch (Exception ex)
{
LogComment(ex.ToString(), “Error Message”);
}
}

private void while1Invoke(object sender, ConditionalEventArgs e)
{
e.Result = !isFinished;
}

private void task1Changed1Invoke(object sender, ExternalDataEventArgs e)
{

int tid = onTaskChanged1_AfterProperties1.TaskItemId;
SPListItem task = workflowProperties.TaskList.GetItemById(tid);

if (Convert.ToString(task[“Status”]) == “Completed”)
{
isFinished = true;
countCompletedTask++;
string assignedTo = Convert.ToString(task[“Assigned To”]);
assignedTo = assignedTo.Substring(assignedTo.IndexOf(“#”) + 1);
LogComment(assignedTo + ” has complete the task (Task ID: ” + tid + “). ” + countCompletedTask + ” of ” + assignees.Count + ” completed”, “Completed”);
}
}

private void completeTask1_MethodInvoking(object sender, EventArgs e)
{
try
{
}
catch (Exception ex)
{
LogComment(ex.ToString(), “”);
}

}

private void repCompleted(object sender, ConditionalEventArgs e)
{
e.Result = (countCompletedTask == assignees.Count);
}

public static DependencyProperty onTaskChanged1_AfterProperties1Property = DependencyProperty.Register(“onTaskChanged1_AfterProperties1”, typeof(Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties), typeof(Workflow_CityLink_Invoices.Workflow1.Workflow1));

[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[BrowsableAttribute(true)]
[CategoryAttribute(“Misc”)]
public SPWorkflowTaskProperties onTaskChanged1_AfterProperties1
{
get
{
return ((Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)(base.GetValue(Workflow_CityLink_Invoices.Workflow1.Workflow1.onTaskChanged1_AfterProperties1Property)));
}
set
{
base.SetValue(Workflow_CityLink_Invoices.Workflow1.Workflow1.onTaskChanged1_AfterProperties1Property, value);
}
}

public static DependencyProperty onTaskChanged1_BeforeProperties1Property = DependencyProperty.Register(“onTaskChanged1_BeforeProperties1”, typeof(Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties), typeof(Workflow_CityLink_Invoices.Workflow1.Workflow1));

[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[BrowsableAttribute(true)]
[CategoryAttribute(“Misc”)]
public SPWorkflowTaskProperties onTaskChanged1_BeforeProperties1
{
get
{
return ((Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)(base.GetValue(Workflow_CityLink_Invoices.Workflow1.Workflow1.onTaskChanged1_BeforeProperties1Property)));
}
set
{
base.SetValue(Workflow_CityLink_Invoices.Workflow1.Workflow1.onTaskChanged1_BeforeProperties1Property, value);
}
}

}
}

Deploy the workflow:

  1. Deploy the project on the production server, then go to your site collection’s root site;
  2. Go “Site Actions > Site Settings”;
  3. Go to “Site Collection Features” under “Site Collection Administration”, activate the feature for this workflow.
  4. Go to the library and then “Library > Workflow Settings”;
  5. Click “Add a workflow”, you can then select the workflow name, task list, and workflow history list.
Posted in SharePoint 2010, Visual Studio 2010, Workflow | 1 Comment

Delay Activity in SharePoint 2010 Workflow (Visual Studio 2010) Not Firing

Three settings needed to be modified. Workflow Throttle, Workflow Batch, and the Hidden Workflow Timer.
You can check the current throttle setting by running the following command:

stsadm -o getproperty -pn workflow-eventdelivery-throttle

Here is my new setting:

stsadm -o setproperty -pn workflow-eventdelivery-throttle -pv “45”

You can check the current batch size setting by running the following command:

stsadm -o getproperty -pn workitem-eventdelivery-batchsize
Here is my new setting:

stsadm -o setproperty -pn workitem-eventdelivery-batchsize -pv “250”

You can check the current interval setting by running the following command, in which you replace the URL with a valid path to a SharePoint application:

stsadm -o getproperty -pn job-workflow -url http://yoursiteurl
Here is my setting:

stsadm -o setproperty -pn job-workflow -pv “Every 5 minutes between 0 and 59” -url http://yoursiteurl

The key part is that now provided I restart the Microsoft SharePointTimer service between deploys, it actually completes a delay!  So remember to recycle the “SharePoint 2010 Timer” service before you deploy a new version of the workflow to the farm.

To debug any code that runs after a delay, you have to attach Visual Studio to the timer service (owstimer.exe), not the w3w process.  I do this by switching off “auto retract after debugging” in the “SharePoint” page of the project’s properties file and manually attaching to the OWSTIMER.EXE process.

(The above is from the internet google search)

Posted in SharePoint 2010, Visual Studio 2010, Workflow | Leave a comment

SharePoint 2010 Search button disappeared

Issue Details:

Went to http://theSharePointSite/sites/Search/Pages/default.aspx manually to do a search and got this error:

Sharepoint Internal server error exception: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Office.Server.Search.WebControls.CoreResultsWebPart.SetPropertiesOnQueryReader()

Solution:

Restart these two services:

SharePoint Foundation Search V4
SharePoint Server Search 14

Posted in SharePoint 2010 | Tagged | Leave a comment

Complete SharePoint tasks via Email using Exchange Web Services (Microsoft Exchange Web Services Managed API 2.0)

Sometimes it is a pain that you want to complete a SharePoint task but you are not on your company’s network or connected via VPN.

This blog shows you how you can send an email to a mailbox to complete a SharePoint task.

How it will works:

1. SharePoint assigns a task to you and you receive a task notification email;

2. There will be several links in that email, e.g., Approve, Reject, Complete task, etc… You can click one of the links and it will open a new email window with a subject like this:

[Action]**SPEmail**[Task ID]**[Passcode]**[Site URL]**[Task List GUID]**[Task Title]

3. You should not change the email subject but you can put your comments in the email body, which will become the task comments;

4. Click the “send” button and the email will be sent to a specific email address, which is monitored by a SharePoint timer job. The timber job will check this mail box every 5 minutes for new emails.

  • The SharePoint timer job will check if the subject contains the word “**SPEmail**”
  • then complete the task for you if the Passcode is correct.

How to make it work:

1. Create the task email in SharePoint designer and generate the “Approve via Email” or “Reject via Email” link:

2015-06-24 09_30_29-Define E-mail Message

intTaskKey

2015-06-24 09_31_30-Define E-mail Message

2. Download and install Microsoft Exchange Web Services Managed API 2.0 to your development machine and then add reference to “Microsoft.Exchange.WebServices” (e.g., Browse to “C:\Bin\EwsAPI\Microsoft.Exchange.WebServices.dll”).

Add the following at the top of your code:

2015-06-24 09_51_51-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

3. This is how you check the mailbox:

2015-06-24 09_57_10-SharePoint Development (Snapshot 1) [Running] - Oracle VM VirtualBox

2015-06-24 10_27_20

Validate the passcode (key), you can make your own key here:

2015-06-24 10_30_18

You might need this callback function if you get an SSL certificate error:

2015-06-24 10_19_42-Oracle VM VirtualBox

4. Complete the SharePoint task:

According to the [Action] in the email subject line, you will need to complete the task for the user.

To approve the task:

2015-06-24 10_35_12 Approve

To reject the task:

2015-06-24 10_35_12 Reject

To mark the task as complete:

2015-06-24 10_35_12 MarkComplete

Finally, add this line:

oWeb.Update();

After you have complete the task, don’t forget the delete the email (move it to the “Deleted Items” folder):

item.Delete(DeleteMode.MoveToDeletedItems);

And this is the AlterTask function (in case of workflow is locked for some reason, it will try again):

2015-06-24 10_39_00-AlterTaskFunction

This is the send email function, if you need it:

2015-06-24 10_40_58-sendemailfunctin

You can write a timer job to run this every 5 minutes.

——————————————————————–

Before you deploy this to your production server, you will need to copy the “Microsoft.Exchange.WebServices.dll” file from your dev machine to the same location in the production server. You might also need to put it into the GAC folder in the production server.

Posted in EWS, SharePoint 2010, SharePoint Designer 2010, Visual Studio 2010, Web Service | Tagged , , | Leave a comment