xml is just a text file. without validating, it hard to tell xml from html which uses a similar syntax (but html does not need to be valid xml). The XmlReader is probably a better approach (you would not need to read the whole file).
Detect xml file type without extension
Hello
As file suggests, user can select any file, and some of them might be with no extension, I will use a content analyzer sdk to handle different situations, but there's one extension that the sdk does not support: .xml
I'm aware of using XmlDocument to .Load the .xml and check for exception, but is there another path to check the file signature/content without loading the whole file? I mean reading the mime header or something like that?
Thanks
2 answers
Sort by: Most helpful
-
-
Fabricio Oliveira 1 Reputation point
2022-11-15T22:29:46.353+00:00 Hi.
You can try the Mime Detective (https://github.com/MediatedCommunications/Mime-Detective)
it's a nuget package to get mimetype from filecontent.