Exemple #1
0
        //----------------------------------------------------------
        private void FillStructureTable(futurocom.easyquery.Sharepoint30.Lists service,
                                        CTableDefinitionSharepoint table)
        {
            if (table == null)
            {
                return;
            }
            try
            {
                XmlNode             node    = service.GetList(table.TableName) as XmlNode;
                XmlNamespaceManager manager = new XmlNamespaceManager(node.OwnerDocument.NameTable);
                manager.AddNamespace("sp", node.NamespaceURI);
                XmlNodeList liste = node.SelectNodes("sp:Fields/sp:Field", manager);
                List <CColonneDefinitionSharepoint> lstCols = new List <CColonneDefinitionSharepoint>();

                foreach (XmlNode childNode in liste)
                {
                    string strNom         = "";
                    string strId          = "";
                    string strType        = "";
                    string strDescription = "";
                    foreach (XmlAttribute attr in childNode.Attributes)
                    {
                        if (attr.Name.ToUpper() == "NAME")
                        {
                            strId = attr.Value;
                        }
                        if (attr.Name.ToUpper() == "NAME")
                        {
                            strNom = XmlConvert.DecodeName(attr.Value);
                        }
                        if (attr.Name.ToUpper() == "TYPE")
                        {
                            strType = attr.Value;
                        }
                        if (attr.Name.ToUpper() == "DESCRIPTION")
                        {
                            strDescription = XmlConvert.DecodeName(attr.Value);
                        }
                        if (strId.Length > 0 && strNom.Length > 0 && strType.Length > 0 && strDescription.Length > 0)
                        {
                            break;
                        }
                    }
                    CColonneDefinitionSharepoint col = new CColonneDefinitionSharepoint();
                    col.SharepointId = strId;
                    col.ColumnName   = strNom;
                    col.DataType     = typeof(string);
                    lstCols.Add(col);
                }
                lstCols.Sort((x, y) => x.ColumnName.CompareTo(y.ColumnName));
                foreach (CColonneDefinitionSharepoint c in lstCols)
                {
                    table.AddColumn(c);
                }
            }
            catch
            {
            }
        }
Exemple #2
0
 //----------------------------------------------------------
 private void AssureListeTables()
 {
     if (m_listeTables == null)
     {
         futurocom.easyquery.Sharepoint30.Lists service = new futurocom.easyquery.Sharepoint30.Lists();
         if (m_strURL.Length > 0)
         {
             service.Url = m_strURL;
         }
         m_listeTables       = new List <CTableDefinitionSharepoint>();
         service.Credentials = new NetworkCredential(m_strUser, m_strPassword);
         try
         {
             XmlNode             node    = service.GetListCollection();
             XmlNamespaceManager manager = new XmlNamespaceManager(node.OwnerDocument.NameTable);
             manager.AddNamespace("sp", node.NamespaceURI);
             XmlNodeList liste = node.SelectNodes("sp:List", manager);
             foreach (XmlNode child in liste)
             {
                 if (child.NodeType == XmlNodeType.Element &&
                     child.Name.ToUpper() == "LIST")
                 {
                     string strNomTable    = "";
                     string strGUID        = "";
                     string strDescription = "";
                     foreach (XmlAttribute attrib in child.Attributes)
                     {
                         if (attrib.Name.ToUpper() == "TITLE")
                         {
                             strNomTable = XmlConvert.DecodeName(attrib.Value);
                         }
                         if (attrib.Name.ToUpper() == "DESCRIPTION")
                         {
                             strDescription = XmlConvert.DecodeName(attrib.Value);
                         }
                         if (attrib.Name.ToUpper() == "ID")
                         {
                             strGUID = attrib.Value;
                         }
                         if (strNomTable.Length > 0 && strGUID.Length > 0 && strDescription.Length > 0)
                         {
                             break;
                         }
                     }
                     CTableDefinitionSharepoint table = new CTableDefinitionSharepoint(
                         strGUID, strNomTable,
                         strDescription);
                     m_listeTables.Add(table);
                     FillStructureTable(service, table);
                 }
             }
             m_listeTables.Sort((x, y) => x.TableName.CompareTo(y.TableName));
         }
         catch (Exception e)
         {
         }
     }
 }
