| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 
 | SqlDataReader sdr;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string query = "SELECT Id, Content From Template WHERE Id = '0108f7ac-7853-4543-8ec4-a04cb755ed46' AND Deleted = '0'";
                SqlCommand cmd = new SqlCommand(query, connection);
                connection.Open();
                sdr = cmd.ExecuteReader();
                XmlDocument doc = new XmlDocument();
                XmlDocument docComplet = new XmlDocument();
 
                if (sdr.HasRows)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add("Nom", typeof(string));
                    dt.Columns.Add("test", typeof(string));
 
                    while (sdr.Read())
                    {
                        string complet = sdr["Content"].ToString();
                        RecupContenu();
 
                        System.Diagnostics.Debug.WriteLine(System.Web.HttpUtility.HtmlDecode(RecupContenu()));
 
                        string contenu = System.Web.HttpUtility.HtmlDecode(RecupContenu());
 
                        doc.LoadXml(contenu);
                        docComplet.LoadXml(complet);
 
                        // Test Content
                        System.Diagnostics.Debug.WriteLine("[-- CONTENU --] --> : " + contenu);
 
                        var nodesIdTemp = docComplet.SelectNodes("Root/StorageObject[@Name]");
                        var nodes = doc.SelectNodes("Template//Component/Properties/Property[@Name='FormId']");
 
                        foreach (XmlElement nodeT in nodesIdTemp)
                        {
                            string nameTemp = nodeT.GetAttribute("Name");
                            foreach (XmlElement node in nodes)
                            {
                                string attributeValue = node.GetAttribute("Value");
                                System.Diagnostics.Debug.WriteLine("Test : " + attributeValue);
                                dt.Rows.Add(nameTemp,attributeValue);
                            }
                        }                       
                    }
                    test.DataSource = dt;
                    test.DataBind();
                }          
            }
            finally
            {
                connection.Close();
            }        
        }
 
        // Méthode pour se connecter au champs Content et récupérer le contenu dans une variable.
        public string connexionContent(string field, SqlDataReader sdr)
        {
            // enregistrement du contenu du champs Content dans une variable
            string content = sdr[field].ToString();
 
            System.Diagnostics.Debug.WriteLine("[ -- Lecture donnée depuis Méthode connexionContent -- ] ----> : " + content);
 
            return content;
        }
 
        // Méthode pour découper le contenu du champs Content
        public string RecupContenu()
        {
            // Tentative de séparation des deux parties de la chaine de caracteres
            string chaineACouper = "<Property Name=\"ObjectContent\" Value=\"";
            string[] chaineArrive = connexionContent("Content", sdr).Split(new string[] { chaineACouper }, StringSplitOptions.None);
            chaineArrive[0] += chaineACouper;
 
            // Séparation des deux parties.
            string stringPartOne = chaineArrive[0];
            string stringPartTwo = chaineArrive[1];
 
            // Test
            System.Diagnostics.Debug.WriteLine("[-- Lecture donnée depuis RecupContenu() --] ---> : " + stringPartTwo);
 
            string chaineACouperFin = "\" /></Properties></StorageObject></Root>";
            string[] chaineFinale = stringPartTwo.Split(new string[] { chaineACouperFin }, StringSplitOptions.None);
            chaineFinale[1] += chaineACouperFin;
 
            string stringFinale = chaineFinale[0];
 
            // Test
            System.Diagnostics.Debug.WriteLine("[-- Lecture bloc final -- ] --> : " + stringFinale);
 
            return stringFinale;
        }
    } | 
Partager