Hello all,
Is there any way to take a selection from MS Word using VSTO, and convert that selection to rtf Right now here is the code which uses the clipboard:
private string ConvertToRTF(Word.XMLNode node)
{
string strData = ""; try{
// Copy to clipboard (This will erase the clipboard contents that the user entered into here before!!!node.Range.Copy();
strData =
Clipboard.GetText(TextDataFormat.Rtf); Clipboard.Clear();}
catch (Exception ex){
Trace.WriteLineIf(logic.ASI3Reporting.TraceError, "Error converting to rtf: " + ex.ToString(), "Errors"); string ss = ex.ToString();}
return strData;}
The problem with the code is that the clipboard contents are now replaced with my selection thus replacing the value at the top of the clipboard stack so the end user won't have their original copied data. I need to copy this because this is the only way that I can get the selection converted to rtf. Another method would require saving the entire document to disk as rtf but this would only work for the entire document, whereas, I need to convert only a selection.
Any help would be greatly appreciated.