I am trying to create a view programatically to be used in an XSLTViewWebPart. When I try to browse to the view I got this exception:
Cannot complete this action. Please try again.
I set the log to verbose in all categories, but there is nothing.
public static void CreateRequestDetailView(SPWeb sourceWeb, string listName, string viewName, string detailNameNorthSouth, string xslLink)
{
SPList sourceList = sourceWeb.GetSafeListByName(listName);
SPView view = sourceList.GetViewByName(viewName);
if(view != null) {
sourceList.Views.Delete(view.ID);
}
StringCollection viewFields = new System.Collections.Specialized.StringCollection();
foreach (SPField field in sourceList.Fields)
{
viewFields.Add(field.StaticName);
}
string myquery = "<Query><Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Number\">{SelectedID}</Value></Eq></Where></Query>";
view = sourceList.Views.Add(viewName, viewFields, myquery, 1, false, false);
view.ParameterBindings += @"<ParameterBinding Name='SelectedID' Location='None' DefaultValue='' />";
view.XslLink = xslLink;
view.Update();
}