I used the following code to insert a file as binary into a SQL server database.
id FileType filelength description FileData
1 application/msword 31232 bus.doc <Binary>
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection("Server=TECH1\\NETSDK;UID=sa;PWD=user1;Database=QUECOSA");
SqlCommand comm=new SqlCommand("Insert into filedata(filetype,filelength,filedata,description) values (@filetype,@fileLength,@filedata,@description)",conn);
SqlParameter param1=new SqlParameter("@filetype",SqlDbType.NVarChar);
param1.Value=myFile.PostedFile.ContentType;
comm.Parameters.Add(param1);
SqlParameter param2=new SqlParameter("@fileLength",SqlDbType.Int);
param2.Value=myFile.PostedFile.ContentLength;
comm.Parameters.Add(param2);
SqlParameter param3=new SqlParameter("@filedata",SqlDbType.Image);
int datalength=myFile.PostedFile.ContentLength;
Byte[] content=new byte[datalength];
myFile.PostedFile.InputStream.Read(content,0,datalength);
param3.Value=content;
comm.Parameters.Add(param3);
SqlParameter param4=new SqlParameter("@description",SqlDbType.NVarChar);
param4.Value=Path.GetFileName(myFile.PostedFile.FileName);
comm.Parameters.Add(param4);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
populatedata();
}
I would like some help to provide a searching tool on the browser so I can load any file I have stored on SQL server database.
I supposed I need to load that file store on the databse on a directory on the server and then provide a link on my website so an internet used can load it.
Any help will be appreciated.
Thanks
id FileType filelength description FileData
1 application/msword 31232 bus.doc <Binary>
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection("Server=TECH1\\NETSDK;UID=sa;PWD=user1;Database=QUECOSA");
SqlCommand comm=new SqlCommand("Insert into filedata(filetype,filelength,filedata,description) values (@filetype,@fileLength,@filedata,@description)",conn);
SqlParameter param1=new SqlParameter("@filetype",SqlDbType.NVarChar);
param1.Value=myFile.PostedFile.ContentType;
comm.Parameters.Add(param1);
SqlParameter param2=new SqlParameter("@fileLength",SqlDbType.Int);
param2.Value=myFile.PostedFile.ContentLength;
comm.Parameters.Add(param2);
SqlParameter param3=new SqlParameter("@filedata",SqlDbType.Image);
int datalength=myFile.PostedFile.ContentLength;
Byte[] content=new byte[datalength];
myFile.PostedFile.InputStream.Read(content,0,datalength);
param3.Value=content;
comm.Parameters.Add(param3);
SqlParameter param4=new SqlParameter("@description",SqlDbType.NVarChar);
param4.Value=Path.GetFileName(myFile.PostedFile.FileName);
comm.Parameters.Add(param4);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
populatedata();
}
I would like some help to provide a searching tool on the browser so I can load any file I have stored on SQL server database.
I supposed I need to load that file store on the databse on a directory on the server and then provide a link on my website so an internet used can load it.
Any help will be appreciated.
Thanks