May 4, 2013

How to upload files using ASP.NET ?


  • Add a file browse HTML control. Right click and select 'Run as Server Control'. Add a button.
  • 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);
}
}

0 comments:

Post a Comment