XmlZipResolver
An XmlUrlResolver for files in a zip file
In the java world a file you can pass a filename of "zip:MyStuff.zip!MyData.xml" and it then handles the MyData.xml file as the xml file to read. The attached file here does the same thing on the .NET side by providing a XmlUrlResolver derived class to handle this case.
This code was about 95% the code from news.oreilly.com/XmlZipResolver.cs where I cleaned it up a little and fixed a couple of subtle bugs.
Just use this class instead of XmlUrlResolver. You can use it for all cases because it calls XmlUrlResolver if the url does not start with zip: or jar:. Hopefully Microsoft will just add this in to XmlUrlResolver in the future.
Download: XmlZipResolver
XmlFileOpen
Opening an XML file that requires a username & password
So you need to open an XML file in .NET and it has a username & password. So piece of cake, you just use XmlUrlResolver.Credentials except... that only works if it's an http or ftp url that requires a username & password.
But what if it's a share on a network drive that requires a username & password to access the file? That gets complicated. Is your app running on a workgroup login or a domain login? Is the file one a workgroup or domain? Is it the same domain? Are the required credentials a user on that machine or a domain user? Or are the permissions a domain group which requires a domain user set of credentials?
Each of those combinations requires a different way of accessing the file. And a couple of combinations are impossible to access, even though "net use" can do it. This is definitely a place where I think Microsoft decided it was too hard to do and so gave up.
And if you find ways to implement some of the remaining (very rare) combinations, please post a comment.
Download: XmlFileOpen.cs


Good to know,and very concise. thanks
Posted by: ben logan | 12/01/2009 at 10:44 AM