Saving the Folder Name in File Open and Save Dialog Box

We can save the Directory name in the File Save Dialog Box, that means when we next time open the Dialog box we can see the Folder name which we have previously opend..

This can be Done by Setting the Registry values.. for this wee need to Include the Microsoft.Win32 name header files in our application

the Above code having the Text box name where we have to display the File Name and the Save file dialog box name..

RegistryKey regKey = Registry.CurrentUser;

regKey = regKey.CreateSubKey("Software\\Test\\EnvVar");

string strTmp = regKey.GetValue("TargetFolder", "").ToString();

SaveFileDialog myDialog = new SaveFileDialog();

myDialog.InitialDirectory = strTmp;

myDialog.Filter = "Excel Files (*.xls)|*.xls";
myDialog.FilterIndex = 1;
myDialog.RestoreDirectory = true;

if (myDialog.ShowDialog() == DialogResult.OK)
regKey.SetValue("TargetFolder", txtFileName.Text);

txtFileName.Text = myDialog.FileName;
btnGo.Enabled = true;

Anil Pandey


Author: shekhar10 Mar 2009 Member Level: Gold   Points : 1

Hi Frnd

really its very good article plz keep post such article

Thanks a lot

Shekhar Kadam

Author: Anil Kumar Pandey27 Mar 2009 Member Level: Diamond   Points : 0


Thanks for thew compliment...

i will try to post more

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: