473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OpenFileDialog interaction with FileStream

don
has anyone experienced problems with interactions between OpenFileDialog and FileStream? When I select "open" from an OpenFileDialog the subsequent calls to FileStream do not create a file. If I do anything else, eg, navigate to other folders, and then press "cancel" the file is created. This occurrs just with the simple code below. Any ideas

private void button1_Click(object sender, System.EventArgs e

// open the common dialog bo
OpenFileDialog of = new OpenFileDialog()
of.ShowDialog()
of.Dispose()
private void button2_Click(object sender, System.EventArgs e

String fn = Environment.CurrentDirectory + "\\test.txt"
FileStream f = new FileStream(fn,FileMode.Create)
f.Close()
}
Nov 16 '05 #1
2 3058
don <an*******@discussions.microsoft.com> wrote:
has anyone experienced problems with interactions between
OpenFileDialog and FileStream? When I select "open" from an
OpenFileDialog the subsequent calls to FileStream do not create a
file. If I do anything else, eg, navigate to other folders, and then
press "cancel" the file is created. This occurrs just with the simple
code below. Any ideas?


I suspect you'll find it *does* create a file, but it changes the
current directory to the one selected in the OpenFileDialog, so the
test.txt file gets created in an "odd" place.

Try this program:

using System;
using System.Windows.Forms;

public class Test
{
static void Main()
{
Console.WriteLine ("Before OpenFileDialog: {0}",
Environment.CurrentDirectory);
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.ShowDialog();
}
Console.WriteLine ("After OpenFileDialog: {0}",
Environment.CurrentDirectory);
}
}

and see what it gives you...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
2G
Hi, I also have had many problems with the openfiledialog , often had to
rewrite app for scratch to get rid of the error

the last problem I had with this nasty dialog
http://groups.google.be/groups?dq=&h...%26start%3D700
"don" <an*******@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
has anyone experienced problems with interactions between OpenFileDialog and FileStream? When I select "open" from an OpenFileDialog the subsequent
calls to FileStream do not create a file. If I do anything else, eg,
navigate to other folders, and then press "cancel" the file is created.
This occurrs just with the simple code below. Any ideas?
private void button1_Click(object sender, System.EventArgs e)
{
// open the common dialog box
OpenFileDialog of = new OpenFileDialog();
of.ShowDialog();
of.Dispose();
}

private void button2_Click(object sender, System.EventArgs e)
{
String fn = Environment.CurrentDirectory + "\\test.txt";
FileStream f = new FileStream(fn,FileMode.Create);
f.Close();
}

Nov 16 '05 #3

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

Similar topics

3
by: bobrad | last post by:
MAYBE SOMEBODY CAM HELP I AM USING THE FOLLOWING CODE TO GET A LOCATION OF A FILE IN A WINFORM DIALOG OpenFileDialog openFileDialog = new OpenFileDialog(); OpenFileDialog.Filter = " Access...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
8
by: e-mid | last post by:
why does not openFileDialog have closed event? i want to do something; as soon as the dialog closes. is there a way to do this?
11
by: Rasmus Teglgaard | last post by:
Hi I need to know how to store the OpenfileDialog.OpenFile() in a memorystream. Do I need to do some kind of conversion before this works I can't write dim mem as new memorystream( mem =...
1
by: Matthew | last post by:
The code is here: http://www.osbornewood.com/matthew/vb.cfm I am trying to Serialize soundFile.Text to an XML file. I have two buttons: Browse and Save Settings. You can enter a value the...
6
by: barbara_dave | last post by:
Hi, All, I want to use the openfiledialog to open different extension files in different directory( only one type files at one time). I set the OpenFiledialog InitialDirectory and Filter...
1
by: marcmc | last post by:
I can't get the following msdn code below to actually open the .txt file i select It seems Return DlgOpenFile.OpenFile() or Return New FileStream(Path, System.IO.FileMode.Open, _...
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
1
by: sam | last post by:
OpenFileDialog appears to be "holding onto" the parent folder of a selected file until the application using the dialog quits. After creating a folder containing a file, I attempted to select...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.