Indicate file in a string

Asked

Viewed 24 times

0

I am developing a site in . NET Core Razor Pages. How can I make a file indicate to a variable? For example:

var xml = (~/MenuXML/menu.xml);

OBS: I need it to be string, the file data.

Motive: I’m trying to turn it into JSON. The code I’m using is following:

var xml = (~/MenuXML/menu.xml);

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);

HttpContext.Session.SetString("xmltojson", json);

1 answer

0

Well, I know this question isn’t long ago, but I did a little bit more research and I figured out a way to do that, so if anyone needs it, I’ll leave it here in the answers.

var xml = System.IO.File.ReadAllText(@"C:\ArquivoXML\arquivo.Xml");
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);
HttpContext.Session.SetString("xmltojson", json);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.