How to get temporary filename when use OpenFileDialog in C# Winform










-2















In C#-WinForms I use a OpenFileDialog. I want to get all files/filenames in a selected folder, without pressing the ok button of the OpenFileDialog.



Is there a good way to achieve this?










share|improve this question
























  • It's strange to get the (not by the user confirmed) selected filename. Probably not.

    – J. van Langen
    Nov 15 '18 at 8:53











  • Really, Any way ?

    – Paul
    Nov 15 '18 at 8:57






  • 1





    Hi Paul, welcome to so! Can you please consider editing your question so that it is easier for people to answer, perhaps providing some code you have already tried and is not working for example. At the moment I don't think your question is clear enough to answer.

    – Kodaloid
    Nov 15 '18 at 8:57






  • 2





    What "code example" do you expect in this situation? Code reading the files after they have been selected? The OP is asking how to read the filenames before the users hits the "ok" button.

    – kajacx
    Nov 15 '18 at 9:16






  • 1





    It is a dialog, it won't complete and won't tell you what was selected until you click OK. Necessarily so, a selected file can be unselected again. So what you want is not in the cards. It has a FileOk event that fires early when the user selects a file, it is meant to prevent selection. Whether that is what you want is not at all clear from the question.

    – Hans Passant
    Nov 15 '18 at 9:50















-2















In C#-WinForms I use a OpenFileDialog. I want to get all files/filenames in a selected folder, without pressing the ok button of the OpenFileDialog.



Is there a good way to achieve this?










share|improve this question
























  • It's strange to get the (not by the user confirmed) selected filename. Probably not.

    – J. van Langen
    Nov 15 '18 at 8:53











  • Really, Any way ?

    – Paul
    Nov 15 '18 at 8:57






  • 1





    Hi Paul, welcome to so! Can you please consider editing your question so that it is easier for people to answer, perhaps providing some code you have already tried and is not working for example. At the moment I don't think your question is clear enough to answer.

    – Kodaloid
    Nov 15 '18 at 8:57






  • 2





    What "code example" do you expect in this situation? Code reading the files after they have been selected? The OP is asking how to read the filenames before the users hits the "ok" button.

    – kajacx
    Nov 15 '18 at 9:16






  • 1





    It is a dialog, it won't complete and won't tell you what was selected until you click OK. Necessarily so, a selected file can be unselected again. So what you want is not in the cards. It has a FileOk event that fires early when the user selects a file, it is meant to prevent selection. Whether that is what you want is not at all clear from the question.

    – Hans Passant
    Nov 15 '18 at 9:50













-2












-2








-2








In C#-WinForms I use a OpenFileDialog. I want to get all files/filenames in a selected folder, without pressing the ok button of the OpenFileDialog.



Is there a good way to achieve this?










share|improve this question
















In C#-WinForms I use a OpenFileDialog. I want to get all files/filenames in a selected folder, without pressing the ok button of the OpenFileDialog.



Is there a good way to achieve this?







c#






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 10:16









jps

3,75362037




3,75362037










asked Nov 15 '18 at 8:50









PaulPaul

2




2












  • It's strange to get the (not by the user confirmed) selected filename. Probably not.

    – J. van Langen
    Nov 15 '18 at 8:53











  • Really, Any way ?

    – Paul
    Nov 15 '18 at 8:57






  • 1





    Hi Paul, welcome to so! Can you please consider editing your question so that it is easier for people to answer, perhaps providing some code you have already tried and is not working for example. At the moment I don't think your question is clear enough to answer.

    – Kodaloid
    Nov 15 '18 at 8:57






  • 2





    What "code example" do you expect in this situation? Code reading the files after they have been selected? The OP is asking how to read the filenames before the users hits the "ok" button.

    – kajacx
    Nov 15 '18 at 9:16






  • 1





    It is a dialog, it won't complete and won't tell you what was selected until you click OK. Necessarily so, a selected file can be unselected again. So what you want is not in the cards. It has a FileOk event that fires early when the user selects a file, it is meant to prevent selection. Whether that is what you want is not at all clear from the question.

    – Hans Passant
    Nov 15 '18 at 9:50

















  • It's strange to get the (not by the user confirmed) selected filename. Probably not.

    – J. van Langen
    Nov 15 '18 at 8:53











  • Really, Any way ?

    – Paul
    Nov 15 '18 at 8:57






  • 1





    Hi Paul, welcome to so! Can you please consider editing your question so that it is easier for people to answer, perhaps providing some code you have already tried and is not working for example. At the moment I don't think your question is clear enough to answer.

    – Kodaloid
    Nov 15 '18 at 8:57






  • 2





    What "code example" do you expect in this situation? Code reading the files after they have been selected? The OP is asking how to read the filenames before the users hits the "ok" button.

    – kajacx
    Nov 15 '18 at 9:16






  • 1





    It is a dialog, it won't complete and won't tell you what was selected until you click OK. Necessarily so, a selected file can be unselected again. So what you want is not in the cards. It has a FileOk event that fires early when the user selects a file, it is meant to prevent selection. Whether that is what you want is not at all clear from the question.

    – Hans Passant
    Nov 15 '18 at 9:50
















