命名空间:
using System.IO;
using System.Xml;
方法:
bool IsXml(string Path)
{
StreamReader sr = new StreamReader(Path);
string strXml = sr.ReadToEnd();
sr.Close();
sr.Dispose();
try
{
XmlDocument xml = new XmlDocument();
xml.LoadXml(strXml);//判断是否加载成功
return true;//是xml文件,返回
}
catch
{
return false;//不是xml文件,返回
}
}
using System.IO;
using System.Xml;
方法:
bool IsXml(string Path)
{
StreamReader sr = new StreamReader(Path);
string strXml = sr.ReadToEnd();
sr.Close();
sr.Dispose();
try
{
XmlDocument xml = new XmlDocument();
xml.LoadXml(strXml);//判断是否加载成功
return true;//是xml文件,返回
}
catch
{
return false;//不是xml文件,返回
}
}