本文介绍了如何检查XML文件是否有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用.Net 4.0框架,ASP.NET 4.0。
如何通过使用文件上传来检查上传文件是否是有效的XML文件control?
Im using .Net 4.0 framework, ASP.NET 4.0.
How to check whether the uploading file is a valid XML file while uploading it by using file upload control?
推荐答案
XElement element;
TRY
{
element=XElement.Load(filename);
-- Add code to updload file here
--Because if you reach here then it meant your file successfully
}
CATCH (exception ex)
{
-- Do not upload file and write code to handle invalid XML file
}
阅读本文以获取更多信息
[]
---希望这有助于
Read this for more information
http://blogs.msdn.com/b/mcsuksoldev/archive/2010/02/04/dynamic-xml-reader-with-c-and-net-4-0.aspx[^]
---Hope this helps
这篇关于如何检查XML文件是否有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!