Monday, July 23, 2012

Illegal characters in path (XmlDocument.Load())

This occurs due to not understanding the expected parameter type for the XmlDocument.Load("filename") method. This method expect a file name.

Look at the following example, this throw the above error.

eg:
//getting a soap response
string sXml = nc.CurrencyExchangeRatesForWeb();
XmlDocument doc = new XmlDocument();
doc.Load(sXml);

To avoid this error, we can use XmlDocument.LoadXml("string") method, following example shows the solution,

eg:
string sXml = nc.CurrencyExchangeRatesForWeb();
XmlDocument doc = new XmlDocument();
doc.LoadXml(sXml);

Happy coding
Tuesday, July 17, 2012

Get File Name from path string

I have seen many young developers are struggle with getting
the only the file name from the full path.

Here is a simple code snippet to get the file name.

string path = "C:\\TEMP\\temp.bmp";
string fileName = System.IO.Path.GetFileName(path);

Happy coding.

My Achievements

Member of

Blog Archive

Followers

free counters