locked
How to open multiple windows to display Word documents RRS feed

  • Question

  • I have a button_click event in an ASP.NET page which creates multiple Word documents, saving them to a shared file server (or in SharePoint, for internet deployment). I need each document to open in a separate window, so users can edit, print and save them individually.

     

        protected void multipleDocsButton_Click(object sender, EventArgs e)

        {

            . . .

            // This doesn't work; only the second document gets opened.

            Response.Redirect("file://myShare/doc1.doc", false);

            Response.Redirect("file://myShare/doc2.doc", false);

     

            // This opens a separate blank IE window before opening each file in Word.

            ScriptManager.RegisterStartupScript(this, typeof(string), "key1",

                "open('file://myShare/doc1.doc');\n", true);

            ScriptManager.RegisterStartupScript(this, typeof(string), "key2",

                "open('file://myShare/doc2.doc');\n", true);

            . . .

        }

     

    How can I do this without opening extra browser windows? And letting the page with the button complete its Ajax activity?

    Thanks.

    Tuesday, April 22, 2008 5:45 PM

Answers

  • Greg Becker found a solution:

        // This closes the extra windows.

        ScriptManager.RegisterStartupScript(this, typeof(string), "1",

            "winref = window.open('file://myShare/doc1.doc');\n winref.close();", true);

        ScriptManager.RegisterStartupScript(this, typeof(string), "2",

            "winref = window.open('file://myShare/doc2.doc');\n winref.close()", true);

    (Won't work if users choose Browse in same window.)
    Wednesday, April 23, 2008 8:09 PM

All replies

  •  

    What version of office are you using?

     

    Tuesday, April 22, 2008 7:49 PM
  • I'm using Office 2007, but I didn't think that mattered; I would like users with Word 2003 to see their documents open in Word as well. When my application provides a link to a Word document, Internet Explorer can display it in the browser window with limited editing capability, or open the document in Microsoft Word (which is preferable). Here is a way to always make it come up in Word (I found on an MSDN blog):
    1. Launch Windows Explorer.
    2. Select “Folder Options...” from the Tools menu.
    3. Select the “File Types” tab.
    4. Scroll down the list of “Registered file types” until you find “DOC - Microsoft Word Document” and select it.
    5. Click on the “Advanced...” button at the bottom of the dialog.
    6. Uncheck the “Browse in same window” checkbox.

     

    Tuesday, April 22, 2008 7:55 PM
  •  

    You could try "open('file://myShare/doc1.doc', '_self');\n"

     

    But I'm not sure that will help.  The problem is its the window that navigates to the file.  The file isn't fetched and then the appropriate window opened.  Hence by the time the navigation to the word document is executed the browser window is open.  If word chooses not use that window then its just left there. 

    Tuesday, April 22, 2008 8:39 PM
  • Greg Becker found a solution:

        // This closes the extra windows.

        ScriptManager.RegisterStartupScript(this, typeof(string), "1",

            "winref = window.open('file://myShare/doc1.doc');\n winref.close();", true);

        ScriptManager.RegisterStartupScript(this, typeof(string), "2",

            "winref = window.open('file://myShare/doc2.doc');\n winref.close()", true);

    (Won't work if users choose Browse in same window.)
    Wednesday, April 23, 2008 8:09 PM
  • Hi, this function is not working in both FireFox n Opera...
    Saturday, March 27, 2010 11:08 AM
  • The following tip can be used to avoid any problem in opening a word document in multiple versions of MS Word in different systems. If we have a reference to Microsoft Word 8.0 Object Library and wrote the following code in VB.Net to open a word document. Dim oWord As Word.ApplicationClass oWard = CreateObject("Word.Application") oWord.Visible = True oWord.documents.Open(Application.StartupPath & "\File1.doc") This method is called the Early binding way to programmatically control another application. But above code may result in popping up an error message such as : QueryInterface for interface for word._Application failed at Word.ApplicationClass.set_Visible(Boolean prop) http://www.mindfiresolutions.com/Opening-a-word-document-in-multiple-versions-of-WordNET-Windows-Application-188.php
    Cheers, Eliza
    Thursday, June 3, 2010 1:13 PM