string path = Path.GetDirectoryName(
Assembly.GetAssembly(typeof(MyClass)).CodeBase);
output:
file:\d:\learning\cs\test\test.xml
What’s the best way to return only d:\learning\cs\test\test.xml
file:\\ will throw exception when I call doc.Save(returnPath) ,however doc.Load(returnPath); works well. Thank you.
If you want the directory of the assembly of that class, you could use the
Assembly.Locationproperty:This isn’t exactly the same as the
CodeBaseproperty, though. TheLocationis the “path or UNC location of the loaded file that contains the manifest” whereas theCodeBaseis the ” location of the assembly as specified originally, for example, in an AssemblyName object”.