private void DecodeFieldList() { SPFieldDefinitionCollection oTemplateFields = SPFieldListTemplates.GetTemplateFieldList(this.ServerTemplate); _Fields = new SPFieldDefinitionCollection(); _Fields.AddRange(SPFieldListTemplates.GetBasicFieldList(this.ListType)); // add the default definitions available no matter the list template. if (_ListData.IsNull("Fields")) { // the field definition is NULL, that means no customization has been applied to the server template for this list. // // We get the default field definitions for the list template. _Fields.AddRange(oTemplateFields); } else { // the field definitions are specified, that means the default server template has been override with custom metadata. // there 2 main node types for field definitions. // FieldRef and Field. I understood that FieldRef maps to a server template default definition and // Field is a custom definition. // For each fieldref, we try to get its definition from the template field definitions. // for each field, we are going to create a new instance of field definition based on the element attributes. System.Xml.XmlDocument oDoc = null; string sXML = "<Fields>" + _ListData["Fields"].ToString() + "</Fields>"; //note: for an unknown reason, oDoc.LoadXml fails in debug (within the VS IDE) // I get rid of the error by freeing memory (closing other opened application). // That piss me off and I discovered that when using an XmlReader it does not generate this error... oDoc = new System.Xml.XmlDocument(); System.IO.StringReader oXmlReader = new System.IO.StringReader(sXML); oDoc.Load(oXmlReader); System.Xml.XmlNodeList oNodes = oDoc.SelectNodes("Fields/*"); if (oNodes != null) { foreach (System.Xml.XmlElement oFieldXmlNode in oNodes) { SPFieldDefinition oDefinition = null; string sAttributeValue = null; switch (oFieldXmlNode.Name) { case "Field": if (oFieldXmlNode.GetAttribute("Type") == "URL") { oDefinition = new SPUrlFieldDefinition( oFieldXmlNode.GetAttribute("DisplayName"), oFieldXmlNode.GetAttribute("Name"), new string[] { oFieldXmlNode.GetAttribute("ColName"), oFieldXmlNode.GetAttribute("ColName2") }); } else if (oFieldXmlNode.GetAttribute("ColName").Length != 0) { oDefinition = new SPFieldDefinition( oFieldXmlNode.GetAttribute("DisplayName"), oFieldXmlNode.GetAttribute("Name"), oFieldXmlNode.GetAttribute("ColName")); } break; case "FieldRef": sAttributeValue = oFieldXmlNode.GetAttribute("ColName"); string sName = oFieldXmlNode.GetAttribute("Name"); if (sAttributeValue != null && sAttributeValue.Length > 0) { // we have a ColName value, we use it. string sDisplayName = sName.Replace("_x0020_", " "); oDefinition = new SPFieldDefinition(sDisplayName, sName, sAttributeValue); } else { // we do not have a ColName value. // we search the server template definition to get the default column mapping oDefinition = oTemplateFields.FindByInternalName(sName); } break; } if (oDefinition != null && _Fields.FindByInternalName(oDefinition.InternalName) == null) { _Fields.Add(oDefinition); } } } } }
private void DecodeFieldList() { SPFieldDefinitionCollection oTemplateFields = SPFieldListTemplates.GetTemplateFieldList(this.ServerTemplate); _Fields = new SPFieldDefinitionCollection(); _Fields.AddRange(SPFieldListTemplates.GetBasicFieldList(this.ListType)); // add the default definitions available no matter the list template. if (_ListData.IsNull("Fields")) { // the field definition is NULL, that means no customization has been applied to the server template for this list. // // We get the default field definitions for the list template. _Fields.AddRange(oTemplateFields); } else { // the field definitions are specified, that means the default server template has been override with custom metadata. // there 2 main node types for field definitions. // FieldRef and Field. I understood that FieldRef maps to a server template default definition and // Field is a custom definition. // For each fieldref, we try to get its definition from the template field definitions. // for each field, we are going to create a new instance of field definition based on the element attributes. System.Xml.XmlDocument oDoc = null; string sXML = "<Fields>" + _ListData["Fields"].ToString() + "</Fields>"; //note: for an unknown reason, oDoc.LoadXml fails in debug (within the VS IDE) // I get rid of the error by freeing memory (closing other opened application). // That piss me off and I discovered that when using an XmlReader it does not generate this error... oDoc = new System.Xml.XmlDocument(); System.IO.StringReader oXmlReader = new System.IO.StringReader(sXML); oDoc.Load(oXmlReader); System.Xml.XmlNodeList oNodes = oDoc.SelectNodes("Fields/*"); if (oNodes != null) { foreach (System.Xml.XmlElement oFieldXmlNode in oNodes) { SPFieldDefinition oDefinition = null; string sAttributeValue = null; switch (oFieldXmlNode.Name) { case "Field": if (oFieldXmlNode.GetAttribute("Type") == "URL") oDefinition = new SPUrlFieldDefinition( oFieldXmlNode.GetAttribute("DisplayName"), oFieldXmlNode.GetAttribute("Name"), new string[] { oFieldXmlNode.GetAttribute("ColName"), oFieldXmlNode.GetAttribute("ColName2") }); else if (oFieldXmlNode.GetAttribute("ColName").Length != 0) oDefinition = new SPFieldDefinition( oFieldXmlNode.GetAttribute("DisplayName"), oFieldXmlNode.GetAttribute("Name"), oFieldXmlNode.GetAttribute("ColName")); break; case "FieldRef": sAttributeValue = oFieldXmlNode.GetAttribute("ColName"); string sName = oFieldXmlNode.GetAttribute("Name"); if (sAttributeValue != null && sAttributeValue.Length > 0) { // we have a ColName value, we use it. string sDisplayName = sName.Replace("_x0020_", " "); oDefinition = new SPFieldDefinition(sDisplayName, sName, sAttributeValue); } else { // we do not have a ColName value. // we search the server template definition to get the default column mapping oDefinition = oTemplateFields.FindByInternalName(sName); } break; } if (oDefinition != null && _Fields.FindByInternalName(oDefinition.InternalName) == null) _Fields.Add(oDefinition); } } } }
private string GetListItemsQuery(SPListDefinition list, bool includeDocumentContent, bool countQuery) { StringBuilder sbSQL = new StringBuilder(); bool bFirst = true; sbSQL.Append("SELECT "); if (countQuery) { sbSQL.Append("COUNT(*)"); } else { SPFieldDefinitionCollection oFields = list.Fields; //Note: Beware, the includeDocumentContent works ONLY on document libraries. // for custom lists we must use GetListItemAttachmentsList method. if (includeDocumentContent) { oFields = new SPFieldDefinitionCollection(); oFields.AddRange(list.Fields); oFields.Add(new SPFieldDefinition("DocContent", "DocContent", "Docs.Content")); } foreach (SPFieldDefinition oField in oFields) { if (bFirst) { bFirst = false; } else { sbSQL.Append(", "); } sbSQL.AppendFormat("{0} AS [{1}]", oField.GetCompletePhysicalName(), oField.DisplayName); } } // Join between UserData and Docs occurs only for Document Libraries // Docs.Type = 0 = File // Docs.Type = 1 = Folder sbSQL.Append(" FROM UserData "); if (list.ListType == SharepointListType.DocumenLibrary) { // 2007/05/01: Bug Fix - Thanks to Merijn Boom // This query was returning some invalid records (one per folder found in document libraries) // that caused the exporter to crash. // // The fix is to perform an INNER JOIN instead of a LEFT JOIN to keep only records of type "File" // (exluding entries of type "Folder") when processing a document library. // // 2009/01/29: Bug Fix - Thanks to Finn Olesen for discovering the issue. // I have removed a condition in the INNER JOIN (on Doc.Version = UserData.tp_version) // that have nothing to do here. The unique value of a document in a document library // can be obtain with only the 2 following fields: ListId, DocLibRowId sbSQL.Append("INNER JOIN Docs ON (Docs.ListId = UserData.tp_ListId AND Docs.DocLibRowId = UserData.tp_ID AND Docs.Type = 0) "); } sbSQL.Append("LEFT JOIN UserInfo Author ON (Author.tp_ID = UserData.tp_Author AND Author.tp_SiteID = UserData.tp_SiteID) "); sbSQL.Append("LEFT JOIN UserInfo Editor ON (Editor.tp_ID = UserData.tp_Editor AND Editor.tp_SiteID = UserData.tp_SiteID) "); sbSQL.AppendFormat("WHERE UserData.tp_ListId = '{0}' ", list.ID); sbSQL.AppendFormat("AND UserData.tp_IsCurrent = CONVERT(bit, 1) "); return(sbSQL.ToString()); }
private string GetListItemsQuery(SPListDefinition list, bool includeDocumentContent, bool countQuery) { StringBuilder sbSQL = new StringBuilder(); bool bFirst = true; sbSQL.Append("SELECT "); if (countQuery) { sbSQL.Append("COUNT(*)"); } else { SPFieldDefinitionCollection oFields = list.Fields; //Note: Beware, the includeDocumentContent works ONLY on document libraries. // for custom lists we must use GetListItemAttachmentsList method. if (includeDocumentContent) { oFields = new SPFieldDefinitionCollection(); oFields.AddRange(list.Fields); oFields.Add(new SPFieldDefinition("DocContent", "DocContent", "Docs.Content")); } foreach (SPFieldDefinition oField in oFields) { if (bFirst) bFirst = false; else sbSQL.Append(", "); sbSQL.AppendFormat("{0} AS [{1}]", oField.GetCompletePhysicalName(), oField.DisplayName); } } // Join between UserData and Docs occurs only for Document Libraries // Docs.Type = 0 = File // Docs.Type = 1 = Folder sbSQL.Append(" FROM UserData "); if (list.ListType == SharepointListType.DocumenLibrary) { // 2007/05/01: Bug Fix - Thanks to Merijn Boom // This query was returning some invalid records (one per folder found in document libraries) // that caused the exporter to crash. // // The fix is to perform an INNER JOIN instead of a LEFT JOIN to keep only records of type "File" // (exluding entries of type "Folder") when processing a document library. // // 2009/01/29: Bug Fix - Thanks to Finn Olesen for discovering the issue. // I have removed a condition in the INNER JOIN (on Doc.Version = UserData.tp_version) // that have nothing to do here. The unique value of a document in a document library // can be obtain with only the 2 following fields: ListId, DocLibRowId sbSQL.Append("INNER JOIN Docs ON (Docs.ListId = UserData.tp_ListId AND Docs.DocLibRowId = UserData.tp_ID AND Docs.Type = 0) "); } sbSQL.Append("LEFT JOIN UserInfo Author ON (Author.tp_ID = UserData.tp_Author AND Author.tp_SiteID = UserData.tp_SiteID) "); sbSQL.Append("LEFT JOIN UserInfo Editor ON (Editor.tp_ID = UserData.tp_Editor AND Editor.tp_SiteID = UserData.tp_SiteID) "); sbSQL.AppendFormat("WHERE UserData.tp_ListId = '{0}' ", list.ID); sbSQL.AppendFormat("AND UserData.tp_IsCurrent = CONVERT(bit, 1) "); return (sbSQL.ToString()); }