none
Can I use the Microsoft.Office.Interop.Word .dll in Silverlight to manipulate the SaveDialogFile of MSWord? RRS feed

  • Question

  • I have problem in making silverlight application, I need to create a Word Document using silverlight and the Save it directly to the database using the Default Save button in MSWord, but then I cannot use the "Microsoft.Office.Interop.Word .dll" in silverlight to manipulate the SaveFileDialog so that I can set the Default path when saving..

    Another question is, can I hide or set the MSWord SaveFileDialog = false in Silverlight using Microsoft.Office.Interop.Word .dll? because my other plan is that to create a custom savefiledialog box in Silverlight and not to use the MSWord SaveFileDialog box..?

    I use the Silverlight 5 Beta, is there any compatibility issue in using other version of MS Office.?

    public partial class MainPage : UserControl 
     
    { 
         
    dynamic objWord; 
         
    dynamic document; 
         
    dynamic range; 
         
    static bool saveDoc = false; 
     
         
    public MainPage() 
         
    { 
             
    InitializeComponent(); 
             objWord
    = AutomationFactory.CreateObject("Word.Application");  
             
    AutomationEvent saveEvent = AutomationFactory.GetEvent(objWord, "DocumentBeforeSave"); 
             saveEvent
    .EventRaised += (s, args) => 
             
    { 
                 saveDoc
    = true; 
     
                 
    if (saveDoc == true) 
                 
    { 
                     
    SaveFileDialog dlg = new SaveFileDialog(); 
                     dlg
    .DefaultExt = ".doc"; // Default file extension 
                     dlg
    .Filter = "Word documents (.doc)|*.doc"; // Filter files by extension 
                     
    Nullable<bool> result = dlg.ShowDialog(); 
     
                     
    if (result == true) 
                     
    { 
                         
    string filename = dlg.SafeFileName; 
                         
    FileInfo aD = new FileInfo(filename); 
                         
    string pathDoc = aD.DirectoryName.ToString(); 
                         
    MessageBox.Show(pathDoc); //trying to get the path so that i can flush it to memory stream 
                     
    } 
                 
    } 
             
    }; 
         
    } 
     
         
    private void Button_Click(object sender, RoutedEventArgs e) 
         
    { 
             
    if (AutomationFactory.IsAvailable) 
             
    { 
                 
    try 
                 
    { 
                     document
    = objWord.Documents.Add(); 
                     
    object startIndex = 0; 
                     range
    = document.Range(ref startIndex); 
                     objWord
    .Visible = true; 
                 
    } 
                 
    catch (Exception ex) 
                 
    { 
                     
    MessageBox.Show(ex.Message); 
                 
    } 
             
    } 
         
    } 
    } 

    • Moved by Cindy Meister MVPModerator Friday, November 18, 2011 7:04 PM not using VSTO technology (From:Visual Studio Tools for Office)
    Friday, November 18, 2011 10:49 AM

All replies

  • Dear Jakoo,

    Based on my experience, your goal may not be achieved in Silverlight when automating Office, because we can't add the reference to the Silverlight application. As a result, we can't get the dialog via the code:

    http://blogs.msdn.com/b/ptorr/archive/2004/01/28/63741.aspx

    Word.Dialog fileSaveAsDlg;

    fileSaveAsDlg = thisApplication.Dialogs[Word.WdWordDialog.wdDialogFileSaveAs];

    In silverlight, when automating Office, there are a lot of limited features. Hope you can figured out about this.

    Regards,


    Be happy.
    Monday, November 21, 2011 7:21 AM
  • Is there other possible way in Silverlight that I can use the Word Document and save it to the database and when I click the save button it can save directly to database/ or remote server..? like in Sharepoint List, after uploading the MS Word file it can directly save the changes in the remote server...

     

    Thank you for your reply... :)

     

    Wednesday, November 23, 2011 10:38 AM