I have a full path as given below.
C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug\DannyGoXuk.DTDs.xhtml-math-svg-flat.dtd
How can the DTDs "part" to be fetched from this whole part?
Desired output:
C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug\DannyGoXuk.DTDs
Can I use String
's methods for this?
If yes, then how to fetch it?
To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null. Syntax: public static string GetFileName (string path);
If you specify a file name only in path , GetFullPath returns the fully qualified path of the current directory.
Use System.IO.Path.GetDirectoryName()
for the entire path, or new DirectoryInfo(path).Parent.Name
for just the name of that one folder.
There is no directory named "DTDs" in the path you posted. IT looks like there's a file named "DannyGoXuk.DTDs.xhtml-math-svg-flat.dtd"
, but the periods (.) in that path are not valid directory separator characters. Did you mean "DannyGoXuk\DTDs\xhtml-math-svg-flat.dtd"
?
If that's the case, given that entire new path, you want something like this to return a list of files in the DTDs
folder:
string path = @"C:\Users\Ronny\Desktop\Sources\Danny\kawas\trunk\csharp\ImportME\XukMe\bin\Debug\DannyGoXuk\DTDs\xhtml-math-svg-flat.dtd";
string[] files = new DirectoryInfo(path).Parent.GetFiles();
in properties window i choose Build Type as Embedded resource.
And now we finally get to it. When you choose "Embedded Resource", the item is bundled into your executable program file. There is no direct path anymore. Instead, set your Build Type to "Content" and set "Copy to Output Directory" to "Copy Always" or "Copy if Newer".
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