Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Remebering the last saved directory path in a saveFileDialog

Posted on 2006-07-23
7
Medium Priority
?
790 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

618 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