473,769 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SaveFileDialog Changing Environment.Cur rentDirectory

Hello:

Correct me if I'm wrong, but it appears that saving a file with the
SaveFileDialog changes the Environment.Cur rentDirectory property.

How can I prevent this?

Thanks,
Travis
Jun 27 '08 #1
2 3961
On May 9, 1:45*pm, "jehugalea...@g mail.com" <jehugalea...@g mail.com>
wrote:
Hello:

Correct me if I'm wrong, but it appears that saving a file with the
SaveFileDialog changes the Environment.Cur rentDirectory property.

How can I prevent this?

Thanks,
Travis
Here's an example and a band-aid:

string currentDirector y = Environment.Cur rentDirectory;
try
{
string directory = "C:\\temp";
SaveFileDialog dialog = new SaveFileDialog( );
dialog.AddExten sion = true;
dialog.CreatePr ompt = false;
dialog.DefaultE xt = ".csv";
dialog.FileName = "example.cs v";
dialog.InitialD irectory = directory; // <-- Most
likely the culprit
dialog.Overwrit ePrompt = true;
dialog.SupportM ultiDottedExten sions = true;
while (dialog.ShowDia log() != DialogResult.OK )
{
MessageBox.Show ("You must select a save
file");
}
return dialog.FileName ;
}
}
finally
{
Environment.Cur rentDirectory = currentDirector y;
}
Jun 27 '08 #2
On Fri, 09 May 2008 12:45:02 -0700, je**********@gm ail.com
<je**********@g mail.comwrote:
Hello:

Correct me if I'm wrong, but it appears that saving a file with the
SaveFileDialog changes the Environment.Cur rentDirectory property.

How can I prevent this?
This has been answered before:
http://groups.google.com/groups/sear...ry&qt_s=Search

In some of the top threads related to that search, you'll find mention
that the FileDialog.Rest oreDirectory property controls this behavior.

Of course, I suppose you could have also just looked at the documentation
for the SaveFileDialog. IMHO, the first thing anyone should do when they
are trying to find the answer to a question related to the use of a
particular framework class is read through the entire list of public
members of the class in question. Often what you're looking for will be
found there. :)

If you look through the previous threads that Google shows you, you will
also see good advice that generally you should not be relying on the
current directory anyway. Sometimes when dealing with legacy code it's
safer to just not change the current directory. But it's usually better
to just use full path names when referencing the file system. Then you're
not dependent on side-effects of other code and/or use actions.

Pete
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1981
by: Fred Lionetti | last post by:
Hi all, I'm just wondering if anyone can tell me how to change an environment variable from python. I know you can view variables through os.environ, but changing the dictionary doesn't seem to change the systmem variable. Thanks for the help! -Fred
0
1248
by: Alan | last post by:
Is there a way to change an environment variable in vb .net?
0
2039
by: Ayca Aksu | last post by:
Hi, I want to change the ''Path" variable during installation of a program. I use Environment.GetEnvironmentVariable("Path"); to get the value of the environment variable. But I dont know how to set it. I have to use EnvironmentPermissionAccess.Write for writing but they dont provide a method for writing. Please help, it's urgent.
1
1242
by: Urs Vogel | last post by:
Hi When building and saving types using the Emit namespace from a Windows service, the AssemblyBuilder.Save methods puts these assemblies into the System32 directory, altough the startup path points is where the Service is located. The AssemblyBuilder.Save method does not allow to set the directory. So how do I control this behaviour? Thanks, Urs
3
6224
by: Johnny | last post by:
How to set an user environment variable from C#? -- Johnny
5
7889
by: John | last post by:
In my VB .Net WinForm app, SaveFileDialog gives me an error msg "C:\MyFile.txt already exists. Do you want to replace it?" What I need to do is to append something to an existing file, so I want to avoid this warning msg. I included "SaveFileDialog.CheckFileExists = False" in my code, but the warning msg keeps showing up. Please help, thanks.
2
1100
by: Michael Groeger | last post by:
Hi everybody, I rewrote a component of us so that it is now a service. Unfortunateley the service cannot start, because the third party product relies on expects to be started from a special working folder. My service itself is placed in this folder but when starting a service the working folder is always the system folder AFAIK. Is it possible to changed this either using MMC or by code? Regards,
1
5963
by: RMB | last post by:
Environment: VS.Net 2003 FW 1.1 VB.Net I have an application that uses reflection to load external assemblies. The external assemblies reside in the same folder as the application exe. When I run the application as a normal windows application, the external assemblies are loaded just fine. When I run the application as a windows service, the application expects the assemblies to be in the windows\system32 directory. How can I change...
6
6805
by: Gabriel | last post by:
Hello, I do this : s = Environment.CurrentDirectory; s = s.Replace("\\", @"\"); Environment.CurrentDirectiry return a path like this C:\\....\\....\\..... I'd like replace the \\ by \, but the code I use not work. Any idea ? Best Regards,
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.