I have an ASP.NET application that generates HTML code. By this, I mean that the code uses write.response to write HTML code directly to the browser for the entire page:
Reponse.Write("<HTML lang=""en"" METHOD=""POST"" ENCTYPE=""multipart/form-data"">")
This is a problem, because I need to enable the generated form to upload files to a folder on the server. I'm not sure about this, but it seems unlikely to me that I can generate ASP.NET fileupload controls to do this because they are translated to input type="file" before delivery to the browser. If I'm wrong about that, please let me know, but for now I'm assuming that I must use the old way:
Response.Write("<input type=""file"" name=""filAttachment"" size=30> ")
This works OK to find the file to be uploaded and, in fact, that's pretty much what I see in the browser source code when asp:fileupload is translated.
But I seem to be missing the reference to whatever sits on the server to save the file when the form is submitted. .NET allows you to reference the upload control directly in
VB and it's as simple as using the .SAVEAS method:
filAttachment.PostedFile.SaveAs...
But of course, I'd get a compiler error trying to reference a field that's defined in generated HTML but not on the .NET form itself because VS doesn't know it exists without the form definition. I could put an asp:fileupload object on the .NET page before adding my generated HTML code, but then I'd be limited to however many such fields I put there, and users always want more. So, I'd rather not go that route if I can help it.
Has anybody got an example of the server side code needed to save uploaded files or an alternative suggestion on how to accomplish this?