#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    2
    Rep Power
    0

    Launching MS Word to open file from a hyperlink?


    Wondering if this can be done. I have the path generated from asp variables. I have the following code:

    <a href="file:<%=sPath & sYear & "\" & sFileName%>" TARGET="_blank">Open Generated File</a>

    This will launch the file in an IE window. I was wondering if it would be possible to have the same link above but have word open the file instead of IE? Have something like a jscript function that does onclick...blah..blah. Is this possible? If so, any sample coding or where to get more information would be great
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    4
    Rep Power
    0
    If you link to a .doc file and the user's machine has a file association setup so that .doc files are opened with Word, whenever they click on the link it will open the file with word. You can put this in a new window using the target property as you have done in your example.

    Just make sure the file that is linked to is a .doc

    HTH
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    2
    Rep Power
    0
    hey valeech,

    tks for the reply. I tested out the file association and my machine already has .doc files associated with MS Word. I kept the target=_blank, should this be changed? As an alternative, in case anyone here wanted to know, I found some jscript code that does this for you. Here is the sample coding that I used to launch the link in MS Word:

    <a href="javascript:startWord('<%= sPath2 &sYear& "/"& sFileName%>')">Open Generated File</a>

    and add the following jscript:

    <script language="JavaScript">
    function startWord(strFile)
    {
    var myApp = new ActiveXObject("Word.Application");
    if (myApp != null)
    {
    myApp.Visible = true;
    myApp.Documents.Open(strFile);
    }
    }
    </script>


    Note: in order to link to UNC paths, make sure that strFile is using "/" in its path versus the conventional "\". For eg. use:
    //computer/folder/file instead of \\computer\folder\file.

IMN logo majestic logo threadwatch logo seochat tools logo