I have a word file stored in a path.
I want to open it using C# code on click of a link.
How to Proceed?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sahil Jani196 reputationPosted Apr 17, 2011, 11:06 PM EDT
Try this code... This will help you out.. . :
Response.Clear();
Response.ContentType = "application/msword"; //change the content here based on different files type
Response.AddHeader("Content-Disposition", "inline;filename=abc.doc");
Response.WriteFile();
Response.End();
Response.Flush();
If you found this answer as helpfull to you then marked this answer as an "ACCEPTED ANSWER"Sahil Jani196 reputationPosted Apr 17, 2011, 11:10 PM EDT
Above code is only for opening a word file but if you want to open any filetype means any file's extention see the attached file overhere.
If you found this answer as helpfull to you then marked this answer as an "ACCEPTED ANSWER"
Chandra Sekhar K160 reputationPosted Apr 18, 2011, 8:14 PM EDT
Sahil Jani196 reputationPosted Apr 18, 2011, 8:33 PM EDT
Sorry once again.
Ankit NandekarRank #703 · 3.4K reputationPosted Apr 18, 2011, 9:04 PM EDT
private string GetDocumentMimeType(string fileName)
{
//string mimeType = "application/unknown";
string mimeType = "application/vnd.msword.document.12";
string ext = System.IO.Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("Content Type") != null)
mimeType = regKey.GetValue("Content Type").ToString();
return "//" + mimeType;
}
For more detail Search article
VulpesRank #55 · 29.2K reputationPosted Apr 19, 2011, 1:32 AM EDT
System.Diagnostics.Process.Start(fullFilePath); // .doc or .docx
Sam HobbsRank #107 · 20.5K reputationPosted Apr 19, 2011, 1:31 PM EDT