Opening word/pdf document in another window
-
Hi All, I am saving a word document in database as bytes and in another column I am saving the file name, I am providing a link button or an anchor tag for the user to select when the user clicks on it the user should be able to see the file opened in another browser window. Can you anybody please help me on it a little bit any code snippet, a link or even a suggestion would help me a lot. I am also searching but asking if somebody can guide me in a right direction. Thanks in advance.
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
-
Hi All, I am saving a word document in database as bytes and in another column I am saving the file name, I am providing a link button or an anchor tag for the user to select when the user clicks on it the user should be able to see the file opened in another browser window. Can you anybody please help me on it a little bit any code snippet, a link or even a suggestion would help me a lot. I am also searching but asking if somebody can guide me in a right direction. Thanks in advance.
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
-
Hi All, I am saving a word document in database as bytes and in another column I am saving the file name, I am providing a link button or an anchor tag for the user to select when the user clicks on it the user should be able to see the file opened in another browser window. Can you anybody please help me on it a little bit any code snippet, a link or even a suggestion would help me a lot. I am also searching but asking if somebody can guide me in a right direction. Thanks in advance.
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
-
Plenty of suggestions at show word file in browser - Google Search[^].
Hi I tried this way but it shows me the document in binary format
protected void Page_Load(object sender, EventArgs e)
{
Investigator _objInvestigator = new Investigator();
InvestigatorService _objinvestigatorService = new InvestigatorService();int InvestigatorId; InvestigatorId = ((Session\["InvestigatorId"\] != null) && int.TryParse(Session\["InvestigatorId"\].ToString(), out InvestigatorId)) ? InvestigatorId : 0; \_objInvestigator = \_objinvestigatorService.GetByInvestigatorId(InvestigatorId); if (\_objInvestigator != null) { if ((\_objInvestigator.CvFile != null) && !string.IsNullOrEmpty(\_objInvestigator.CvFileNameWithExt)) { String ext = System.IO.Path.GetExtension(\_objInvestigator.CvFileNameWithExt); Response.ContentType = "application/" + ext; Response.AddHeader("content-length", \_objInvestigator.CvFile.Length.ToString()); Response.BinaryWrite(\_objInvestigator.CvFile); } } }
And this the code for link button click
protected void loadFile_Click(object sender, EventArgs e)
{
Response.Write(string.Format("<script>window.open('{0}','_blank');</script>", "TheFile.aspx"));
}Any suggestions please?
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
-
Hi I tried this way but it shows me the document in binary format
protected void Page_Load(object sender, EventArgs e)
{
Investigator _objInvestigator = new Investigator();
InvestigatorService _objinvestigatorService = new InvestigatorService();int InvestigatorId; InvestigatorId = ((Session\["InvestigatorId"\] != null) && int.TryParse(Session\["InvestigatorId"\].ToString(), out InvestigatorId)) ? InvestigatorId : 0; \_objInvestigator = \_objinvestigatorService.GetByInvestigatorId(InvestigatorId); if (\_objInvestigator != null) { if ((\_objInvestigator.CvFile != null) && !string.IsNullOrEmpty(\_objInvestigator.CvFileNameWithExt)) { String ext = System.IO.Path.GetExtension(\_objInvestigator.CvFileNameWithExt); Response.ContentType = "application/" + ext; Response.AddHeader("content-length", \_objInvestigator.CvFile.Length.ToString()); Response.BinaryWrite(\_objInvestigator.CvFile); } } }
And this the code for link button click
protected void loadFile_Click(object sender, EventArgs e)
{
Response.Write(string.Format("<script>window.open('{0}','_blank');</script>", "TheFile.aspx"));
}Any suggestions please?
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
what is the file's extension? .doc or .docx I think it is your content type that is incorrect If the extension is .doc, the content type should be application/msword and if your extension is .docx, the content type should be application/vnd.openxmlformats-officedocument.wordprocessingml.document
-
what is the file's extension? .doc or .docx I think it is your content type that is incorrect If the extension is .doc, the content type should be application/msword and if your extension is .docx, the content type should be application/vnd.openxmlformats-officedocument.wordprocessingml.document
The content type can be three 1. doc, 2. docx and then .pdf but I think I pretty much got answer from you but if you can just give me whats the type for the pdf. Thanks buddy. :)
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
-
what is the file's extension? .doc or .docx I think it is your content type that is incorrect If the extension is .doc, the content type should be application/msword and if your extension is .docx, the content type should be application/vnd.openxmlformats-officedocument.wordprocessingml.document
-
what is the file's extension? .doc or .docx I think it is your content type that is incorrect If the extension is .doc, the content type should be application/msword and if your extension is .docx, the content type should be application/vnd.openxmlformats-officedocument.wordprocessingml.document
Hey buddy still docx is showing binary data doesn't look good to humans man. Here is the code, can you please let me know where did I do mistake?
Investigator _objInvestigator = new Investigator();
InvestigatorService _objinvestigatorService = new InvestigatorService();int InvestigatorId; InvestigatorId = ((Session\["InvestigatorId"\] != null) && int.TryParse(Session\["InvestigatorId"\].ToString(), out InvestigatorId)) ? InvestigatorId : 0; \_objInvestigator = \_objinvestigatorService.GetByInvestigatorId(InvestigatorId); if (\_objInvestigator != null) { if ((\_objInvestigator.CvFile != null) && !string.IsNullOrEmpty(\_objInvestigator.CvFileNameWithExt)) { String ext = System.IO.Path.GetExtension(\_objInvestigator.CvFileNameWithExt); //string path = Server.MapPath("~\\\\E:\\\\karthikeyan\\\\venky\\\\pdf\\\\aaaa.PDF"); //WebClient client = new WebClient(); //Byte\[\] buffer = client.DownloadData(path); //if (buffer != null) //{ if (ext.ToLower() == ".doc") { Response.ContentType = "application/" + "msword"; Response.AddHeader("content-length", \_objInvestigator.CvFile.Length.ToString()); Response.BinaryWrite(\_objInvestigator.CvFile); } else if(ext.ToLower() == ".docx") { Response.ContentType = "application/" + "vnd.openxmlformats-officedocument.wordprocessingml.document"; Response.AddHeader("content-length", \_objInvestigator.CvFile.Length.ToString()); Response.BinaryWrite(\_objInvestigator.CvFile); } else if (ext.ToLower() == ".pdf") { Response.ContentType = "application/" + ext; Response.AddHeader("content-length", \_objInvestigator.CvFile.Length.ToString()); Response.BinaryWrite(\_objInvestigator.CvFile); } } }
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."
-
Hey buddy still docx is showing binary data doesn't look good to humans man. Here is the code, can you please let me know where did I do mistake?
Investigator _objInvestigator = new Investigator();
InvestigatorService _objinvestigatorService = new InvestigatorService();int InvestigatorId; InvestigatorId = ((Session\["InvestigatorId"\] != null) && int.TryParse(Session\["InvestigatorId"\].ToString(), out InvestigatorId)) ? InvestigatorId : 0; \_objInvestigator = \_objinvestigatorService.GetByInvestigatorId(InvestigatorId); if (\_objInvestigator != null) { if ((\_objInvestigator.CvFile != null) && !string.IsNullOrEmpty(\_objInvestigator.CvFileNameWithExt)) { String ext = System.IO.Path.GetExtension(\_objInvestigator.CvFileNameWithExt); //string path = Server.MapPath("~\\\\E:\\\\karthikeyan\\\\venky\\\\pdf\\\\aaaa.PDF"); //WebClient client = new WebClient(); //Byte\[\] buffer = client.DownloadData(path); //if (buffer != null) //{ if (ext.ToLower() == ".doc") { Response.ContentType = "application/" + "msword"; Response.AddHeader("content-length", \_objInvestigator.CvFile.Length.ToString()); Response.BinaryWrite(\_objInvestigator.CvFile); } else if(ext.ToLower() == ".docx") { Response.ContentType = "application/" + "vnd.openxmlformats-officedocument.wordprocessingml.document"; Response.AddHeader("content-length", \_objInvestigator.CvFile.Length.ToString()); Response.BinaryWrite(\_objInvestigator.CvFile); } else if (ext.ToLower() == ".pdf") { Response.ContentType = "application/" + ext; Response.AddHeader("content-length", \_objInvestigator.CvFile.Length.ToString()); Response.BinaryWrite(\_objInvestigator.CvFile); } } }
Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."