Click here to Skip to main content
15,916,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Comments
Richard C Bishop 28-Feb-13 11:22am    
You have to upload it first and then read it to check its validity.

 
Share this answer
 
Try this

Just read this and add some more code in it

C#
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
 
Share this answer
 
v3
Comments
ravi_patsamatla 28-Feb-13 12:59pm    
i have tried the below solution but after reading the file into xelement, i need to check whether the file contains the following
1. XML version
2. !Doctype
3. check whether the file contains few folders in which i need to check some other nodes.

any help would be appreciated hugely.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900