How to open an xml using c# and datagridview?

Viewed 63

I managed to open an xml that was saved on my PC for test purposes or to display it with the datagridview, but this does not work with an xml that is on an external server. Do I have to change something in my code or what could be the problem? Thanks in advance! :) with following code:

 private void button1_Click(object sender, EventArgs e)
    {
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(@"test.xml");
        dataGridView1.DataSource = dataSet.Tables[0];
    }
1 Answers
private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            XmlReader xmlFile;
            xmlFile = XmlReader.Create("/test.xml", new XmlReaderSettings());
            DataSet ds = new DataSet();
            ds.ReadXml(xmlFile);
            dataGridView1.DataSource = ds.Tables[0];
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
Related