Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class PageStat #Region " Properties " Private _XmlPath As String Public ReadOnly Property XmlPath() As String Get Return _XmlPath End Get End Property #End Region #Region " Variables " Private Page As System.Web.UI.Page #End Region Private Function SetXmlPath() As String If Not Directory.Exists(Page.Server.MapPath("") & "\Data") Then Dim Dir As New DirectoryInfo(Page.Server.MapPath("")) Dir.CreateSubdirectory("Data") End If If Not File.Exists(Page.Server.MapPath("Data") & "\PageStat.xml") Then Try Dim FI As FileInfo FI = New FileInfo(Page.Server.MapPath("Data/PageStat.xml")) Catch ex As Exception ''' Certainement une erreur dans le nom du fichier ''' Je vois pas ce que je peux faire pour l'instant ''' je relance l'erreur Throw ex End Try 'Creation du Fichier XML Dim XMLobj As System.Xml.XmlTextWriter Dim ue As New System.[Text].UnicodeEncoding XMLobj = New System.Xml.XmlTextWriter(Page.Server.MapPath("Data/PageStat.xml"), ue) 'indentation etc... XMLobj.Formatting = System.Xml.Formatting.Indented XMLobj.Indentation = 3 XMLobj.WriteStartDocument() XMLobj.WriteComment("XML crée pour Enregistrer le nombre de passage sur une page par Cyril Durand") XMLobj.WriteComment("http://www.codes-sources.com/auteurdetail.aspx?ID=19303") XMLobj.WriteComment("crée le " & Now.ToLongDateString) XMLobj.WriteStartElement("Pages") 'Pages XMLobj.WriteEndElement() '/Pages XMLobj.Close() End If Return Page.Server.MapPath("Data/PageStat.xml") End Function Public Sub New(ByVal InstanceOfPage As System.Web.UI.Page) Page = InstanceOfPage _XmlPath = SetXmlPath() End Sub Public Sub WriteStat() Dim Compteur As Decimal = ReadStat() Dim Doc As New XmlDocument Doc.Load(Page.Server.MapPath("Data/PageStat.xml")) If Compteur = -1 Then 'ajout des stats de la page Dim mElement As XmlElement mElement = Doc.CreateElement("Page") mElement.InnerText = 1.ToString mElement.SetAttribute("PageName", Page.Request.CurrentExecutionFilePath) 'Fermeture du fichier Doc.DocumentElement.AppendChild(mElement) Doc.Save(Page.Server.MapPath("Data/PageStat.xml")) Else Dim Node As XmlNode = Doc.DocumentElement.FirstChild Do Until Node Is Nothing If Node.Attributes(0).Value = Page.Request.CurrentExecutionFilePath Then Node.InnerText = (Compteur + 1).ToString End If Node = Node.NextSibling Loop Doc.Save(Page.Server.MapPath("Data/PageStat.xml")) End If End Sub Public Function ReadStat(ByVal PageName As String) As Decimal Dim Doc As New XmlDocument Doc.Load(Page.Server.MapPath("Data/PageStat.xml")) Dim NodeList As XmlNodeList = Doc.DocumentElement.ChildNodes For Each Node As XmlNode In NodeList If Node.Attributes(0).Value = PageName Then Dim count As String = Node.InnerText Return CType(count, Decimal) Exit Function End If Next Return -1 End Function Public Function ReadStat() As Decimal Return ReadStat(Page.Request.CurrentExecutionFilePath) End Function End Class