473,499 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

try to handle openfiledialog in my web page

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 Button1_Click(object sender, EventArgs e) I wrote:
OpenFileDialog filedlg = new OpenFileDialog();
filedlg.Title = "Choose an image to upload";
filedlg.InitialDirectory = @"c:\";
filedlg.Filter = "Image Files (JPG, JPEG, GIF, BMP, TIF,
PNG)|*.jpg;*jpeg;*.gif;*.bmp;*.tif;*.png|All files (*.*)|*.*";
filedlg.FilterIndex = 2;
filedlg.RestoreDirectory = true;
filedlg.ShowDialog();
but when I click on this button, I receive error.

what's wrong with my code.

thank you.
monica
Feb 25 '07 #1
1 2994
You cannot use a Windows Forms control in an ASP.NET web page in this way.

You need to use the ASP.NET UploadFile control, which renders in the correct
place - in the client's browser. This is a standard HTML control that
browsers all understand what to do with. unfortunately, it only provides
simple file browsing dialog and does not offer a way to create a file
extension "filter" like the OpenFileDIalog control does.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Monica" wrote:
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 Button1_Click(object sender, EventArgs e) I wrote:
OpenFileDialog filedlg = new OpenFileDialog();
filedlg.Title = "Choose an image to upload";
filedlg.InitialDirectory = @"c:\";
filedlg.Filter = "Image Files (JPG, JPEG, GIF, BMP, TIF,
PNG)|*.jpg;*jpeg;*.gif;*.bmp;*.tif;*.png|All files (*.*)|*.*";
filedlg.FilterIndex = 2;
filedlg.RestoreDirectory = true;
filedlg.ShowDialog();
but when I click on this button, I receive error.

what's wrong with my code.

thank you.
monica
Feb 25 '07 #2

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...
2
3063
by: don | last post by:
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...
4
7965
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
6025
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?
3
4218
by: Zagor | last post by:
Hi All, I was wondering if it is possible to use(if it will work) the OpenFileDialog class in ASP.NET. Currently I am using the classic javascript but I have I need to customize the browse...
4
10182
by: hullnwm | last post by:
In my asp.net page I'm attempting to use the OpenfileDialog object to offer a common dialog box for the user to select a particular file on their hard drive that may subsequently be uploaded to...
8
6055
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...
4
4019
by: NickP | last post by:
Hi there, This is really crazy! 1. Make a folder 2. Put a text file in the folder 3. Run the following code... Dim pop As New OpenFileDialog Using pop
3
3956
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
0
7012
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
7180
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
7225
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...
0
4605
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...
0
3105
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...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
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 ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
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...

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.