Help need in OpenFileDialog
-
Hi, using openfiledialog to select a particular file and store the selected file name in a string it sores the filename with path so is there any way to store only the file name not the whole path? Thanks
-
Hi, using openfiledialog to select a particular file and store the selected file name in a string it sores the filename with path so is there any way to store only the file name not the whole path? Thanks
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
There is no method called getfilename !! see I have this below OpenFileDialog select_file = new OpenFileDialog(); select_file.Title = "selected file"; select_file.Filter = "(*.txt) | *.txt"; if (select_file.ShowDialog() != DialogResult.Cancel) { file = select_file.FileName; // stores whole path with file name } but i want only selected file name in file not the path .
-
There is no method called getfilename !! see I have this below OpenFileDialog select_file = new OpenFileDialog(); select_file.Title = "selected file"; select_file.Filter = "(*.txt) | *.txt"; if (select_file.ShowDialog() != DialogResult.Cancel) { file = select_file.FileName; // stores whole path with file name } but i want only selected file name in file not the path .
-
There is no method called getfilename !! see I have this below OpenFileDialog select_file = new OpenFileDialog(); select_file.Title = "selected file"; select_file.Filter = "(*.txt) | *.txt"; if (select_file.ShowDialog() != DialogResult.Cancel) { file = select_file.FileName; // stores whole path with file name } but i want only selected file name in file not the path .
Did you actually click on the link you were provided with? Changing just 1 line of your code would get you what you want! Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
-
There is no method called getfilename !! see I have this below OpenFileDialog select_file = new OpenFileDialog(); select_file.Title = "selected file"; select_file.Filter = "(*.txt) | *.txt"; if (select_file.ShowDialog() != DialogResult.Cancel) { file = select_file.FileName; // stores whole path with file name } but i want only selected file name in file not the path .
well... I use a little longer way, but I think there is a shorter way, but I don't know it... so here is my way:
file = select_file.FileName.Substring(select_file.FileName.LastIndexOf("\\") + 1, select_file.FileName.Length - select_file.FileName.LastIndexOf("\\") - 5); // -5 = -4 - 3 letters of ending (you can cancel that if you want the ending) and 1 dot, and -1 - for the +1 we do in the first parameter to cancel the \ in the start.
---- modified ---- the other way is better (as they told you here). if you didn't see the examples so look here:file = System.IO.Path.GetFileName(select_file.FileName); // Will retrive the file's name with extension file = System.IO.Path.GetFileNameWithoutExtension(select_file.FileName); // Will retrive the file's name with out extension
-- modified at 4:12 Friday 12th May, 2006 -
well... I use a little longer way, but I think there is a shorter way, but I don't know it... so here is my way:
file = select_file.FileName.Substring(select_file.FileName.LastIndexOf("\\") + 1, select_file.FileName.Length - select_file.FileName.LastIndexOf("\\") - 5); // -5 = -4 - 3 letters of ending (you can cancel that if you want the ending) and 1 dot, and -1 - for the +1 we do in the first parameter to cancel the \ in the start.
---- modified ---- the other way is better (as they told you here). if you didn't see the examples so look here:file = System.IO.Path.GetFileName(select_file.FileName); // Will retrive the file's name with extension file = System.IO.Path.GetFileNameWithoutExtension(select_file.FileName); // Will retrive the file's name with out extension
-- modified at 4:12 Friday 12th May, 2006Yes, and it is
file = Path.GetFileName(select_file.FileName);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
There is no method called getfilename !! see I have this below OpenFileDialog select_file = new OpenFileDialog(); select_file.Title = "selected file"; select_file.Filter = "(*.txt) | *.txt"; if (select_file.ShowDialog() != DialogResult.Cancel) { file = select_file.FileName; // stores whole path with file name } but i want only selected file name in file not the path .
Use the method I suggested:
file = Path.GetFileName(select_file.FileName);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de -- modified at 4:16 Friday 12th May, 2006
-
Hi, using openfiledialog to select a particular file and store the selected file name in a string it sores the filename with path so is there any way to store only the file name not the whole path? Thanks
Hi; this is simplest code u can use to get file name;first u have to import System.IO namespace. string path=openfiledialog1.PostedFile.FileName; string filename=Path.GetFileName(path); Response.Write(filename); it will work fine. with regards Nikesh Sahu nikesh
-
Hi; this is simplest code u can use to get file name;first u have to import System.IO namespace. string path=openfiledialog1.PostedFile.FileName; string filename=Path.GetFileName(path); Response.Write(filename); it will work fine. with regards Nikesh Sahu nikesh
:omg::wtf: That would be a good answer if the poster had asked about ASP.NET Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour