473,624 Members | 2,637 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(o bject sender, EventArgs e) I wrote:
OpenFileDialog filedlg = new OpenFileDialog( );
filedlg.Title = "Choose an image to upload";
filedlg.Initial Directory = @"c:\";
filedlg.Filter = "Image Files (JPG, JPEG, GIF, BMP, TIF,
PNG)|*.jpg;*jpe g;*.gif;*.bmp;* .tif;*.png|All files (*.*)|*.*";
filedlg.FilterI ndex = 2;
filedlg.Restore Directory = true;
filedlg.ShowDia log();
but when I click on this button, I receive error.

what's wrong with my code.

thank you.
monica
Feb 25 '07 #1
1 3005
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(o bject sender, EventArgs e) I wrote:
OpenFileDialog filedlg = new OpenFileDialog( );
filedlg.Title = "Choose an image to upload";
filedlg.Initial Directory = @"c:\";
filedlg.Filter = "Image Files (JPG, JPEG, GIF, BMP, TIF,
PNG)|*.jpg;*jpe g;*.gif;*.bmp;* .tif;*.png|All files (*.*)|*.*";
filedlg.FilterI ndex = 2;
filedlg.Restore Directory = true;
filedlg.ShowDia log();
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 (*.mdb)|*.mdb|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) DataBaseLocation.Text = openFileDialog.FileName;
2
3074
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 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(object sender, System.EventArgs e // open the common dialog bo...
4
7990
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
6037
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
4224
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 button. Does anyone knows some good source of information? Thank you for your time.
4
10191
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 our website. The reason I'm doing it this way is that I've read that by using the common dialog box, the security issues are based on the logged in user. Of course, I added a reference to System.Windows.Forms and added a using clause.
8
6077
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...
4
4027
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
4003
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 selects? thanks...
0
8182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
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
8635
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
7178
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
6115
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
5570
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
4085
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...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.