Click here to Skip to main content
15,888,315 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
How to upload a file to server using asp.net?
Posted

Use the FileUpload Control:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx[^]

Details on how to save the uploaded file in this tutorial:

http://asp.net-tutorials.com/controls/file-upload-control/[^]
 
Share this answer
 
Use FileUpload control and create a folder in your appliction as in example Uploads1 and use this method
C#
protected void btnSub_Click(object sender, EventArgs e)
   {
       try
       {
           string filename = FileUpload1.FileName;
           FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Uploads1\\" + filename));
           string path = "~\\Uploads1\\" + filename;
           SqlConnection con = new SqlConnection(str);
           lblinfo.Text = " uploaded successfully ";
           cmd = new SqlCommand("Insert into news(headline,publication,edition,date,url) values(@head,@publication,@edition,@date,'" + path + "')", con);
           cmd.Parameters.AddWithValue("head", TextBox1.Text);
           cmd.Parameters.AddWithValue("publication", TextBox2.Text);
           cmd.Parameters.AddWithValue("edition", TextBox3.Text);
           cmd.Parameters.AddWithValue("date", TextBox4.Text);
           cmd.CommandType = CommandType.Text;
           con.Open();
           cmd.ExecuteNonQuery();
           con.Close();
       }
       catch (Exception ex)
       {
           Response.Write(ex.ToString());
       }

   }
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900