Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.. my dear friends.. i want to create one page for uploading doc file and save it on my database sql server 2005.. so what is code for that c# asp.net
Posted

You can make a validation to chech doc file extension on file upload control.
and try this

C#
protected void btnSub_Click(object sender, EventArgs e)
   {
       try
       {
           string filename = FileUpload1.FileName;

           FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Uploadform\\" + filename.Trim()));

           string path = "~\\Uploadform\\" + filename.Trim();

           OleDbConnection con = new OleDbConnection(str);//str is connection string
           cmd = new OleDbCommand("Insert into adminCircular(title,type,url1) values('" + txttitle.Text + "','" + txttype.Text + "','" + path + "')", con);
           lblinfo.Text = " Uploaded Successfully ";
           cmd.CommandType = CommandType.Text;
           con.Open();
           cmd.ExecuteNonQuery();
           con.Close();
       }
       catch (Exception ex)
       {
           Response.Write(ex.ToString());
       }
   }
 
Share this answer
 
v2
Hi,

See the below link for uploading the data from Excel file to SQL Server Database Table.

I hope it will help you some extent.

http://www.shiningstar.net/aspnet_articles/DataSet/DataSetProject1.aspx[^]
 
Share this answer
 
 
Share this answer
 
You can not save direct file to database. there are ways to store file in DB

1. you need to convert file to BYTE and then store BYTEarray to database in binary format

2. store only Path not physical file.

Now use Fileupload control and validate it against *.DOC file.
after you have accept file, use FileUploadControl1.PostedFile.SaveAs(//path) method to save the file to server.
 
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