It's strange to get the (not by the user confirmed) selected filename. Probably not.

– J. van Langen
Nov 15 '18 at 8:53





It's strange to get the (not by the user confirmed) selected filename. Probably not.

– J. van Langen
Nov 15 '18 at 8:53













Really, Any way ?

– Paul
Nov 15 '18 at 8:57





Really, Any way ?

– Paul
Nov 15 '18 at 8:57




1




1





Hi Paul, welcome to so! Can you please consider editing your question so that it is easier for people to answer, perhaps providing some code you have already tried and is not working for example. At the moment I don't think your question is clear enough to answer.

– Kodaloid
Nov 15 '18 at 8:57





Hi Paul, welcome to so! Can you please consider editing your question so that it is easier for people to answer, perhaps providing some code you have already tried and is not working for example. At the moment I don't think your question is clear enough to answer.

– Kodaloid
Nov 15 '18 at 8:57




2




2





What "code example" do you expect in this situation? Code reading the files after they have been selected? The OP is asking how to read the filenames before the users hits the "ok" button.

– kajacx
Nov 15 '18 at 9:16





What "code example" do you expect in this situation? Code reading the files after they have been selected? The OP is asking how to read the filenames before the users hits the "ok" button.

– kajacx
Nov 15 '18 at 9:16




1




1





It is a dialog, it won't complete and won't tell you what was selected until you click OK. Necessarily so, a selected file can be unselected again. So what you want is not in the cards. It has a FileOk event that fires early when the user selects a file, it is meant to prevent selection. Whether that is what you want is not at all clear from the question.

– Hans Passant
Nov 15 '18 at 9:50





It is a dialog, it won't complete and won't tell you what was selected until you click OK. Necessarily so, a selected file can be unselected again. So what you want is not in the cards. It has a FileOk event that fires early when the user selects a file, it is meant to prevent selection. Whether that is what you want is not at all clear from the question.

– Hans Passant
Nov 15 '18 at 9:50












1 Answer
1






active

oldest

votes


















0














if i understood your question in the right way, you want to get the Filenames out of your selected folder. To archive that, you could use a FolderBrowserDialog.



FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
if(folderBrowser.ShowDialog() == DialogResult.OK)

var path = folderBrowser.SelectedPath;
System.Windows.IO.DirectoryInfo info = new System.Windows.IO.DirectoryInfo(path);
foreach(var file in info.GetFiles())

//do what you want with your files.
//example
listbox1.Items.Add(file.Name);




If you got some further question, feel free to ask.



-- EDIT --



Ok now i understood what you mean.



You want to get the files out of a folder when clicking on it.
Maybe build your own dialog (simple new window). With a treeview on it. And if you click on a treeviewitem, on ther other side it displays you the files and subfolder.



enter image description here






share|improve this answer

























  • Hi Hendrik, All dialogs return selected path after click on button OK. But I want to get name selected path before click on button OK

    – Paul
    Nov 16 '18 at 2:28











  • The easiest way would be to create a new dialog your self as i mentoined in my edit. Just create a new Window with a treeview oder maybe two treeviews. One on the left the other one on the right, same like windows explorer layout.

    – Hendrik Roskamp
    Nov 16 '18 at 8:16











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315523%2fhow-to-get-temporary-filename-when-use-openfiledialog-in-c-sharp-winform%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














if i understood your question in the right way, you want to get the Filenames out of your selected folder. To archive that, you could use a FolderBrowserDialog.



FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
if(folderBrowser.ShowDialog() == DialogResult.OK)

var path = folderBrowser.SelectedPath;
System.Windows.IO.DirectoryInfo info = new System.Windows.IO.DirectoryInfo(path);
foreach(var file in info.GetFiles())

//do what you want with your files.
//example
listbox1.Items.Add(file.Name);




If you got some further question, feel free to ask.



-- EDIT --



Ok now i understood what you mean.



You want to get the files out of a folder when clicking on it.
Maybe build your own dialog (simple new window). With a treeview on it. And if you click on a treeviewitem, on ther other side it displays you the files and subfolder.



enter image description here






share|improve this answer

























  • Hi Hendrik, All dialogs return selected path after click on button OK. But I want to get name selected path before click on button OK

    – Paul
    Nov 16 '18 at 2:28











  • The easiest way would be to create a new dialog your self as i mentoined in my edit. Just create a new Window with a treeview oder maybe two treeviews. One on the left the other one on the right, same like windows explorer layout.

    – Hendrik Roskamp
    Nov 16 '18 at 8:16
















