.rtf->clipboard->FreeTextBox

M

Markusek Peter

Hi.
I want to get rtf to my FreeTextBox(ftb instance in code below). So I copy
..rtf to clipboard, and now I want to paste it from clipboard to ftb. But I
got error 'Object reference not set to an instance of an object.'
Here's my code:
--
System.Windows.Forms.RichTextBox MyRTF = new
System.Windows.Forms.RichTextBox();


MyRTF.LoadFile("e:\\projects\\iso\\hmm\\h.rtf");

MyRTF.SelectAll();

MyRTF.Copy();

System.Windows.Forms.IDataObject data =
System.Windows.Forms.Clipboard.GetDataObject();

if (data.GetDataPresent(System.Windows.Forms.DataFormats.Rtf))

{

ftb.Text = data.GetData(System.Windows.Forms.DataFormats.Rtf).ToString();

}

--------------

Here is error:

--

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 67: ftb.ToolbarLayout = "Paste";
Line 68: System.Windows.Forms.IDataObject data =
System.Windows.Forms.Clipboard.GetDataObject();
Line 69: if (data.GetDataPresent(System.Windows.Forms.DataFormats.Rtf))
Line 70: {
Line 71: ftb.Text =
data.GetData(System.Windows.Forms.DataFormats.Rtf).ToString();


==============================

Thanks for help.
 
T

Thomas Johansen

Hi Peter,

I am feeling pretty confident this is caused by the ASPNET user account not
having enough access priviledges to access the windows clipboard. (Also I
wouldn't recommend using System.Windows.Forms namespace in web applications)
The reason I believe this, it that the part of your code that chokes is the
'data' variable - it isn't instantiated (most likely it results in NULL).
 
K

Kevin Spencer

What does this question have to do with ASP.Net? Every reference in it is to
Windows Forms.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
T

Thomas Johansen

Hint: "FreeTextBox" - although I have to admit I was thrown off at first
myself, but I understand what he is trying to accomplish and replied to
him...
 

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

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top