Uploading Files Using ASP.NET

Add a file browse HTML control. Right click and select 'Run as Server Control'. Add a button. So you have something like this:

<input type="file" runat="server" ID="File1" /><asp:Button runat="server" ID="Button1" /> 

Double click the button and add the following code.

private void Button1_Click(object sender, System.EventArgs e)
{
string strFilename;

try
{
strFilename = File1.PostedFile.FileName;
strFilename = System.IO.Path.GetFileName(strFilename);
File1.PostedFile.SaveAs(@"f:\"+strFilename);
}
catch(Exception ex)
{
Response.Write(ex);
}
}

You might also like...

Comments

Man from Mars

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry