Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a word doc/rtf file and got some code that it will convert to it xps doc and It can be loaded in the DocumentViewer, I have a button that will open the file in ms word so it can be edited and saved. The problem is since the xps file is open in documentviewer, I was not able to reload the xps document in document viewer. Can some help me unloading file in document viewer. Below is my code.

C#
private XpsDocument ConvertWordDocToXPSDoc(string wordDocName, string xpsDocName)
		{

			// Create a WordApplication and add Document to it
			Microsoft.Office.Interop.Word.Application
				wordApplication = new Microsoft.Office.Interop.Word.Application();
			wordApplication.Documents.Add(wordDocName);

			Document doc = wordApplication.ActiveDocument;			
			try
			{
				doc.SaveAs(xpsDocName, WdSaveFormat.wdFormatXPS);
				wordApplication.Quit();
				XpsDocument xpsDoc = new XpsDocument(xpsDocName, FileAccess.ReadWrite);
				return xpsDoc;
			}
			catch (Exception exp)
			{
				string str = exp.Message;
			}
			return null;
		}

		private void LoadMyreminder()
		{
			string XPSMyReminder = String.Concat(Path.GetDirectoryName(_myReminder), "\\",
						   Path.GetFileNameWithoutExtension(_myReminder), ".xps");
			myRemviewer.Document = ConvertWordDocToXPSDoc(
				_myReminder,
				XPSMyReminder).GetFixedDocumentSequence();
			
		}

		private void BtnEditMyrem_Click(object sender, RoutedEventArgs e)
		{
			Microsoft.Office.Interop.Word.Application ap = new Microsoft.Office.Interop.Word.Application
			{
				Visible = true
			};
			Document document = ap.Documents.Open(_myReminder);

		}


What I have tried:

searching google, try to close the doc file by using Xpsdocument Close
Posted
Comments
[no name] 26-Sep-19 12:28pm    
Make a copy.
Erwin Alcantara 26-Sep-19 12:45pm    
Didn't get it well.. How?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900