I want to split this text in to 2 parts with C#.Net windows application.
C:\Users\Microsoft\Pictures\2010-04-22\003.jpg
First part: C:\Users\Microsoft\Pictures\2010-04-22\
Second part: 003.jpg
Thanks.
I want to split this text in to 2 parts with C#.Net windows application.
C:\Users\Microsoft\Pictures\2010-04-22\003.jpg
First part: C:\Users\Microsoft\Pictures\2010-04-22\
Second part: 003.jpg
Thanks.
var name = new FileInfo(@"C:\Users\Microsoft\Pictures\2010-04-22\003.jpg").Name;
If you are working with files and paths, use FileInfo:
System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\Users\Microsoft\Pictures\2010-04-22\003.jpg
");
string dir = f.DirectoryName;
string file = f.Name;
Or, as Marcelo Cantos says, you can use System.IO.Path. Using Reflector you can see that FileInfo.Directory name calls Path.GetDirectoryName(base.FullPath) so it's very much the same
Use the System.IO.Path class:
Path.GetDirectoryName(path);
Path.GetFileName(path);