?
Solved

Remebering the last saved directory path in a saveFileDialog

Posted on 2006-07-23
7
Medium Priority
?
784 Views
Last Modified: 2008-01-09

Hi all,

I am implementing a saveFileDialog in C# . First time when I choose a directory to save a file, I want to remember it so that for the second time , I do not have to start from my C: drive and go to the previously saved directory.

There should be a easy way to do, and your help on this is appreciated.

Ramesh
0
Comment
Question by:Ramesh4u
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 400 total points
ID: 17165107
It depends on what you call "an easy way"

I believe the easies way is to save the file (directory) path into a text or xml file.
If it's a text file you just write or read one line

public string readPath()
{
  // create reader & open file
  TextReader tr = new StreamReader("path.txt");// or (Application.StartupPath + "\\" + "path.txt")

  // read a line of text
  string path = tr.ReadLine();

  // close the stream
  tr.Close();
 
  return path;
}

You need to add error handling if no file exists (return "C:\")

public void writePath(string path)
{
  // create a writer and open the file
  TextWriter tw = new StreamWriter("path.txt"); // or (Application.StartupPath + "\\" + "path.txt")

  // write a line of text to the file
  tw.WriteLine(path);

  // close the stream
  tw.Close();

}
0
 
LVL 3

Expert Comment

by:BBK_
ID: 17165415
If you want to retain the selected directory name only till the application close, then better keep the value in a static variable,
If you want to keep this every time application opens, then better approch is to store the value in registry than in any XML or text file
0
 

Expert Comment

by:dreckgos
ID: 17165856
I think you want to find out how to set the dialog programmaticly to a specified path, am I right?

Just before showing the dialog, set the dialog.filename property to your desired directory, like this:

dialog.FileName=@"C:\";
the "@" specifies not to interpret the \ as an escape sequence.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 17172328
2 dreckgos

"then better approch is to store the value in registry than in any XML or text file"
No doubts. Give an example of code. Ramesh asked for an easy solution :)

2 Ramesh
If you want to save in the registry you may have a look at http://www.knowdotnet.com/articles/registrywrapper.html
0
 

Expert Comment

by:dreckgos
ID: 17173645
anarki, I think you got the names wrong....
0
 

Expert Comment

by:dreckgos
ID: 17173674
anarki, I think you got the names wrong....

 Dont forget Ramesh... save the directory in any way you want and then set the filename or filepath property!
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 17179979
My apologies, dreckgos!

The message was to BBK.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question