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.
Delete() method takes the full path (absolute path including the file name) of the file to be deleted. If file does not exist, no exception is thrown. The following code snippet deletes a file, Authors. txt stored in C:\Temp\Data\ folder.
Remarks. A path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk; for example, a path might map to a location in memory or on a device. The exact format of a path is determined by the current platform.
string path = new Uri(Assembly.GetAssembly(typeof(MyClass)).CodeBase).LocalPath;
If you want the directory of the assembly of that class, you could use the Assembly.Location
property:
string path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MyClass)).Location);
This isn't exactly the same as the CodeBase
property, though. The Location
is the "path or UNC location of the loaded file that contains the manifest" whereas the CodeBase
is the " location of the assembly as specified originally, for example, in an AssemblyName object".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With