Exemple #3
0
        //----------------------------------------------------------
        public DataTable GetDataWithCAML(ITableDefinition tableDefinition, string strCAMLQuery, params string[] strIdsColonnesSource)
        {
            DataTable tableResult            = null;
            CTableDefinitionSharepoint table = tableDefinition as CTableDefinitionSharepoint;

            if (table == null)
            {
                return(tableResult);
            }

            futurocom.easyquery.Sharepoint30.Lists service = new futurocom.easyquery.Sharepoint30.Lists();
            if (m_strURL.Length > 0)
            {
                service.Url = m_strURL;
            }
            service.Credentials = new NetworkCredential(m_strUser, m_strPassword);

            //Création de la liste des colonnes attendues
            XmlDocument doc        = new XmlDocument();
            XmlElement  nodeFields = null;

            if (strIdsColonnesSource.Length > 0)
            {
                nodeFields = doc.CreateElement("ViewFields");
                foreach (string strIdColonne in strIdsColonnesSource)
                {
                    XmlElement nodeField = doc.CreateElement("FieldRef");
                    nodeFields.AppendChild(nodeField);
                    XmlAttribute att = doc.CreateAttribute("Name");
                    att.Value = strIdColonne;
                    nodeField.Attributes.Append(att);
                }
            }
            XmlElement nodeQuery = null;

            if (strCAMLQuery.Length > 0)
            {
                nodeQuery = doc.CreateElement("Query");
                XmlElement nodeWhere = doc.CreateElement("Where");
                nodeQuery.AppendChild(nodeWhere);
                nodeWhere.InnerXml = strCAMLQuery;
            }
            XmlElement nodeQueryOptions = doc.CreateElement("QueryOptions");

            nodeQueryOptions.InnerXml = "";
            XmlNode node = service.GetListItems(table.Id, null, nodeQuery, nodeFields, "", nodeQueryOptions, null);

            XmlNamespaceManager manager = new XmlNamespaceManager(node.OwnerDocument.NameTable);

            foreach (XmlAttribute att in node.Attributes)
            {
                if (att.Name.StartsWith("xmlns:"))
                {
                    string strAbrv = att.Name.Substring(att.Name.IndexOf(":") + 1);
                    manager.AddNamespace(strAbrv, att.Value);
                }
            }
            XmlNodeList liste = node.SelectNodes("/rs:data/z:row", manager);

            tableResult = new DataTable(tableDefinition.TableName);
            //Création de la structure de la table
            Dictionary <string, DataColumn> dicCols = new Dictionary <string, DataColumn>();

            foreach (IColumnDefinition col in table.Columns)
            {
                CColonneDefinitionSharepoint colShp = col as CColonneDefinitionSharepoint;
                if (colShp != null && (strIdsColonnesSource.Length == 0 || strIdsColonnesSource.Contains(colShp.SharepointId)))
                {
                    DataColumn newCol = new DataColumn(col.ColumnName, col.DataType);
                    tableResult.Columns.Add(newCol);

                    dicCols[colShp.SharepointId] = newCol;
                }
            }

            foreach (XmlNode xmlRow in liste)
            {
                DataRow row = tableResult.NewRow();
                foreach (XmlAttribute att in xmlRow.Attributes)
                {
                    if (att.Name.StartsWith("ows_"))
                    {
                        string     strNomCol  = att.Name.Substring(4);
                        DataColumn colDeTable = null;
                        if (dicCols.TryGetValue(strNomCol, out colDeTable))
                        {
                            row[colDeTable] = att.Value;
                        }
                    }
                }
                try{
                    tableResult.Rows.Add(row);
                }
                catch {}
            }
            return(tableResult);
        }