OpenfileDialog in ASP.NET code behind ILLEGAL ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hullnwm

    #1

    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.InitialDire ctory = @"c:\" ;
    ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
    ofd.FilterIndex = 1 ;
    ofd.RestoreDire ctory = true ;
    ofd.ShowDialog( );

    ShowDialog() throws the following exception:

    [InvalidOperatio nException: It is invalid to show a modal dialog or form
    when the application is not running in
    UserInteractive mode. Specify the ServiceNotifica tion or DefaultDesktopO nly
    style to display a notification
    from a service application.]
    System.Windows. Forms.CommonDia log.ShowDialog( )
    TestPortal1.Att achFileForm.btn Browse_Click(Ob ject sender, EventArgs e) in
    c:\inetpub\wwwr oot\testportal1 \attachfileform .aspx.cs:73
    System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
    System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
    eventArgument)
    System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
    sourceControl, String eventArgument)
    System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
    System.Web.UI.P age.ProcessRequ estMain()

    Any advise you can give would be greatly appreciated.

    Thanks,
    IpPhD


  • Karl Seguin

    #2
    Re: OpenfileDialog in ASP.NET code behind ILLEGAL ?

    It just doesn't work.

    ASP.Net only works by rendering legitimate html, css and
    javascript...br owsers 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" <hullnwm@nospam .nospam> wrote in message
    news:%23J$Jh32S FHA.3184@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > 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.InitialDire ctory = @"c:\" ;
    > ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
    > ofd.FilterIndex = 1 ;
    > ofd.RestoreDire ctory = true ;
    > ofd.ShowDialog( );
    >
    > ShowDialog() throws the following exception:
    >
    > [InvalidOperatio nException: It is invalid to show a modal dialog or form
    > when the application is not running in
    > UserInteractive mode. Specify the ServiceNotifica tion or
    > DefaultDesktopO nly style to display a notification
    > from a service application.]
    > System.Windows. Forms.CommonDia log.ShowDialog( )
    > TestPortal1.Att achFileForm.btn Browse_Click(Ob ject sender, EventArgs e)
    > in c:\inetpub\wwwr oot\testportal1 \attachfileform .aspx.cs:73
    > System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
    >
    > System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
    > eventArgument)
    > System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
    > sourceControl, String eventArgument)
    > System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
    > System.Web.UI.P age.ProcessRequ estMain()
    >
    > Any advise you can give would be greatly appreciated.
    >
    > Thanks,
    > IpPhD
    >[/color]


    Comment

    • Simon Harris

      #3
      Re: OpenfileDialog in ASP.NET code behind ILLEGAL ?

      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" <hullnwm@nospam .nospam> wrote in message
      news:%23J$Jh32S FHA.3184@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > 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.InitialDire ctory = @"c:\" ;
      > ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
      > ofd.FilterIndex = 1 ;
      > ofd.RestoreDire ctory = true ;
      > ofd.ShowDialog( );
      >
      > ShowDialog() throws the following exception:
      >
      > [InvalidOperatio nException: It is invalid to show a modal dialog or form
      > when the application is not running in
      > UserInteractive mode. Specify the ServiceNotifica tion or
      > DefaultDesktopO nly style to display a notification
      > from a service application.]
      > System.Windows. Forms.CommonDia log.ShowDialog( )
      > TestPortal1.Att achFileForm.btn Browse_Click(Ob ject sender, EventArgs e)
      > in c:\inetpub\wwwr oot\testportal1 \attachfileform .aspx.cs:73
      > System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
      >
      > System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
      > eventArgument)
      > System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
      > sourceControl, String eventArgument)
      > System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
      > System.Web.UI.P age.ProcessRequ estMain()
      >
      > Any advise you can give would be greatly appreciated.
      >
      > Thanks,
      > IpPhD
      >[/color]


      Comment

      • Steve C. Orr [MVP, MCSD]

        #4
        Re: OpenfileDialog in ASP.NET code behind ILLEGAL ?

        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.


        --
        I hope this helps,
        Steve C. Orr, MCSD, MVP



        "hullnwm" <hullnwm@nospam .nospam> wrote in message
        news:%23J$Jh32S FHA.3184@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > 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.InitialDire ctory = @"c:\" ;
        > ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
        > ofd.FilterIndex = 1 ;
        > ofd.RestoreDire ctory = true ;
        > ofd.ShowDialog( );
        >
        > ShowDialog() throws the following exception:
        >
        > [InvalidOperatio nException: It is invalid to show a modal dialog or form
        > when the application is not running in
        > UserInteractive mode. Specify the ServiceNotifica tion or
        > DefaultDesktopO nly style to display a notification
        > from a service application.]
        > System.Windows. Forms.CommonDia log.ShowDialog( )
        > TestPortal1.Att achFileForm.btn Browse_Click(Ob ject sender, EventArgs e)
        > in c:\inetpub\wwwr oot\testportal1 \attachfileform .aspx.cs:73
        > System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
        >
        > System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
        > eventArgument)
        > System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
        > sourceControl, String eventArgument)
        > System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
        > System.Web.UI.P age.ProcessRequ estMain()
        >
        > Any advise you can give would be greatly appreciated.
        >
        > Thanks,
        > IpPhD
        >[/color]


        Comment

        • hullnwm

          #5
          Re: OpenfileDialog in ASP.NET code behind ILLEGAL ?

          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]" <Steve@Orr.ne t> wrote in message
          news:ezCuoG3SFH A.2812@TK2MSFTN GP09.phx.gbl...[color=blue]
          > 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" <hullnwm@nospam .nospam> wrote in message
          > news:%23J$Jh32S FHA.3184@TK2MSF TNGP09.phx.gbl. ..[color=green]
          >> 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.InitialDire ctory = @"c:\" ;
          >> ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
          >> ofd.FilterIndex = 1 ;
          >> ofd.RestoreDire ctory = true ;
          >> ofd.ShowDialog( );
          >>
          >> ShowDialog() throws the following exception:
          >>
          >> [InvalidOperatio nException: It is invalid to show a modal dialog or form
          >> when the application is not running in
          >> UserInteractive mode. Specify the ServiceNotifica tion or
          >> DefaultDesktopO nly style to display a notification
          >> from a service application.]
          >> System.Windows. Forms.CommonDia log.ShowDialog( )
          >> TestPortal1.Att achFileForm.btn Browse_Click(Ob ject sender, EventArgs e)
          >> in c:\inetpub\wwwr oot\testportal1 \attachfileform .aspx.cs:73
          >> System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
          >>
          >> System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
          >> eventArgument)
          >> System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
          >> sourceControl, String eventArgument)
          >> System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
          >> System.Web.UI.P age.ProcessRequ estMain()
          >>
          >> Any advise you can give would be greatly appreciated.
          >>
          >> Thanks,
          >> IpPhD
          >>[/color]
          >
          >[/color]


          Comment

          Working...