473,854 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(o bject sender, System.EventArg s e

// open the common dialog bo
OpenFileDialog of = new OpenFileDialog( )
of.ShowDialog()
of.Dispose()
private void button2_Click(o bject sender, System.EventArg s e

String fn = Environment.Cur rentDirectory + "\\test.txt "
FileStream f = new FileStream(fn,F ileMode.Create)
f.Close()
}
Nov 16 '05 #1
2 3092
don <an*******@disc ussions.microso ft.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.WriteLi ne ("Before OpenFileDialog: {0}",
Environment.Cur rentDirectory);
using (OpenFileDialog ofd = new OpenFileDialog( ))
{
ofd.ShowDialog( );
}
Console.WriteLi ne ("After OpenFileDialog: {0}",
Environment.Cur rentDirectory);
}
}

and see what it gives you...

--
Jon Skeet - <sk***@pobox.co m>
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*******@disc ussions.microso ft.com> wrote in message
news:9A******** *************** ***********@mic rosoft.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(o bject sender, System.EventArg s e)
{
// open the common dialog box
OpenFileDialog of = new OpenFileDialog( );
of.ShowDialog() ;
of.Dispose();
}

private void button2_Click(o bject sender, System.EventArg s e)
{
String fn = Environment.Cur rentDirectory + "\\test.txt ";
FileStream f = new FileStream(fn,F ileMode.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
360
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 (*.mdb)|*.mdb|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) DataBaseLocation.Text = openFileDialog.FileName;
4
8014
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 Explorer i am getting error saying that cannot delete that folder as some process is using it. After that i selected a file from the same folder in OpenFileDialog. When i tried to delete the folder after selecting the file also it is giving the...
8
6045
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
4500
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 = OpenfileDialog.Openfile( It says not supported cast or something like that
1
1315
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 textbox and click Save Settings and it will generate a file settings.xml. The contents of soundFile.Text are in that file.
6
3027
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 property for ".dat" files at first time, it works. When I try to use openfiledialog to set different InitialDirectory an different Filter property for ".txt" files at second time, I got frozen window. Even I added code to dispose openfiledialog after...
1
250
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, _ System.IO.FileAccess.ReadWrite) don't actually do anything. Please help as I need this working for my prototype tomorrow.
8
6107
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 only the files I want to see appear in the file list box. When I change the filter to one of the other filters, all the files in the list disappear. If I then manually type a filter into the "Filename" textbox, then the files appear and the filter...
1
3788
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 that file with an OpenFileDialog. I used the following code to create the dialog: Dim a As New OpenFileDialog a.ShowDialog() a.Dispose()
0
11024
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
10679
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...
0
9513
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...
1
7914
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5741
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...
1
4560
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3186
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.