public void RowLimitWitANumberPrintsTheRowLimit() { var limit = Fixture.Create <int>(); var sut = new RowLimit(limit); sut.ToString().ShouldBe(string.Format("<RowLimit>{0}</RowLimit>", limit)); }
/// <summary> /// Queries SharePoint for list items. /// </summary> /// <param name="listService">List service proxy class instance</param> /// <param name="listName">List name</param> /// <returns>CAML with list items</returns> protected XmlNode LoadListItems(Lists listService, string listName) { // Get all SharePoint lists XmlNode listCollectionCaml = listService.GetListCollection(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(listCollectionCaml.OwnerDocument.NameTable); nsmgr.AddNamespace("soap", "http://schemas.microsoft.com/sharepoint/soap/"); // Check list with given name exists XmlNodeList collections = listCollectionCaml.SelectNodes("/soap:List[@Title = '" + listName + "']", nsmgr); // If specified list does not exists show error if (collections.Count == 0) { DisplayError(ResHelper.GetString("SharePoint.listdoesnotexists")); return(null); } #region "Advanced options" //XmlElement query = null; XmlDocument viewFields = null; XmlDocument query = null; XmlDocument queryOptions = null; // Specify search by query if (!String.IsNullOrEmpty(Query)) { //query = xmlOptions.CreateElement("Query"); //query.InnerXml = this.Query; //"<Where><Gt><FieldRef Name=\"ID\" /><Value Type=\"Counter\">0</Value></Gt></Where>"; query = new XmlDocument(); query.LoadXml(Query); } // Select item if (!String.IsNullOrEmpty(ItemIDField)) { string queryValue = QueryHelper.GetText(ItemIDField, null); if (queryValue != null) { IsSelected = true; // Set field name from ItemIDField if not set string fieldName = (String.IsNullOrEmpty(SelectedItemFieldName)) ? ItemIDField : SelectedItemFieldName; // No query was set if (query == null) { query = new XmlDocument(); } // Get or create Query node XmlNode queryNode = query.SelectSingleNode("Query"); if (queryNode == null) { queryNode = query.CreateNode(XmlNodeType.Element, "Query", null); query.AppendChild(queryNode); } // Get or create Where node XmlNode whereNode = queryNode.SelectSingleNode("Where"); if (whereNode == null) { whereNode = query.CreateNode(XmlNodeType.Element, "Where", null); queryNode.AppendChild(whereNode); } // Prepare query for selecting item string selectItem = String.Format("<Eq><FieldRef ID='{0}' /><Value Type='{1}'>{2}</Value></Eq>", fieldName, ItemIDFieldType, queryValue); // Incorporate with original query if (!String.IsNullOrEmpty(whereNode.InnerXml)) { selectItem = String.Format("<And>{0}{1}</And>", whereNode.InnerXml, selectItem); } // Update Where node whereNode.InnerXml = selectItem; } } // Specify which fields should be retrieved if (!String.IsNullOrEmpty(ViewFields)) { viewFields = new XmlDocument(); string xml = "<ViewFields>"; string[] fields = ViewFields.Split(';'); foreach (string field in fields) { xml += string.Format("<FieldRef Name=\"{0}\" />", field.Trim()); } xml += "</ViewFields>"; viewFields.LoadXml(xml); } //xmlDoc.CreateElement("QueryOptions"); //queryOptions.InnerXml = ""; // If set limit maximum count of rows string rowLimit = (RowLimit > 0) ? RowLimit.ToString() : null; #endregion // Get documents in the list XmlNode documentsXml = listService.GetListItems(ListName, null, query, viewFields, rowLimit, queryOptions, null); return(documentsXml); }
/// <summary>Retrieves the data.</summary> public void GetData() { edu.demo.portal.Lists listService = new edu.demo.portal.Lists(); if (UserName.Length > 0) { listService.Credentials = new System.Net.NetworkCredential(UserName, Password); } else { listService.Credentials = System.Net.CredentialCache.DefaultCredentials; } listService.Url = GetWebServiceUrl(this.DNSName, this.URL); XmlDocument xmlDoc = new XmlDocument(); XmlElement query = xmlDoc.CreateElement("Query"); XmlElement viewFields = xmlDoc.CreateElement("ViewFields"); XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions"); int i = 0; if (SelectFields.Count == 0) { HasError = true; ErrorMessage = rm.GetString("ErrSelectFieldEmpty", CultureInfo.CurrentCulture); // ErrorMessage="SelectFields is empty."; return; } //Add columns to datatable //Construct viewfields try { foreach (string field in SelectFields) { dt.Columns.Add(field, System.Type.GetType(SelectFieldTypes[i].ToString())); viewFields.InnerXml += "<FieldRef Name=\"" + field + "\" />"; i++; } } catch (Exception ex) { HasError = true; ErrorMessage = rm.GetString("ErrProcessingSelectFields", CultureInfo.CurrentCulture) + ": " + ex.Message; // ErrorMessage="Error processing SelectFields: " + ex.Message; return; } //RecurseSubFolders if (RecurseSubFolders) { queryOptions.InnerXml = "<ViewAttributes Scope=\"Recursive\" />"; } try { //Paging prevpage = PageInfo; queryOptions.InnerXml += "<Paging ListItemCollectionPositionNext=\"" + System.Web.HttpUtility.HtmlEncode(PageInfo) + "\" />"; } catch (Exception ex) { HasError = true; ErrorMessage = rm.GetString("ErrPagingError", CultureInfo.CurrentCulture) + ": " + ex.Message; // ErrorMessage="Paging error: " + ex.Message; return; } try { //Build where clause query.InnerXml = BuildQuery(); //Add order by if (OrderBy.Length > 0) { query.InnerXml += OrderBy; } } catch (Exception ex) { HasError = true; ErrorMessage = rm.GetString("ErrWhereClauseError") + ": " + ex.Message; // ErrorMessage="Error building where clause: " + ex.Message; return; } //Run the query try { XmlNode nodeListItems = listService.GetListItems(ListName, viewName, query, viewFields, RowLimit.ToString(), queryOptions, WebId()); if (debug) { DebugXML = nodeListItems.OuterXml; } // Loop through each node in the XML response and display each item. System.Data.DataRow dr; foreach (XmlNode listItem in nodeListItems) { if (listItem.HasChildNodes) { if (listItem.Attributes["ListItemCollectionPositionNext"] != null) { nextpage = listItem.Attributes["ListItemCollectionPositionNext"].Value; } foreach (XmlNode nd in listItem.ChildNodes) { if (nd.Attributes != null) { dr = dt.NewRow(); for (int a = 0; a < SelectFields.Count; a++) { if (nd.Attributes["ows_" + SelectFields[a].ToString()] != null) { dr[a] = nd.Attributes["ows_" + SelectFields[a].ToString()].Value; } } dt.Rows.Add(dr); } } } } } catch (Exception ex) { HasError = true; ErrorMessage = ex.Message; #if DEBUG LogToFile("Error Message:" + ex.Message + " Stack Trace" + ex.StackTrace); #endif } }