Copy-paste office documents via clipboard

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
 
J

JensB

Hi

I am not a C# programmer, but if you want to bring the content from a
word.doc file to another,
you could use this wordbasic command:
selection.InsertFile(documentFilename)

Might be at some help.

JensB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top