Problem with clipboard

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.
 
T

tzachk

tzachk said:
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.

The article I'm refering to is
http://www.codeproject.com/cs/system/clipboard_backup_cs.asp
 
T

tzachk

Isn't there anyone here that has experience with the clipboard?
tzachk said:
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.

The article I'm refering to is
http://www.codeproject.com/cs/system/clipboard_backup_cs.asp
 

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