Sunday, October 12, 2008

.NET Directory Notes

The documentation for the XmlWriter.Create Method (string) function has ArgumentNullException as the only exception that will be thrown for this function. I've found that System.IO.DirectoryNotFoundException can also be thrown here.

The AppDomain.CurrentDomain.BaseDirectory does not terminate with a back slash if you are running a unit test - you need to add this if you're going to append further directories. To make the using of AppDomain.CurrentDomain.BaseDirectory work in both unit tests and production code you might want to create a property to access the AppDomain.CurrentDomain.BaseDirectory that looks something like this:

string SafeBaseDirectory
                return AppDomain.CurrentDomain.BaseDirectory.EndsWith(@"\") ? 
                                AppDomain.CurrentDomain.BaseDirectory :
                                AppDomain.CurrentDomain.BaseDirectory + @"\";

No comments:

Post a Comment