none
Can I open the document in MS word which is already open in AxWebBrowser control ? RRS feed

  • Question

  • I am using AxWebBrowser control AxSHDocVw.AxWebBrowser to open word document in my application.

    here is the code

    if(strFileName.Length != 0)

    {

    Object refmissing = System.Reflection.Missing.Value;

    oDocument = null;

    axWebBrowser1.Navigate(strFileName, ref refmissing , ref refmissing , ref refmissing , ref refmissing);

     }

    So after opened the document(say test1.docx) through AxWebBrowser control can I open the same document(test1.docx) in MS word(by double click) ?

    because if i double click to open same document then document in my application will get removed

    so is there way to prevent user to not open same document if it is already open in AxWebBrowser control ?


    Tuesday, March 12, 2013 10:36 AM

All replies

  • Hello,

    Could you share your project via SkyDrive: https://skydrive.live.com/

    I would like to test your project on my computer.

    I think openning it again should not remove the one in AxWebBrowser since it would be opened in read-only mode.

    Thanks,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 15, 2013 10:32 AM
    Moderator
  • No, I also opened document in MS word in read only mode but still it remove the one in AxWebBrowser.

    I can share my code

     public void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
            {

                //Note: You can use the reference to the document object to
                //      automate the document server.
                if (!successfulLoad)
                    return;
                Object o = e.pDisp;
                if (o != null)
                {
                    oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null);

                    try
                    {
                        Object oApplication = o.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, oDocument, null);
                        if (oApplication != null)
                        {
                            wdApplication = oApplication as Microsoft.Office.Interop.Word.Application;
                            //Object oName = o.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, oApplication, null);
                            //MessageBox.Show("File opened by: " + oName.ToString());
                            wdApplication.DocumentBeforeSave+=new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(wdApplication_DocumentBeforeSave);
                            Type myType = oApplication.GetType();

                            wdApplication.WindowBeforeRightClick += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowBeforeRightClickEventHandler(WordApplication_RightClick);
                            InitializeMenu();
                            DeselectAllFromActiceDocument();
                        }

                    }
                    catch (Exception ex)
                    {
                        Logger.LogErrorMessage(DateTime.Now + " " + ex.Message, "WinWordControl.cs;axWebBrowser1_NavigateComplete2()");
                        Console.WriteLine(ex.Message);
                        //throw new UBmatrix.RBME.Excel.RBMECommon.Exception.FileInUseException();
                    }
                }
            }

    Monday, March 18, 2013 3:49 PM
  • Hi Damon

    Can you share your email id  so that I can share my project on skydrive.



    • Edited by BarunSmart Tuesday, March 19, 2013 9:39 AM
    Tuesday, March 19, 2013 9:38 AM
  • OK, you can share it with this E-mail ID: projectsUpload@outlook

    --------

    Note: This ID is temporarily created only for BarunSmart's sharing.


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 19, 2013 5:18 PM
    Moderator
  • Hi Damon

    I share my sample project.

    Can you please test and tell me if anything wrong in the code.

    Thanks

    Wednesday, March 20, 2013 8:43 AM
  • Hi,

    I have received your project, thanks for sharing.

    And I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Furthermore, I think it would benefit for troubleshooting if you provide the version of MS Office because I suspect this issue is version relevant.

    Sorry for any inconvenience and have a nice day!

    Regards,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 20, 2013 10:32 AM
    Moderator
  • HI,

    I am using Microsoft Office Word 2007(32-bit) and OS-Windows 7.

    Did you able to reproduce the scenario on which I asked this question ?

    Thanks

    Wednesday, March 20, 2013 10:57 AM
  • Hello,

    I was able to recreate the same issue you have described with your code.

    When the document is opened an entry is created in the running object table (ROT).  The ROT a globally accessible look-up table on each workstation. A workstation's ROT keeps track of those objects that can be identified by a moniker and that are currently running on the workstation.  When a client tries to bind a moniker to an object, the moniker checks the ROT to see if the object is already running; this allows the moniker to bind to the current instance instead of loading a new one.  So basically what you are seeing is working as designed.

    I have not found a way to prevent a user from opening a document if it is already opened in the AxWebBrowser control.  I did spend some time trying to create another instance of Word to see if I could avoid using the existing ROT entry but, that lead to more problems.  I was not able to get code that worked well what you are trying to accomplish. 

    One alternative approach you may want to consider is to create a temporary copy of the document and then open that document in the AxWebBrowser control.  That way if someone opens the original document in Word they would be using a different document.  If you think the uses would be making changes to the document through the AxWebBrowser control you would need to have addition code to save those changes back to the original document.


    Thank you, Matt B. Microsoft Online Community Support

    Friday, March 29, 2013 9:17 PM
  • Hi Damon

    Did you find any solution for this issue ?


    • Edited by BarunSmart Tuesday, April 2, 2013 11:11 AM
    Tuesday, April 2, 2013 11:10 AM
  • Hello,

    Have you read Matt's reply? According to his explanation, the issue you encountered is a by design issue. I suggest you following the workaround which provided by Matt: creating a temporary copy of the document and opening the copy in the AxWebBrowser control.

    Best Regards,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 3, 2013 3:31 PM
    Moderator