Viewing Word documents in WPF
I am trying to program a text document viewer in WPF I using this code I have this error int this line the public partial class MainWindow : Window
message "Window" is an ambiguous reference between "System.Windows.Window" and "Microsoft.Office.Interop.Word.window". How to fix 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();
}
}
}
+3
source to share
1 answer
Alias ββWord 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;
+3
source to share