private void ModifyCAMLFilter(SPView view) { var xml = new XmlDocument(); xml.LoadXml(view.GetViewXml()); if (xml.DocumentElement == null) { return; } var query = xml.DocumentElement.SelectSingleNode(CAML.Query); if (query != null) { var where = query.SelectSingleNode(CAML.Where); if (where == null) { where = xml.CreateNode(XmlNodeType.Element, CAML.Where, string.Empty); query.AppendChild(where); var w = CAMLGenerator.JoinFilters(CAMLPredicates, CAML.And); where.InnerXml = w; } else { var whereParts = new List <string> { where.InnerXml }; whereParts.AddRange(CAMLPredicates); where.InnerXml = CAMLGenerator.JoinFilters(whereParts, CAML.And); } } view.SetViewXml(xml.OuterXml); Debug.WriteLine(xml.OuterXml); }
private void AddViewToList(SPWeb web, string listUrl, string viewString) { SPList list = web.GetList(GetListUrl(web.ServerRelativeUrl, listUrl)); XmlDocument doc = new XmlDocument(); doc.LoadXml(viewString); SPView loadedView = new SPView(list, doc); SPView newView = list.Views.Add(loadedView.Title, loadedView.ViewFields.ToStringCollection(), loadedView.Query, loadedView.RowLimit, loadedView.Paged, loadedView.DefaultView); string viewXmlString = doc.DocumentElement.OuterXml; newView.SetViewXml(viewXmlString); newView.Update(); }