473,386 Members | 1,734 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,386 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 5688
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
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...

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.