c# - Parse an xml file by knowing its folder is in -


i'm working on project , need parse xml files knowing folder in, not files name. in folder there 1 file.

i'd never assume folder contains single file, , wouldn't assume folder contains xml files. people can manipulate folders, know :-)

that's why i'd enumerate files in folder, single out files have .xml extension , parse them follows:

string[] allfiles = directory.getfiles(thefoldername); foreach (string filename in allfiles) {     if (path.getextension(filename).equals(".xml", stringcomparison.invariantcultureignorecase))     {         parsexmlfile(filename);     } } 

and parsexmlfile method looks this:

private void parsexmlfile(string file) {     xmldocument doc = new xmldocument();     doc.load(file);     // continue processing content     // ... } 

please note though file has .xml extension doesn't mean is valid xml file, please add error handling above code.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -