none
Document Library selected it open in word using programmatically RRS feed

  • Question

  • Hello All,

    I have SharePoint Document Library with the word document, I want to open word document in MS Word with the programmatically in c# with the Document sync mode.

    Thanks

    Wednesday, January 4, 2017 12:09 PM

All replies

  • You can use .NET managed Word programming to open the file from SharePoint library.

    Once you provide a proper path of file in open command, it will allow to work in sync mode.


    Thanks, Ashish | Please mark a post helpful/answer if it is helpful or answer your query.

    Thursday, January 5, 2017 12:11 AM
  • I am using this code to open the word document file in MS word form the SharePoint Library with the sync mode.

    object missing = System.Reflection.Missing.Value;
    object readOnly = false;
    object isVisible = true;
    string file = "SharepointURL";
    
    Microsoft.SharePoint.Client.File newFile = client.Web.GetFileByServerRelativeUrl(file);
    client.Load(newFile);
    client.ExecuteQuery();
    object nfile = newFile;
    
    Microsoft.Office.Interop.Word.Application applicationWord = new Microsoft.Office.Interop.Word.Application();
    Microsoft.Office.Interop.Word.Document modelloBusta = new Microsoft.Office.Interop.Word.Document();
    
    applicationWord.Visible = true;
    
    modelloBusta = applicationWord.Documents.Open(ref nfile, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
    modelloBusta.Activate();

    Its give me this error : Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

    Thursday, January 5, 2017 6:51 AM
  • Hi Ashish,

    Even I want to do the same and have used the .Net managed word programming, but I am getting the below error.

    Additional information: Sorry, we couldn't find your file. Was it moved, renamed, or deleted?

    Let me know if you need anything else.

    Thanks.

    Thursday, January 5, 2017 8:03 AM
  • Hi,

    I tested this and it’s working in my local.

     static void Main(string[] args)
            {
                Microsoft.Office.Interop.Word.Application applicationWord = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document modelloBusta = new Microsoft.Office.Interop.Word.Document();
    
                applicationWord.Visible = true;
    
                object missing = System.Reflection.Missing.Value;
                object readOnly = false;
                object isVisible = true;
                object fileName = @"http://sp:12001/Shared%20Documents/test.docx";
    
                modelloBusta = applicationWord.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
                modelloBusta.Activate();
                Console.ReadKey();
    
            }

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, January 6, 2017 7:17 AM
  • Hi,

    Is any update for your issue?

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, January 16, 2017 10:11 AM