B
braz
Copy-paste office documents via clipboard
Hello!
I need to copy paste office documents via clipboard. I wrote next code:
public void InsertDocument(object mDocument, string documentFileName)
{
if(mDocument!=null)
{
FileStream fileStream = new FileStream(documentFileName,FileMode.Open);
byte[] file = new byte[(int)fileStream.Length];
fileStream.Read(file,0,(int)fileStream.Length);
fileStream.Close();
Clipboard.SetDataObject(new
DataObject(System.Windows.Forms.DataFormats.FileDrop,file), false);
object selection = mDocument.GetType().InvokeMember("Selection",
BindingFlags.GetProperty, null, mMSWord, null);
selection.GetType().InvokeMember("Paste",BindingFlags.InvokeMethod, null,
selection, null);
}
}
The last command couses inner exception "command error". Is there wrong
DataFormat ? What should I put to the clipboard, file in binary or file path
as a string ? What should I correct to get it working ?
Thanks
Hello!
I need to copy paste office documents via clipboard. I wrote next code:
public void InsertDocument(object mDocument, string documentFileName)
{
if(mDocument!=null)
{
FileStream fileStream = new FileStream(documentFileName,FileMode.Open);
byte[] file = new byte[(int)fileStream.Length];
fileStream.Read(file,0,(int)fileStream.Length);
fileStream.Close();
Clipboard.SetDataObject(new
DataObject(System.Windows.Forms.DataFormats.FileDrop,file), false);
object selection = mDocument.GetType().InvokeMember("Selection",
BindingFlags.GetProperty, null, mMSWord, null);
selection.GetType().InvokeMember("Paste",BindingFlags.InvokeMethod, null,
selection, null);
}
}
The last command couses inner exception "command error". Is there wrong
DataFormat ? What should I put to the clipboard, file in binary or file path
as a string ? What should I correct to get it working ?
Thanks