Hi All,
I have a page where i am uploading pdf/word/xls files and storing in the database.
And then i am opening it in their respective extension format.
What i need now is
- upload pdf/word/xls files and storing it in the database with .txt extension
- Display the Binary data that is stored, inside a div tag.(earlier i was displaying it in pdf/word/xls)
Plz Help me with this,
Here is the code of wat i was doing earlier,
Uploading the file and saving in DB
protected void btnSaveDocument_Click(object sender, EventArgs e)
{
string DocumentName = txtDocName.Text;
string DocumentDescription = txtDocDescription.Text;
int len=FileUpload1.PostedFile.ContentLength;
byte[] DocumentFile = new byte[len];
FileUpload1.PostedFile.InputStream.Read(DocumentFile, 0, len);
//string path = Server.MapPath(DocumentFile);
string filename = Server.HtmlEncode(FileUpload1.FileName);
string extension = System.IO.Path.GetExtension(filename);
Documentations doc = new Documentations();
doc.AddDocument(DocumentName, DocumentDescription, DocumentFile, extension);
}
Fetch the binary data from DB and display in their respective formats.
protected void btnGetDocuments_Click(object sender, EventArgs e)
{
int DocumentID = Convert.ToInt32(txtDocID.Text);
Documentations docs = new Documentations();
DataSet ObjDoc = new DataSet();
ObjDoc = docs.FetchDocs(DocumentID);
byte[] document = (byte[])ObjDoc.Tables[0].Rows[0]["Documentation"];
//Response.BinaryWrite(document);
string strExtenstion = ObjDoc.Tables[0].Rows[0]["Extension"].ToString();
string DocName = ObjDoc.Tables[0].Rows[0]["DocumentName"].ToString();
Response.Clear();
Response.Buffer = true;
if (strExtenstion == ".doc" || strExtenstion == ".docx")
{
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("content-disposition", "inline;filename=" + DocName + ".doc");
}
else if (strExtenstion == ".xls" || strExtenstion == ".xlsx")
{
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "inline;filename=" + DocName + ".xls");
}
else if (strExtenstion == ".pdf")
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline;filename=" + DocName + ".pdf");
}
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(document);
Response.End();
}