tags:

views:

60

answers:

3

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.

+1  A: 
var name = new FileInfo(@"C:\Users\Microsoft\Pictures\2010-04-22\003.jpg").Name;
Darin Dimitrov
you're only answering half the question
Rune FS
+7  A: 

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

edosoft
+6  A: 

Use the System.IO.Path class:

Path.GetDirectoryName(path);
Path.GetFileName(path);
Marcelo Cantos