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

OpenfileDialog in ASP.NET code behind ILLEGAL ?

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.

Here's the problem, when I use the following code

OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Choose File";
ofd.InitialDirectory = @"c:\" ;
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
ofd.FilterIndex = 1 ;
ofd.RestoreDirectory = true ;
ofd.ShowDialog();

ShowDialog() throws the following exception:

[InvalidOperationException: It is invalid to show a modal dialog or form
when the application is not running in
UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly
style to display a notification
from a service application.]
System.Windows.Forms.CommonDialog.ShowDialog()
TestPortal1.AttachFileForm.btnBrowse_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\testportal1\attachfileform.aspx .cs:73
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

Any advise you can give would be greatly appreciated.

Thanks,
IpPhD
Nov 19 '05 #1
4 10179
It just doesn't work.

ASP.Net only works by rendering legitimate html, css and
javascript...browsers have no idea what/how an OpenFileDialog is/works....

you need to use an HtmlFileInput...no alterantives unless you can use an ocx
or some java (not script).

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"hullnwm" <hu*****@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Here's the problem, when I use the following code

OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Choose File";
ofd.InitialDirectory = @"c:\" ;
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
ofd.FilterIndex = 1 ;
ofd.RestoreDirectory = true ;
ofd.ShowDialog();

ShowDialog() throws the following exception:

[InvalidOperationException: It is invalid to show a modal dialog or form
when the application is not running in
UserInteractive mode. Specify the ServiceNotification or
DefaultDesktopOnly style to display a notification
from a service application.]
System.Windows.Forms.CommonDialog.ShowDialog()
TestPortal1.AttachFileForm.btnBrowse_Click(Object sender, EventArgs e)
in c:\inetpub\wwwroot\testportal1\attachfileform.aspx .cs:73
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

Any advise you can give would be greatly appreciated.

Thanks,
IpPhD

Nov 19 '05 #2
I think you'll find that System.Windows.Forms is only for Windows
applications - Not for ASP.Net apps.

Have a Google for u0ploading files with ASP.Net.

"hullnwm" <hu*****@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Here's the problem, when I use the following code

OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Choose File";
ofd.InitialDirectory = @"c:\" ;
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
ofd.FilterIndex = 1 ;
ofd.RestoreDirectory = true ;
ofd.ShowDialog();

ShowDialog() throws the following exception:

[InvalidOperationException: It is invalid to show a modal dialog or form
when the application is not running in
UserInteractive mode. Specify the ServiceNotification or
DefaultDesktopOnly style to display a notification
from a service application.]
System.Windows.Forms.CommonDialog.ShowDialog()
TestPortal1.AttachFileForm.btnBrowse_Click(Object sender, EventArgs e)
in c:\inetpub\wwwroot\testportal1\attachfileform.aspx .cs:73
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

Any advise you can give would be greatly appreciated.

Thanks,
IpPhD

Nov 19 '05 #3
It's really not going to work the way you're doing it. What exactly are you
trying to accomplish?
This article shows you how to allow file uploads in ASP.NET.
http://SteveOrr.net/articles/EasyUploads.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"hullnwm" <hu*****@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Here's the problem, when I use the following code

OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Choose File";
ofd.InitialDirectory = @"c:\" ;
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
ofd.FilterIndex = 1 ;
ofd.RestoreDirectory = true ;
ofd.ShowDialog();

ShowDialog() throws the following exception:

[InvalidOperationException: It is invalid to show a modal dialog or form
when the application is not running in
UserInteractive mode. Specify the ServiceNotification or
DefaultDesktopOnly style to display a notification
from a service application.]
System.Windows.Forms.CommonDialog.ShowDialog()
TestPortal1.AttachFileForm.btnBrowse_Click(Object sender, EventArgs e)
in c:\inetpub\wwwroot\testportal1\attachfileform.aspx .cs:73
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

Any advise you can give would be greatly appreciated.

Thanks,
IpPhD

Nov 19 '05 #4
Hi Steve,
Thanks for setting me straight and thank you very much for the link. It
helped immensely.
Thanks again,
ipPhD

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:ez**************@TK2MSFTNGP09.phx.gbl...
It's really not going to work the way you're doing it. What exactly are
you trying to accomplish?
This article shows you how to allow file uploads in ASP.NET.
http://SteveOrr.net/articles/EasyUploads.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"hullnwm" <hu*****@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Here's the problem, when I use the following code

OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Choose File";
ofd.InitialDirectory = @"c:\" ;
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
ofd.FilterIndex = 1 ;
ofd.RestoreDirectory = true ;
ofd.ShowDialog();

ShowDialog() throws the following exception:

[InvalidOperationException: It is invalid to show a modal dialog or form
when the application is not running in
UserInteractive mode. Specify the ServiceNotification or
DefaultDesktopOnly style to display a notification
from a service application.]
System.Windows.Forms.CommonDialog.ShowDialog()
TestPortal1.AttachFileForm.btnBrowse_Click(Object sender, EventArgs e)
in c:\inetpub\wwwroot\testportal1\attachfileform.aspx .cs:73
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

Any advise you can give would be greatly appreciated.

Thanks,
IpPhD


Nov 19 '05 #5

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

Similar topics

3
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
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
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
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?
6
by: John | last post by:
Hi all: Is it possible to use an OpenFileDIalog from an ASP.NET application code behind file teh same way a Windows Application can? Thanks. John.
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...
1
by: Shilpa | last post by:
Hi, I have a OpenFileDialog on my windows form whose filter is *.*. I want the users to be able to further filter the files by giving *.doc or *.zip etc in the "file name" field of the dialog...
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...
0
by: mbewers1 | last post by:
Hi I'm having a problem trying to get a customised OpenFileDialog() to fulfil my requirements. The code for this custom-built dialog has been taken from another site...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.