Friday, February 24, 2012

Create Grid View

private static string CreateGridView(SPWeb web, string listName, string viewName, string fields)
{
SPList list = web.Lists.TryGetList(listName);
if (null == list)
{
// LogError
return string.Empty;
}
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
string[] names = fields.Split(';');
foreach (string name in names)
{
viewFields.Add(name);
}
SPView view = list.Views.Add(viewName, viewFields, "", 100, false, false, SPViewCollection.SPViewType.Grid, false);
return view.Url;
}

No comments:

Post a Comment