ganders Posted November 26, 2004 Posted November 26, 2004 hi the property OpenFileDialog.FileName returns the whole path of the selected file. how do i get only the filename (without the path in front)? best regards georg Quote
coldfusion244 Posted November 26, 2004 Posted November 26, 2004 The only way I know (using C#) is to find the last slash and then get all characters after that. [CS] string strFile = OpenDialog1.FileName; strFile = strFile.Substring(strFile.LastIndexOf("\")); [/CS] Using LastIndexOf("\") we find the last place the slash is used, this denotes the last directory. Everything after that is the filename and extension. So we use substring to obtain everything after that point. Quote -Sean
Administrators PlausiblyDamp Posted November 26, 2004 Administrators Posted November 26, 2004 Easiest way is probably to use the Path class. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
donnacha Posted November 26, 2004 Posted November 26, 2004 You could also set the RestoreDirectory to false and then use the current directory and parse this out of your FileName, thus giving you the file name on its own. It is a bit silly that there isin't a property that has the name on its own. Quote Hamlet
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.