try to handle openfiledialog in my web page

G

Guest

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
 
G

Guest

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
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top