How to open MS Office Word in asp.net?

in my application, when the user clicks the button for a specific link, the word MS should open, how can I write code for this. Thanks you

+4
source share
3 answers

It is not possible to guarantee that a particular application will be open when a user clicks a link / button on a web page. The application you are opening is determined by your browser and operating system settings.

As a developer, you can specify the MIME type of the file you are returning. By doing so, you tell the user what type of file the response contains. W3Schools provides a pretty good MIME type for the content list type, and FILExt also provides a MIME type for the files it lists.

Assuming that you specify the appropriate type of MIME content, you can be sure that the user’s browser and operating system will open the file in the appropriate application according to their settings. Since you want to open a Word Document file, the corresponding MIME content type will be one of the following:

  Extension Type / sub-type
  docx application / vnd.openxmlformats-officedocument.wordprocessingml.document
  doc application / msword
 

How and where to specify the type of content depends largely on the type of ASP.NET application you are working with. If you are writing an ASP.NET Webforms application, you must change the MIME type of the Response object in the Page_Load method. In an ASP.NET MVC application, you do this in a controller action. In any case, the specific line of code is the same.

Response.ContentType = "application/msword"; 
+4
source

When you click on the link, redirect the browser to the mydoc.docx file - the browser will open it in Word if they have Word installed. You also need to make sure your IIS server has a MIME type setting, see Downloading Docx from IE - Setting MIME Types in IIS

If you create a Word document on the fly, you will need to set the MIME type so that the browser knows that the answer is a text document. I suggest a docx format for creating content.

+2
source

If this is a Windows application, this should work ...

System.Diagnostics.Process.Start ("FileName.doc");

For a web application, simply redirect the file name to the hosted server or use one of the methods described in the message below ...

http://www.dotnetscraps.com/dotnetscraps/post/4-ways-to-send-a-PDF-file-to-the-IE-Client-in-ASPNET-20.aspx

+1
source

Source: https://habr.com/ru/post/1308212/


All Articles