Victor Charles
asked on
How to protect xml files?
Hello,
I'm trying to secure my xml files my making them read only and also if possible not to allow users to open them. Below is a code I found in the web but I can't use it with the method that I'm usimg to view my xml using VB.NET is there a way to modify the code to work with my VB.NET project?
Methos used to open xml files:
Dim dt As New DataTable()
dt.Columns.Add("Link_ID")
Dim linker As XElement = XElement.Load(Application. StartupPat h + "\LinkFinal.xml")
For Each item As XElement In linker.Elements("Row")
Dim linkID As String = item.Element("Link_ID").Va lue
Dim dr As DataRow = dt.NewRow()
dr("Link_ID") = linkID
Next
bs.DataSource = dt
C1TrueDBGrid1.DataSource = bs
Dim FilteredDT As DataTable
Dim DV As New DataView(dt, SearchCriteria, Nothing, DataViewRowState.CurrentRo ws)
FilteredDT = DV.ToTable
C1TrueDBGrid1.DataSource = FilteredDT
Code found:
File.Open("C:\temp\Filenam e.xml",Fil eMode.Appe nd,FileAcc ess.ReadWr ite,FileSh are.None);
Thanks,
Victor
I'm trying to secure my xml files my making them read only and also if possible not to allow users to open them. Below is a code I found in the web but I can't use it with the method that I'm usimg to view my xml using VB.NET is there a way to modify the code to work with my VB.NET project?
Methos used to open xml files:
Dim dt As New DataTable()
dt.Columns.Add("Link_ID")
Dim linker As XElement = XElement.Load(Application.
For Each item As XElement In linker.Elements("Row")
Dim linkID As String = item.Element("Link_ID").Va
Dim dr As DataRow = dt.NewRow()
dr("Link_ID") = linkID
Next
bs.DataSource = dt
C1TrueDBGrid1.DataSource = bs
Dim FilteredDT As DataTable
Dim DV As New DataView(dt, SearchCriteria, Nothing, DataViewRowState.CurrentRo
FilteredDT = DV.ToTable
C1TrueDBGrid1.DataSource = FilteredDT
Code found:
File.Open("C:\temp\Filenam
Thanks,
Victor
Use:
Dim lStream As New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
Dim doc As As New XmlDocument()
doc.Load(lStream)
Then use doc to manipulate xml data
Dim lStream As New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
Dim doc As As New XmlDocument()
doc.Load(lStream)
Then use doc to manipulate xml data
ASKER
Hello,
How do you incorporate the code in part a with my code in part b, still can't figure it out.
Thanks,
Victor
a) Dim lStream As New IO.FileStream(fileName, IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite, IO.FileShare.None)
Dim doc As New XmlDocument()
doc.Load(lStream)
b) Dim dt As New DataTable()
dt.Columns.Add("Link_ID")
Dim linker As XElement = XElement.Load(Application. StartupPat h + "\LinkFinal.xml")
For Each item As XElement In linker.Elements("Row")
Dim linkID As String = item.Element("Link_ID").Va lue
Dim dr As DataRow = dt.NewRow()
dr("Link_ID") = linkID
Next
bs.DataSource = dt
C1TrueDBGrid1.DataSource = bs
Dim FilteredDT As DataTable
Dim DV As New DataView(dt, SearchCriteria, Nothing, DataViewRowState.CurrentRo ws)
FilteredDT = DV.ToTable
C1TrueDBGrid1.DataSource = FilteredDT
How do you incorporate the code in part a with my code in part b, still can't figure it out.
Thanks,
Victor
a) Dim lStream As New IO.FileStream(fileName, IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite, IO.FileShare.None)
Dim doc As New XmlDocument()
doc.Load(lStream)
b) Dim dt As New DataTable()
dt.Columns.Add("Link_ID")
Dim linker As XElement = XElement.Load(Application.
For Each item As XElement In linker.Elements("Row")
Dim linkID As String = item.Element("Link_ID").Va
Dim dr As DataRow = dt.NewRow()
dr("Link_ID") = linkID
Next
bs.DataSource = dt
C1TrueDBGrid1.DataSource = bs
Dim FilteredDT As DataTable
Dim DV As New DataView(dt, SearchCriteria, Nothing, DataViewRowState.CurrentRo
FilteredDT = DV.ToTable
C1TrueDBGrid1.DataSource = FilteredDT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You!
ASKER
When you you use the hidden attribute, where is the file hidden?, can users still somehow see it? Can you use more than one attribute to a file?
Encrypt xml.