0














if i understood your question in the right way, you want to get the Filenames out of your selected folder. To archive that, you could use a FolderBrowserDialog.



FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
if(folderBrowser.ShowDialog() == DialogResult.OK)

var path = folderBrowser.SelectedPath;
System.Windows.IO.DirectoryInfo info = new System.Windows.IO.DirectoryInfo(path);
foreach(var file in info.GetFiles())

//do what you want with your files.
//example
listbox1.Items.Add(file.Name);




If you got some further question, feel free to ask.



-- EDIT --



Ok now i understood what you mean.



You want to get the files out of a folder when clicking on it.
Maybe build your own dialog (simple new window). With a treeview on it. And if you click on a treeviewitem, on ther other side it displays you the files and subfolder.



enter image description here






share|improve this answer

























  • Hi Hendrik, All dialogs return selected path after click on button OK. But I want to get name selected path before click on button OK

    – Paul
    Nov 16 '18 at 2:28











  • The easiest way would be to create a new dialog your self as i mentoined in my edit. Just create a new Window with a treeview oder maybe two treeviews. One on the left the other one on the right, same like windows explorer layout.

    – Hendrik Roskamp
    Nov 16 '18 at 8:16














0












0








0







if i understood your question in the right way, you want to get the Filenames out of your selected folder. To archive that, you could use a FolderBrowserDialog.



FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
if(folderBrowser.ShowDialog() == DialogResult.OK)

var path = folderBrowser.SelectedPath;
System.Windows.IO.DirectoryInfo info = new System.Windows.IO.DirectoryInfo(path);
foreach(var file in info.GetFiles())

//do what you want with your files.
//example
listbox1.Items.Add(file.Name);




If you got some further question, feel free to ask.



-- EDIT --



Ok now i understood what you mean.



You want to get the files out of a folder when clicking on it.
Maybe build your own dialog (simple new window). With a treeview on it. And if you click on a treeviewitem, on ther other side it displays you the files and subfolder.



enter image description here






share|improve this answer















if i understood your question in the right way, you want to get the Filenames out of your selected folder. To archive that, you could use a FolderBrowserDialog.



FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
if(folderBrowser.ShowDialog() == DialogResult.OK)

var path = folderBrowser.SelectedPath;
System.Windows.IO.DirectoryInfo info = new System.Windows.IO.DirectoryInfo(path);
foreach(var file in info.GetFiles())

//do what you want with your files.
//example
listbox1.Items.Add(file.Name);




If you got some further question, feel free to ask.



-- EDIT --



Ok now i understood what you mean.



You want to get the files out of a folder when clicking on it.
Maybe build your own dialog (simple new window). With a treeview on it. And if you click on a treeviewitem, on ther other side it displays you the files and subfolder.



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 9:17

























answered Nov 15 '18 at 9:10









Hendrik RoskampHendrik Roskamp

516




516












  • Hi Hendrik, All dialogs return selected path after click on button OK. But I want to get name selected path before click on button OK

    – Paul
    Nov 16 '18 at 2:28











  • The easiest way would be to create a new dialog your self as i mentoined in my edit. Just create a new Window with a treeview oder maybe two treeviews. One on the left the other one on the right, same like windows explorer layout.

    – Hendrik Roskamp
    Nov 16 '18 at 8:16


















  • Hi Hendrik, All dialogs return selected path after click on button OK. But I want to get name selected path before click on button OK

    – Paul
    Nov 16 '18 at 2:28











  • The easiest way would be to create a new dialog your self as i mentoined in my edit. Just create a new Window with a treeview oder maybe two treeviews. One on the left the other one on the right, same like windows explorer layout.

    – Hendrik Roskamp
    Nov 16 '18 at 8:16

















Hi Hendrik, All dialogs return selected path after click on button OK. But I want to get name selected path before click on button OK

– Paul
Nov 16 '18 at 2:28





Hi Hendrik, All dialogs return selected path after click on button OK. But I want to get name selected path before click on button OK

– Paul
Nov 16 '18 at 2:28













The easiest way would be to create a new dialog your self as i mentoined in my edit. Just create a new Window with a treeview oder maybe two treeviews. One on the left the other one on the right, same like windows explorer layout.

– Hendrik Roskamp
Nov 16 '18 at 8:16






The easiest way would be to create a new dialog your self as i mentoined in my edit. Just create a new Window with a treeview oder maybe two treeviews. One on the left the other one on the right, same like windows explorer layout.

– Hendrik Roskamp
Nov 16 '18 at 8:16




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315523%2fhow-to-get-temporary-filename-when-use-openfiledialog-in-c-sharp-winform%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3