简体   繁体   中英

C# cant read xml in dataset

I just figuered out how to read my XML in the dataset. Everything worked fine and after I started with encryption and decryption the ReadXML stopped working.

FTP.DownloadFile();
DataSet dataSet = new DataSet();
String encrypted = File.ReadAllText(Path.GetTempPath() + "\\lagerbestand.xml");
//String decrypted = StringCipher.DecryptString(encrypted, "XXXXX");
//MessageBox.Show(decrypted);
dataSet.ReadXml(encrypted);
dataGridView.DataSource = dataSet.Tables[0];

The dataSet.ReadXML(encrypted); gives me an exception.

Illegal letters in the path.

The path is correct, the String encrypted is also filled. The encrypted String looks like the following:

"<NewDataSet>\r\n  <Table1>\r\n    <Artikelname>1</Artikelname>\r\n    <Artikelnummer>2</Artikelnummer>\r\n    <Lieferant>3</Lieferant>\r\n    <Bestand>4</Bestand>\r\n    <Artikelbeschreibung>5</Artikelbeschreibung>\r\n    <Min-Lagermenge>6</Min-Lagermenge>\r\n    <Einkauf>7</Einkauf>\r\n    <Verkauf>8</Verkauf>\r\n  </Table1>\r\n</NewDataSet>"

The method expects a file path not the actual xml.

See: https://docs.microsoft.com/en-us/dotnet/api/system.data.dataset.readxml?view=netframework-4.8

This should work:

dataSet.ReadXML(Path.GetTempPath() + "\\lagerbestand.xml");

ReadXML expects a file path

You should try this way

DataSet dataSet = new DataSet();
String encrypted = File.ReadAllText(Path.GetTempPath() + "\\lagerbestand.xml");
//String decrypted = StringCipher.DecryptString(encrypted, "BeRo-0sT:De0asdnjkinu786*!");
//MessageBox.Show(decrypted);
StringReader sr = new StringReader(encrypted);
dataSet.ReadXml(sr);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM