Downloading Word Document in Browser

Go To StackoverFlow.com

2

I have a Microsoft Word document that I would like to link to in my site. The document is actually hosted on another server (Internal SharePoint site). I would like it if when the user clicks the link that it opens the document in their browser by default. If not possible then it will prompt them for download.

Is this possible for me to control or is it only something each individual user has to set up on their machines?

2012-04-04 20:36
by Dismissile


1

If the user can access the Sharepoint site, you can just link to download link of the document on the Sharepoint site?

If the user cannot acces the Sharepoint site, you could stream it yourself, but that's hardly recommended.

Why can't you just link to the download link of the document?

EDIT:

You specifically want to know how to make sure the link opens directly. For this you need to change the MIME type of the Response (the download) to provide more info to the browser how it can open that link. More info in this answer: https://stackoverflow.com/a/2806749/65087

In my applications, I generally create a Util method that can provide a MIME type, based on the extension.

This solution will work if you can offer the download yourself for your Controller, eg. by calling the File() ActionResult. This also requires you to have access to the physical file, so you can stream it.

So, I'm not sure this fully answers your question, since you said the document is on a Sharepoint site...?

2012-04-04 20:40
by Bertvan
That is what I'm doing. I want to know if I can somehow force it to open in their browser instead of prompting them for a file download. I've been to some sites where clicking on a PDF file or a word document will open it directly in the browser (if the machine has a plugin). I'm asking if it's something I can control or only something a user can control - Dismissile 2012-04-04 20:41
OK, modifying my answer on how you can do tha - Bertvan 2012-04-04 20:50
That's what I thought. Since the file is hosted somewhere else I can't use File() to stream it. I will either have to change it to host the file myself or tell the users that it's not going to open directly - Dismissile 2012-04-04 21:28
Ads