Create Getfile.aspx.cs file
Add the namespace:
using System.Data.SqlClient;
using System.Data.SqlTypes;
Modify the Page_Load function:
protected void Page_Load(object sender, EventArgs e)
{
int pid = Convert.ToInt32(Request[“id”]);
SqlConnection myConnection = new SqlConnection(“Data Source=\”localhost\”;Initial Catalog=\”demo\”;Persist Security Info=True;User ID=demo;Password=demo”);
SqlCommand mycommand = myConnection.CreateCommand();
myConnection.Open();
mycommand.CommandText = “SELECT filedata ” +
” FROM Table_word WHERE (ID = ” + pid.ToString() + “)”;
SqlDataReader myReader = mycommand.ExecuteReader();
myReader.Read();
SqlBinary binaryStream = myReader.GetSqlBinary(0);
myReader.Close();
myConnection.Close();
Response.BinaryWrite(binaryStream.Value);
}
So you can get the file stream from the sql database. The component can open it as follow:
var str=window.location.search;
var pos_start=str.indexOf(“id”)+3;
if (pos_start == 2)return;
var fileid = “http://localhost/Getdc.aspx?id=” + str.substring(pos_start);
document.all.OfficeViewer.Open(fileid);
Leave a Reply
You must be logged in to post a comment.
Recent Comments