Upload

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

Hi there!

I'd like o k'now how to make un upload of a certain file
to disk in ASP.

Thank you for your time
 
Hi,

In ASP.NET you can upload a file using the File control. Add a File control
from the HTML controls toolbox if using VS.NET or manually with the code:

<INPUT id="File1" type="file" name="File1" runat="server">

Now in CodeBehind you can use the File1.PostedFile on for example
a btnUpload click event like this:

private void btnUpload_Click(object sender, System.EventArgs e)
{
if(File1.PostedFile != null)
File1.PostedFile.SaveAs(@"c:\uploadfolder\data.txt");
}

Note that you must have write privileges to the folder you upload to set
properly for the user that runs the ASP.NET app.

Good luck!
/Emil
 
You can also use a plain vanilla 'input type="file"' in your page, and in
the PostBack, you can get uploaded files from the Request.Files collection.
Make sure in either case that you set the encoding type of the form to
"multipart/form-data".

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big things are made up of
lots of little things.
 
Back
Top