Below is the sample code of a console application that removes workflow column from the default view of the SharePoint list:
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint;
namespace
RemoveWorkFlowColumnFromSPView
{
class Program
{
static void Main(string[]
args)
{
if
(args.Length != 4)
{
Console.WriteLine("Please input parameters.");
Console.WriteLine("Format: <site url> <list name> <view
name> <workflow template name>");
return;
}
string
workflowColName = string.Empty;
string
siteUrl = args[0]; //
"http://www.vpc.com/sites/PFW"; //
string
listName = args[1]; // "Perimeter Firewall
Request"; //
string
viewName = args[2]; // "All Requests"; //
string
workflowName = args[3]; //
"FirewallRequestWorkFlow"; //
using
(SPSite site = new SPSite(siteUrl))
{
using
(SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPView objView =
web.Lists[listName].Views[viewName];
//static
name of the workflow column is equal to 8_character_name_of_workflow_column,
//
without space and is case sensitive.
workflowColName =
workflowName.Substring(0, 8);
if
(objView.ViewFields.Exists(workflowColName))
{
objView.ViewFields.Delete(workflowColName);
objView.Update();
Console.WriteLine(string.Format("{0} column: {1} has been removed successfully from
the {2} view",
workflowName,
workflowColName,
viewName));
}
web.AllowUnsafeUpdates = false;
}
}
}
}
}
No comments:
Post a Comment