by
192 12
0
6
8,805
34
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Specified
Popularity: 608th place
This snippet is Public
.NETFramework3.5
InputName0strFile
InputType0string
LanguageCSharp
LicenseMIT_X11
MethodNameGetXmlStringFromFile
OutputTypestring

C#: Read XML file into string

This is a method to read XML file into string
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1068/C---Read-XML-file-into-string?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static string GetXmlStringFromFile(string strFile) { // Load the xml file into XmlDocument object. XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(strFile); } catch (XmlException e) { throw new GenericException("Error in GetXmlString function", e); } // Now create StringWriter object to get data from xml document. StringWriter sw = new StringWriter(); XmlTextWriter xw = new XmlTextWriter(sw); xmlDoc.WriteTo(xw); return sw.ToString(); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus