473,320 Members | 1,930 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,320 software developers and data experts.

OpenFileDialog control

Hello,

I wanted to ask if anyone can help me complete the
following code. I found this example while searching
through help documnets. What i want to achieve is to open
a dialog box that lets the user select an images file.
I am using the openFileDialog control.

Here is what i have done so far for the onlick event for
the button...
Dim myStream As Stream
Dim openFileDialog1 As New OpenFileDialog()

openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All
files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then
myStream = openFileDialog1.OpenFile()
If Not (myStream Is Nothing) Then
' Insert code to read the stream here.
myStream.Close()
End If
End If

Im not sure on what to write for the stream code (where
the comment is). Does anyone have any useful articles or
advise.

thx.
Jul 21 '05 #1
8 5672
Here is some C# code sample:

OpenFileDialog authFileDlg = new OpenFileDialog();
authFileDlg.InitialDirectory = ".";
authFileDlg.Filter = "auth files (*.fox)|*.fox|All files
(*.*)|*.*";
authFileDlg.FilterIndex = 1;
authFileDlg.RestoreDirectory = true;
try
{
if (authFileDlg.ShowDialog() == DialogResult.OK)
{
Stream myStream = null;
m_arAuth.Clear(); //clear the list
if ((myStream = authFileDlg.OpenFile()) != null)
{
//get the login details
BinaryFormatter myBinFormat = new BinaryFormatter ();
m_arAuth = (ArrayList)myBinFormat.Deserialize(myStream);
myStream.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "!!! OPEN - ERROR !!!");
return;
}

-----Original Message-----
Hello,

I wanted to ask if anyone can help me complete the
following code. I found this example while searching
through help documnets. What i want to achieve is to opena dialog box that lets the user select an images file.
I am using the openFileDialog control.

Here is what i have done so far for the onlick event for
the button...
Dim myStream As Stream
Dim openFileDialog1 As New OpenFileDialog()

openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All
files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then myStream = openFileDialog1.OpenFile()
If Not (myStream Is Nothing) Then
' Insert code to read the stream here.
myStream.Close()
End If
End If

Im not sure on what to write for the stream code (where
the comment is). Does anyone have any useful articles or
advise.

thx.
.

Jul 21 '05 #2
Cor
Hi Lina,

I do not understand your question, (I understand it but why a stream) if you
want an image, the only reason can be in my opinion if you want to write it
to a database direct withouth showing it or something.

If you only want the image and you do not have used a picture box then it is
\\\
dim myimage as image
If openFileDialog1.ShowDialog() = DialogResult.OK Then
myimage.fromfile(openFileDialog1.filename)
End If
///

I hope this helps,

Cor
Jul 21 '05 #3
Hi Cor,

I want to load the image into a picture box.
I wasnt to sure what i was doin and i found this example
with the stream in it!! :o)

What do i write if i want to insert the image that is
selceted by the user into my picturebox?
Of course i will have to make sure that the user actully
selects a file!

Also, I have managed to set the filter to bitmaps, jpegs,
and all files. However i only want the all files to show
all the image files. How would i write this??

Thx for for help#
:)

-----Original Message-----
Hi Lina,

I do not understand your question, (I understand it but why a stream) if youwant an image, the only reason can be in my opinion if you want to write itto a database direct withouth showing it or something.

If you only want the image and you do not have used a picture box then it is\\\
dim myimage as image
If openFileDialog1.ShowDialog() = DialogResult.OK Then
myimage.fromfile(openFileDialog1.filename)
End If
///

I hope this helps,

Cor
.

Jul 21 '05 #4
Cor
Hi Lina,

fdlOpen.Filter = "All Image Formats (*.bmp;*.jpg;*.jpeg;*.gif;*.tif)|" & _
"*.bmp;*.jpg;*.jpeg;*.gif;*.tif|Bitmaps (*.bmp)|*.bmp|" &
_
"GIFs (*.gif)|*.gif|JPEGs (*.jpg)|*.jpg;*.jpeg|TIFs
(*.tif)|*.tif"

And than of course simple.

Picturebox1.image.fromfile(openFileDialog1.filenam e)

I hope this was what you where looking for?

Cor
Jul 21 '05 #5
There is a good example on
www.TechnicalVideos.net
Hours of .Net and Sql Server videos for $20
Jul 21 '05 #6
Hi Cor,

I have used the following code but the image doesnt seem
to load into my picture box!!

OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Filter = "All Image Formats
(*.bmp;*.jpg;*.jpeg;*.gif;*.tif)|" & _
"*.bmp;*.jpg;*.jpeg;*.gif;*.tif|Bitmaps (*.bmp)|*.bmp|"
& _
"GIFs (*.gif)|*.gif|JPEGs (*.jpg)|*.jpg;*.jpeg|TIFs
(*.tif)|*.tif"

OpenFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then
PictureBox1.Image.FromFile(OpenFileDialog1.FileNam e)
End If

-----Original Message-----
Hi Lina,

fdlOpen.Filter = "All Image Formats (*.bmp;*.jpg;*.jpeg;*.gif;*.tif)|" & _ "*.bmp;*.jpg;*.jpeg;*.gif;*.tif|Bitmaps (*.bmp)|*.bmp|" &_
"GIFs (*.gif)|*.gif|JPEGs (*.jpg) |*.jpg;*.jpeg|TIFs(*.tif)|*.tif"

And than of course simple.

Picturebox1.image.fromfile(openFileDialog1.filena me)

I hope this was what you where looking for?

Cor
.

Jul 21 '05 #7
Cor
Hi Lina,

Sorry it was to quick and dirty typed

PictureBox1.Image.FromFile(OpenFileDialog1.FileNam e)


PictureBox1.Image = image.FromFile(OpenFileDialog1.FileName)

I think it will go now?

Cor
Jul 21 '05 #8
thx Cor,

it is working now :o)
Your help is appreciated.
-----Original Message-----
Hi Lina,

Sorry it was to quick and dirty typed

PictureBox1.Image.FromFile(OpenFileDialog1.FileNam e)
PictureBox1.Image = image.FromFile

(OpenFileDialog1.FileName)
I think it will go now?

Cor
.

Jul 21 '05 #9

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

Similar topics

1
by: Johann Blake | last post by:
A number of posts have indicated developers having problem getting an OpenFileDialog to startup in a specific directory when the dialog is shown. The first time you show the dialog, the...
3
by: cider123 | last post by:
Everything I've read so far states you can't inherit or extend these dialogs because they're "sealed". I considered building my own custom control, but I haven't been able to find: 1) How to...
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...
8
by: Lina | last post by:
Hello, I wanted to ask if anyone can help me complete the following code. I found this example while searching through help documnets. What i want to achieve is to open a dialog box that lets...
5
by: De kessé | last post by:
Im trying to do this from ASP.NET and it does not work. Dim ofd As New OpenFileDialog Openfiledialog is not there. But I can find it in the object browser. In my web config i can see this...
0
by: Gregaz | last post by:
I have a form in my project, which I open as a DialogBox. On that that form there are 3 TextBoxes. To one of them I want to write in a file path. To have it easier I have an OpenFileDialog control...
6
by: Mike | last post by:
Hello all, I'm trying to work with the openfiledialog and being new to vb and vb.net I'm having some problems. Wherever I have Me.OpenFileDialog1 I keep getting the following error: C:\Visual...
1
by: =?Utf-8?B?TW9uaWNh?= | last post by:
Hi 1- I want to pick a file in my website project using asp.net 2- I added System.Windows.Forms by add references to my project. 3- I attach a button to my project. 4- in side...
3
by: Martijn Mulder | last post by:
It strikes me that System.Windows.Forms.OpenFileDialog seems te 'remember' which directory it was in last, even when a new OpenFileDialog-object is created for every access to the file system....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.