Upload

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
 
E

Emil Kvarnhammar

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
 
K

Kevin Spencer

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top