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
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.
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...
Re: Clarification on upload file