How to prevent opening .docx files directly from the server in IE?

How to prevent opening .docx files directly from the server in IE?

by Samuli Koskinen -
Number of replies: 8

Hi,

I'm using Moodle 2.6 and I have a problem with opening .docx files in Internet Explorer:

When I add a .docx attachment to a assignment and click it I get the option to open it or download it. 

open

If I choose open, the document opens in Word in Protected View mode.

protectedview

If I click the enable editing button, the moodle login page opens inside Word (apparently because the user has no permission to edit the attachment):

login


So the point is I want to prevent this from happening. This situation can be avoided if the document is downloaded instead of opening it, but I want to completely remove the possibility of this happening.

I guess the best way would be to force the file to download (in moodle 1.9 I used the forcedownload=1 parameter), but I don't know how to do it in Moodle 2.6. There is a built-in option to force download for the "file" resource but this cannot be done for an attachment.

Any help on the topic is highly appreciated! smile

Samuli


Average of ratings: Useful (2)
In reply to Samuli Koskinen

Re: How to prevent opening .docx files directly from the server in IE?

by Samuli Koskinen -

BUMP!

In reply to Samuli Koskinen

Re: How to prevent opening .docx files directly from the server in IE?

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Samuli,
never thought at it but you can try - not tested so it couldn't work - to change a line in the assigment code, mod/assign/lib.php::assign_pluginfile(), to always force the download:

diff --git a/mod/assign/lib.php b/mod/assign/lib.php
index f8faee1..abe5176 100644
--- a/mod/assign/lib.php
+++ b/mod/assign/lib.php
@@ -1287,5 +1287,5 @@ function assign_pluginfile($course,
     if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
         return false;
     }
-    send_stored_file($file, 0, 0, $forcedownload, $options);
+    send_stored_file($file, 0, 0, true, $options);
 }

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: How to prevent opening .docx files directly from the server in IE?

by Samuli Koskinen -

Thank you for your suggestion, but it looks like that function is missing completely in Moodle 2.6 /mod/assign/lib.php (It can be found in the 2.8 version of the /mod/assign/lib.php).

There are similar functions in /mod/assign/feedback/file/lib.php and /mod/assign/submission/file/lib.php that handle the file in IE just like I wanted to, but not in mod/assign/lib.php. So I can find how moodle handles the feedback and submission files of the assignment, but not how it handles attachment files of the assignment.

Do you think it is possible to implement this function that handles assignment attachments to moodle 2.6?

Thanks,

Samuli

In reply to Samuli Koskinen

Re: How to prevent opening .docx files directly from the server in IE?

by Robin Leung -

I have reports of this as well with the latest version of IE 11, running on Windows 8.1, and using the latest Office suite 2013.

In reply to Samuli Koskinen

Re: How to prevent opening .docx files directly from the server in IE?

by Chris Wharton -

The correct way to do this is to add the forcedownload parameter to the download link url - e.g. https://mysite.org/pluginfile.php/11530/block_html/content/Quick%20user%20guide%20v1.3.pdf?forcedownload=1

Average of ratings: Useful (1)
In reply to Chris Wharton

Re: How to prevent opening .docx files directly from the server in IE?

by Robin Leung -

Thanks Chris.

How do you go about doing that?

I've found another solution and that is to adjust the "Protected view" settings in Microsoft Office that also solved the issue.

In reply to Robin Leung

Re: How to prevent opening .docx files directly from the server in IE?

by Chris Wharton -

The above method really only works for manually created links that can be edited. The assignment module auto-generates those links.

I've tried uploading then downloading an assignment file, on a test site, and the download url actually already had forcedownload=1 set. Maybe IE is ignoring this parameter.

In reply to Chris Wharton

Re: How to prevent opening .docx files directly from the server in IE?

by Robin Leung -
Yes, IE seems to be having the way like you described it to be. I've tried to replicate the problem with the latest version of IE on Windows 7 Enterprise but can't seem to replicate the problem.

However, problem seems to be revolving around Windows 8.1 with latest version of IE 11.