2

For an Intranet web application (document management), I want to show a list of files associated with a certain customer. The resulting HTML is like this:

<a href="file:///server/share/dir/somefile.docx">somefile.docx</a>
<a href="file:///server/share/dir/someotherfile.pdf">somefile.pdf</a>
<a href="file:///server/share/dir/yetanotherfile.txt">yetanotherfile.txt</a>

This works fine. Unfortunetly, when clicking on a text file (or image file), Internet Explorer (and I guess most other browsers as well) insist on showing it in the browser instead of opening the file with the associated application (e.g. Notepad). In our case, this is undesired behavior, since it does not allow the user to edit the file.

Is there some workaround to this behavior (e.g. something like <a href="file:///..." open="external">)? I'm aware that this is a browser-specific thing, and an IE-only solution would be fine (it's an Intranet application after all).

Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • PS: Opening the file on the server and streaming it with `Content-disposition: attachment` is not an option, since this would only allow the user to edit *a local copy* of the file. – Heinzi May 05 '10 at 13:51
  • Even if the user can open the file directly in the appropriate application, the file is still just a local copy. – dnagirl May 05 '10 at 14:10
  • @dnagirl: No, it's not. At least IE is smart enough *not* to download a local copy of the file but to send the UNC path to the application. – Heinzi May 05 '10 at 15:24

2 Answers2

1

Do you WANT people to just mess around with things lying on your server? That reeks of lack of security to me...

I'd recommend letting the user check it out locally and using a database or similar to allow people to check in new drafts. Said drafts should be verified and validated somehow before they are actually written to the server's filesystem.

Platinum Azure
  • 45,269
  • 12
  • 110
  • 134
  • 2
    Yes, this is a requirement. It's a software for small companies where the common files are located on a network share and all files are edited "in-place". File access is managed by NTFS permissions. – Heinzi May 05 '10 at 14:03
0

I just tested this and it seems to work (IE6, not in FF or Chrome):

<HTML>
<script language="JavaScript">
  function startWord(strFile)
  {
    var myApp = new ActiveXObject("Word.Application");
    if (myApp != null)
    {
      myApp.Visible = true;
      myApp.Documents.Open(strFile);
    }
  }
</script>
<a href="javascript:startWord('file:///server/share/dir/test.doc')">test.doc</a>.

Found it here.

J.Hendrix
  • 2,199
  • 4
  • 20
  • 26
  • Thanks, but Word files are not the problem here. The problem are text files, image files, and any other type of file that IE can display inline. – Heinzi May 05 '10 at 15:25
  • You should see the link I referenced. It has other file-types/Program-associations. I can at least get you pointed in the right direction. Another alternative would be to write a custom protocol but this would require an install or regedit on the local machines. – J.Hendrix May 06 '10 at 14:20