Вопрос

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.

Это было полезно?

Решение

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());
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top