vb to C#

G

Guest

I have to loard an XML document and modify it cotent in C#
here is my source code. but it writen in VB.NET because i had some PB when i
tried to get to à specific TAG of my XML document.

i dont know excactly how to write this instructions in C# :
doc.Item("Configuration").Item("Extensions").Item("Data").AppendChild(elem)

Here is my VB.NET code :

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim rk As RegistryKey =
Registry.LocalMachine.OpenSubKey("software\\reportingservices")
Dim s As String = rk.GetValue("rsconfigfilepath")
Dim doc As XmlDocument Dim node As XmlNode
Dim elem As XmlElement
Dim rsconfig As String = s + "\RSReportServer.config"
Dim reader As XmlTextReader = New XmlTextReader(rsconfig)
reader.WhitespaceHandling = WhitespaceHandling.None
reader.MoveToContent() reader.Read()
doc.Load(reader)
elem = doc.CreateElement("Extension")
elem.SetAttribute("Name", "NKAS")
elem.SetAttribute("Type",
"Securitas.ReportingServices.DataExtension.colConnection,Securitas.ReportingServices.DataExtension")
doc.Item("Configuration").Item("Extensions").Item("Data").AppendChild(elem)
doc.Save(rsconfig)

End Sub

I would like to get the equivalent in C#.
Thanks in advance.
Regards
 
N

Nicholas Paldino [.NET/C# MVP]

Tino,

You can probably do this:

// Append the child.
doc["Configuration"]["Extensions"]["Data"].AppendChild(elem);

Typically, the indexer in C# maps to the Item property.

Hope this helps.
 
G

Guest

thank you for your code.
it wirks nice !!

i have another PB : i want to delete the current node of my xml document.

exemple :

<Data>
<Extension Name="ODBC" Type="XXXXX" />
<Extension Name="FSI" PPPP" />
<Extension Name="SRS" MMMM" />
</Data>
How can i delete the line : <Extension Name="SRS" MMMM" /> ???

Thankk you for your reply .

Nicholas Paldino said:
Tino,

You can probably do this:

// Append the child.
doc["Configuration"]["Extensions"]["Data"].AppendChild(elem);

Typically, the indexer in C# maps to the Item property.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tino said:
I have to loard an XML document and modify it cotent in C#
here is my source code. but it writen in VB.NET because i had some PB when
i
tried to get to à specific TAG of my XML document.

i dont know excactly how to write this instructions in C# :
doc.Item("Configuration").Item("Extensions").Item("Data").AppendChild(elem)

Here is my VB.NET code :

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim rk As RegistryKey =
Registry.LocalMachine.OpenSubKey("software\\reportingservices")
Dim s As String = rk.GetValue("rsconfigfilepath")
Dim doc As XmlDocument Dim node As XmlNode
Dim elem As XmlElement
Dim rsconfig As String = s + "\RSReportServer.config"
Dim reader As XmlTextReader = New XmlTextReader(rsconfig)
reader.WhitespaceHandling = WhitespaceHandling.None
reader.MoveToContent() reader.Read()
doc.Load(reader)
elem = doc.CreateElement("Extension")
elem.SetAttribute("Name", "NKAS")
elem.SetAttribute("Type",
"Securitas.ReportingServices.DataExtension.colConnection,Securitas.ReportingServices.DataExtension")
doc.Item("Configuration").Item("Extensions").Item("Data").AppendChild(elem)
doc.Save(rsconfig)

End Sub

I would like to get the equivalent in C#.
Thanks in advance.
Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top