Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Wednesday, October 5, 2016

Access denied error message while saving files on C drive - Windows 7

Access denied,Access denied saving files,Windows 7 Access Denied saving files, Windows 7 Cannot save files to Drive:,open text files as administrator

I have Windows 7 machine and have set myself as the Administrator. However, when trying to modify an XML file in Notepad and save the file, it states 'Access Denied!'. It will not save the file.



Below is the solution worked for me:

Step 1. Open the notepad application in elevated mode. This can be done by right click the Notepad icon from Windows > Click 'Run as administrator'.

Step 2. You can now edit and save that file in the same folder without any issues.



If you want to open the notepad elevated every time, then right click the Notepad shortcut icon > in 'shortcut' tab click on the 'Advanced' button > tick 'run as administrator'.



Thursday, November 19, 2009

XML Error- A semi colon character was expected. Error processing resource –

1) XML Error: A semi colon character was expected. Error processing resource –

Error Description:

While  viewing  the xml file in a web browser, sometimes an error "A semi colon character was expected." Occurs.

Example of a  XML snippet  that throws this error:

<NODES>

<NODE Caption="Ext Link" Link Name="http://google.com/ccc?key=0AEeVE& hl=en" />

</NODES>

Reason:

This occurs when using external links on the XSLT sheet which contains the character “&”.

Solution:

The work around is to simply replace every instance of & in the link with &amp;

<NODES>

<NODE Caption="Ext Link" Link Name="http://google.com/ccc?key=0AEeVE&amp;hl=en" />

</NODES>

Friday, October 2, 2009

Manipulating XML Data Using DataSet Class

This article describes how to use a windows form in VB.NET to manage data in XML files. The code snippets in this article demonstrate inserting, updating, and deleting row entries from an XML data file that has been loaded into the DataSet class using the ReadXML method. This article also demonstrates how to display the data from the XML file.

I Use DataGridView to list the XML File and each row of DataGridView contains two buttons EDIT and DELETE for the purpose of updating and deleting XML File

Sample XML File


For the examples in this article, I use the TestXML.xml.


<?xml version="1.0" standalone="yes" ?>

-
<NODES>

-
<Details>


<ID>1</ID>


<Name>Mr.XX</Name>


<Age>28</Age>


<DOJ>12/29/2006</DOJ>


</Details>

-
<Details>


<ID>2</ID>


<Name>MR.YY</Name>


<Age>27</Age>


<DOJ>9/16/2009</DOJ>


</Details>

-
<Details>


<ID>3</ID>


<Name>Ram</Name>


<Age>29</Age>


<DOJ>10/2/2009</DOJ>


</Details>


</NODES>


You'll need the following namespaces in the VB.NET code for execution:

Imports System.Xml

Reading XML into a DataSet

.NET provides the DataSet class with methods that read and parse an XML file for access within code.

The following code snippet illustrates the XMLRead and XMLWrite methods from the DataSet class

Dim ds As New DataSet

Try

ds.ReadXml("C:\Documents\TestXML.xml")

ds.WriteXml("C:\Documents\TestXML.xml")


Catch ex As Exception

MsgBox(ex.Message)


End Try


The DataSet class contains an array of rows, each row called Details with Four columns called ID , Name, Age and DOJ.

Listing Data

If you want to list the contents of the DataSet in the same order as the XML file, use the following code:


Try

ds.ReadXml("C:\Viji\Documents\TestXML.xml")


Catch ex As Exception

MsgBox(ex.Message)


Exit Sub


End

Try


DataGridView1.Columns.Clear()

DataGridView1.DataSource = Nothing



If Not ds Is Nothing Then

DataGridView1.DataSource = ds.Tables(0)


End If



If DataGridView1.Rows.Count > 0 Then


Dim dgButtoncol As
New DataGridViewButtonColumn

dgButtoncol.UseColumnTextForButtonValue = True


dgButtoncol.HeaderText = "View"

dgButtoncol.Text = "View"

dgButtoncol.Name = "View"

DataGridView1.Columns.Add(dgButtoncol)


dgButtoncol = New DataGridViewButtonColumn

dgButtoncol.UseColumnTextForButtonValue = True

dgButtoncol.HeaderText = "Edit"

dgButtoncol.Text = "Edit"

dgButtoncol.Name = "Edit"

DataGridView1.Columns.Add(dgButtoncol)



dgButtoncol = New DataGridViewButtonColumn

dgButtoncol.UseColumnTextForButtonValue = True

dgButtoncol.HeaderText = "Delete"

dgButtoncol.Text = "Delete"

dgButtoncol.Name = "Delete"

DataGridView1.Columns.Add(dgButtoncol)

End If


Inserting Data

The following code sample shows how to insert a new row into the DataSet:


Try


Dim ID As String


ID = ds.Tables(0).Rows.Count + 1



Dim dr As DataRow = ds.Tables(0).NewRow

dr("ID") = ID

dr("Name") = txtName.Text.Trim

dr("Age") = txtAge.Text.Trim

dr("DOJ") = DateTimePicker1.Value.ToShortDateString


ds.Tables(0).Rows.Add(dr)


ds.WriteXml("C:\Documents\TestXML.xml")


Catch ex As Exception

MsgBox(ex.Message)


End Try


Where txtName, txtAge (text boxes) and DateTimePicker1 controls are used to let the user enter new value.


Updating Data

To update a row in the DataSet, you must locate the row and update the fields within the row. A key field must be selected and searched, using the value of the field prior to the change, to locate the correct row for update. For this example the "ID" field is used as the key field.

If the Name of the ID 1, MR.XX should have been Mr.XXX, here is an example of how you could change it:


Try


If Not ds Is Nothing Then


For
Each dr As DataRow In ds.Tables(0).Rows


Dim ID As String = Convert.ToString(dr("ID"))



If ID = txtID.Text Then


dr("Name") = txtName.Text.Trim

dr("Age") = txtAge.Text.Trim

dr("DOJ") = DateTimePicker1.Value.ToShortDateString


Exit For


End If


Next


ds.WriteXml("C:\Documents\TestXML.xml")

End If

Catch ex As Exception

MsgBox(ex.Message)


End Try


Deleting Data

To delete the Mr.XX Data , a key field must be selected and searched, using the value of the field prior to the delete, to locate the correct row for removal. For this example the "ID" field is used again as the key field. Use the following code:

'I clicked on DataGridView Delete Button

Dim ID As String = sender.Rows(e.RowIndex).Cells("ID").Value.ToString.Trim



For Each dr As DataRow In ds.Tables(0).Rows


Dim rowID As String = Convert.ToString(dr("ID"))


If ID = rowID Then

dr.Delete()


Exit For


End If


Next

ds.WriteXml("C:\Viji\Documents\TestXML.xml")


This article has explained the concepts of editing, updating and deleting records from XML File using Dataset.