Pergunta

I have this line of code that retrieves and XML file and saves it to an SPFile

SPFile XMLFile = SPContext.Current.Web.GetFile("C:\\Users\\maleem\\Documents\\XMLTest.xml");

I want to get the XML/Text within it and output it to a literal, I tried

StreamReader  reader = new StreamReader(XMLFile.OpenBinaryStream());

And a few variants but its not working.

Foi útil?

Solução

If you use the OpenBinary method of SPFile the return is a byte array you can then convert it into a string.

Depending on the encoding you can try this:

For default encoding:

string str = System.Text.Encoding.Default.GetString(XMLFile.OpenBinary());

For UTF8:

string str = System.Text.Encoding.UTF8.GetString(XMLFile.OpenBinary());
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top