A Alan T Jul 27, 2006 #1 I got a string. eg. C:\Temp\Documents\MyDoc.doc How do I get the name of the document only? ie. MyDoc.doc
I got a string. eg. C:\Temp\Documents\MyDoc.doc How do I get the name of the document only? ie. MyDoc.doc
J Jianwei Sun Jul 27, 2006 #2 Alan said: I got a string. eg. C:\Temp\Documents\MyDoc.doc How do I get the name of the document only? ie. MyDoc.doc Click to expand... Try this: using System.IO; FileInfo fileInfo = new FileInfo(fileName); string nameWithoutPath=fileInfo.Name.
Alan said: I got a string. eg. C:\Temp\Documents\MyDoc.doc How do I get the name of the document only? ie. MyDoc.doc Click to expand... Try this: using System.IO; FileInfo fileInfo = new FileInfo(fileName); string nameWithoutPath=fileInfo.Name.
N Nicholas Paldino [.NET/C# MVP] Jul 27, 2006 #3 Jianwei, That's a bit much, actually. I would recommend using the static GetFileName method on the Path class in the System.IO namespace. Hope this helps.
Jianwei, That's a bit much, actually. I would recommend using the static GetFileName method on the Path class in the System.IO namespace. Hope this helps.
A Alan T Jul 27, 2006 #4 Thanks, it works. After I got the name, how do I get rid of the extension ? Eg. MyDoc.doc to MyDoc
N Nicholas Paldino [.NET/C# MVP] Jul 27, 2006 #5 Alan, You can pass the file name to the static GetFileNameWithoutExtension method on the Path class. Hope this helps.
Alan, You can pass the file name to the static GetFileNameWithoutExtension method on the Path class. Hope this helps.