Added support for downloading input files directly from the web.

This commit is contained in:
the_fiddler 2010-10-14 20:14:27 +00:00
parent 20dbff2b88
commit 2ab2af9e95

View file

@ -23,6 +23,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net;
using System.Xml.Linq; using System.Xml.Linq;
namespace CHeaderToXML namespace CHeaderToXML
@ -41,7 +42,25 @@ namespace CHeaderToXML
public IEnumerable<XElement> Parse(string path) public IEnumerable<XElement> Parse(string path)
{ {
return Parse(File.ReadAllLines(path)); string[] contents = null;
if (path.StartsWith("http://") || path.StartsWith("https://"))
{
// Download from the specified url into a temporary file
using (var wb = new WebClient())
{
string filename = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
wb.DownloadFile(path, filename);
contents = File.ReadAllLines(filename);
File.Delete(filename);
}
}
else
{
// The file is on disk, just read it directly
contents = File.ReadAllLines(path);
}
return Parse(contents);
} }
} }
} }