Use HTML <input type="file" > instead of .Net FileUpload control?

Discussion in 'ASP .Net' started by Gert, Jul 10, 2007.

  1. Gert

    Gert Guest

    Would it be possible to access the file CONTENT in codebehind for a
    standard:
    <input id="htmlFile" type="file" />

    Then in codebehind:
    foreach (string keyName in
    System.Web.HttpContext.Current.Request.Form.Keys)
    {
    //i can see keyName = "htmlFile" here as well as the "c:/myfile.txt"
    for example
    // i need content here
    }

    I cant use:
    <asp:FileUpload ID="dotnetFile" runat="server" />
    because I attempt to integrate legacy ASP application in our new
    master page UI framework.

    Help would be much appreciated

    G
    Gert, Jul 10, 2007
    #1
    1. Advertising

  2. Gert

    Patrice Guest

    ASP.NET controls are just a way to generate HTML markup anyway i..e. the
    file upload control just creates an input type="file" tag. If you want to
    get a file posted from a non ASP.NET page, it's likely the simplest way
    would be to use the Request.Files collection...

    --
    Patrice



    "Gert" <> a écrit dans le message de news:
    ...
    > Would it be possible to access the file CONTENT in codebehind for a
    > standard:
    > <input id="htmlFile" type="file" />
    >
    > Then in codebehind:
    > foreach (string keyName in
    > System.Web.HttpContext.Current.Request.Form.Keys)
    > {
    > //i can see keyName = "htmlFile" here as well as the "c:/myfile.txt"
    > for example
    > // i need content here
    > }
    >
    > I cant use:
    > <asp:FileUpload ID="dotnetFile" runat="server" />
    > because I attempt to integrate legacy ASP application in our new
    > master page UI framework.
    >
    > Help would be much appreciated
    >
    > G
    >
    Patrice, Jul 10, 2007
    #2
    1. Advertising

  3. Gert

    Teemu Keiski Guest

    Hi,

    you could try iterating Request.Files (item type is HttpPostedFile)

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Gert" <> wrote in message
    news:...
    > Would it be possible to access the file CONTENT in codebehind for a
    > standard:
    > <input id="htmlFile" type="file" />
    >
    > Then in codebehind:
    > foreach (string keyName in
    > System.Web.HttpContext.Current.Request.Form.Keys)
    > {
    > //i can see keyName = "htmlFile" here as well as the "c:/myfile.txt"
    > for example
    > // i need content here
    > }
    >
    > I cant use:
    > <asp:FileUpload ID="dotnetFile" runat="server" />
    > because I attempt to integrate legacy ASP application in our new
    > master page UI framework.
    >
    > Help would be much appreciated
    >
    > G
    >
    Teemu Keiski, Jul 10, 2007
    #3
  4. Gert wrote:
    > Would it be possible to access the file CONTENT in codebehind for a
    > standard:
    > <input id="htmlFile" type="file" />
    >
    > Then in codebehind:
    > foreach (string keyName in
    > System.Web.HttpContext.Current.Request.Form.Keys)
    > {
    > //i can see keyName = "htmlFile" here as well as the "c:/myfile.txt"
    > for example
    > // i need content here
    > }
    >
    > I cant use:
    > <asp:FileUpload ID="dotnetFile" runat="server" />
    > because I attempt to integrate legacy ASP application in our new
    > master page UI framework.


    Use the Request.Files collection.

    --
    Göran Andersson
    _____
    http://www.guffa.com
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Jul 10, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HVG
    Replies:
    2
    Views:
    2,473
  2. =?Utf-8?B?TmF0aGFu?=

    Page has Expired - using html input control (type=file)

    =?Utf-8?B?TmF0aGFu?=, Aug 18, 2005, in forum: ASP .Net
    Replies:
    14
    Views:
    3,948
    Steven Cheng[MSFT]
    Sep 12, 2005
  3. VB Programmer
    Replies:
    1
    Views:
    2,515
    VB Programmer
    Jan 18, 2006
  4. Roberto
    Replies:
    3
    Views:
    308
  5. Walter
    Replies:
    6
    Views:
    236
    Bob Barrows [MVP]
    Sep 17, 2004
Loading...

Share This Page