Reputation: 727
I'm trying to programming viewing word documents in WPF I using this code
I have this error int this line public partial class MainWindow : Window
the message show 'Window' is an ambiguous reference between ' System.Windows.Window' and ' Microsoft.Office.Interop.Word.window'. how can correct it ?
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
// Create OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".doc";
dlg.Filter = "Word documents (.doc)|*.doc";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
if (dlg.FileName.Length > 0)
{
SelectedFileTextBox.Text = dlg.FileName;
string newXPSDocumentName =
String.Concat(System.IO.Path.GetDirectoryName(dlg.FileName), "\\",
System.IO.Path.GetFileNameWithoutExtension(dlg.FileName), ".xps");
// Set DocumentViewer.Document to XPS document
documentViewer1.Document =
ConvertWordDocToXPSDoc(dlg.FileName,
newXPSDocumentName).GetFixedDocumentSequence();
}
}
}
Upvotes: 2
Views: 2638
Reputation: 9089
Alias Word's Window
class.
using WordWindow = Microsoft.Office.Interop.Word.Window;
using Window = System.Windows.Window;
Then change where you are using Window
from Word to use the new alias WordWindow
.
An example of where it goes:
...
using System.IO;
using Microsoft.Office.Interop.Word;
using Microsoft.Win32;
using WordWindow = Microsoft.Office.Interop.Word.Window;
using Window = System.Windows.Window;
Upvotes: 3