Results 1 to 4 of 4

Thread: Clarification on upload file

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Clarification on upload file

    I've searched and read the links, but I still dont' get it, think I'm missing something obvious. Just trying to upload a file.

    Put a HTML File Field on my page, set the id to "inputFile". Put a Web Forms button on the page, and trying this in the code:
    Code:
    inputFile.PostedFile.SaveAs(@"c:\temp\uploadedFile.xml");
    Of course the code behind does not recognize "inputFile". All the examples I've seen actually put the code in the page, and not in the code behind. Is that how you have to do it? One link I read from Code Project said I should have something like this in my code, which I don't see
    Code:
    protected HtmlInputFile filMyFile;
    Of course if I try to put that in manually (named inputFile) I get an object reference not set to instance error.

    Am I missing some hook? Or do I have to put the code in the page and not the code behind?

    Thanks,
    Mike

  2. #2

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Clarification on upload file

    Well, I still don't get it, but going through the steps here I was able to get it to work. I *think* the only difference was not dragging an html file field on to the form, but specifying it in the html, but I'm a little lost.

  3. #3
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: Clarification on upload file

    Quote Originally Posted by Mike Hildner
    Well, I still don't get it, but going through the steps here I was able to get it to work. I *think* the only difference was not dragging an html file field on to the form, but specifying it in the html, but I'm a little lost.
    If you want to access it from Code Behind you need to Drag a "File Field" Control and then right click and choose "Run as Server Control". This declares this control as
    protected System.Web.UI.HtmlControls.HtmlInputFile File1;
    in the declaration part of the code which lets you access the control from code behind....

    If you write this manually in the declration section then you can access the control same way...
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  4. #4

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Clarification on upload file

    ah, I see, thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width