T
tzachk
I'm using .NET 2.0 with VS 2005 on Windows XP Pro and I'm having
problems with the clipboard.
I'm trying to copy the contents of a word document. The problem is that
sometime it is working, and sometime not, using the same piece of code.
I searched through the internet and implemented all recommendation
including using API (as seen in this article). But nothing helps. It
only works the first time I use the application and then I get null
even though there is content in the clipboard.
Below is an excerpt from my code:
<i><b>private static int Content()
{
// Some code
ClipboardData cd = new ClipboardData(doc); <= Passing Word.Document doc
string text = cd.S;
// some code
}
[Serializable]
public class ClipboardData
{
string s;
string fileName = @"tempClip";
public ClipboardData(Word.Document doc)
{
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
ClipboardHelper.Serialize(fileName);
ClipboardHelper.Deserialize(fileName);
IDataObject data = Clipboard.GetDataObject();
s = data.GetData(DataFormats.Text).ToString();
Clipboard.SetDataObject(string.Empty);
}
public string S
{
get
{
return s;
}
}
}</b></i>
Any help will be highly appreciated as this drives me nuts.
problems with the clipboard.
I'm trying to copy the contents of a word document. The problem is that
sometime it is working, and sometime not, using the same piece of code.
I searched through the internet and implemented all recommendation
including using API (as seen in this article). But nothing helps. It
only works the first time I use the application and then I get null
even though there is content in the clipboard.
Below is an excerpt from my code:
<i><b>private static int Content()
{
// Some code
ClipboardData cd = new ClipboardData(doc); <= Passing Word.Document doc
string text = cd.S;
// some code
}
[Serializable]
public class ClipboardData
{
string s;
string fileName = @"tempClip";
public ClipboardData(Word.Document doc)
{
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
ClipboardHelper.Serialize(fileName);
ClipboardHelper.Deserialize(fileName);
IDataObject data = Clipboard.GetDataObject();
s = data.GetData(DataFormats.Text).ToString();
Clipboard.SetDataObject(string.Empty);
}
public string S
{
get
{
return s;
}
}
}</b></i>
Any help will be highly appreciated as this drives me nuts.