OpenFileDialog interaction with FileStream

G

Guest

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()
}
 
J

Jon Skeet [C# MVP]

don said:
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...
 
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=&...soft.public.dotnet.languages.csharp&start=700


don said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top