Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

problem in using clipboard class in webapplication

Posted on 2009-04-06
4
Medium Priority
?
406 Views
Last Modified: 2013-12-17
Hi

I was reading an article on clipboard.

http://www.codeproject.com/KB/shell/clipboard01.aspx?print=true

But when I am using this code on the web application I am getting runtime error.


"object reference is not set"

I am attaching the code where I am getting this error.

Can't we use it in web application
if(Clipboard.GetDataObject().GetDataPresent(DataFormats.Text))

Open in new window

0
Comment
Question by:KaranGupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24075690
I'm guessing that you've included a reference to System.Windows.Forms so that you are able to use the Clipboard object.

You might try calling the Clipboard methods in a Single Thread Aparment (STA).

However, you may find some nasty side effects using the clipboard in a Web App. If two users call the same method at the same time, one my place data in the clipboard, and the other retrieves that data.
Private Sub ee24297524()
    Dim td As New System.Threading.Thread(AddressOf GetClipboardText)
    td.ApartmentState = System.Threading.ApartmentState.STA
    td.Start()
    td.Join()
End Sub
 
Private Sub GetClipboardText()
    Dim b As Boolean = System.Windows.Forms.Clipboard.ContainsText()
End Sub

Open in new window

0
 
LVL 16

Expert Comment

by:sunithnair
ID: 24075695
Why would you want to do this in a web application? This code and post is useful only in the context of a winforms application. If you need to access the client clipboard data then you will have to do it using javascript.
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24075929
Thanks for the points, I gave an answer that would work, but I do agree with sunithnair.
I'd recommend using the Session variable, the cache or a temp file instead of the clipboard.
0
 
LVL 3

Expert Comment

by:techprocess
ID: 24206509
Where to call ee24297524() given in above comment. I getting error -
"the Current thread must be set to single thread apartment (STA) mode before
OLE calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it. This exception is only raised if a debugger is attached to the
process."
Is there is any solution?
Regards,
Krishna Mohan Singh
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question