can I use .NET to copy stuff to clipboard?

J

Jeff

hi

..NET 3.5

I'm wondering if I can use .NET/C# to copy stuff to user's clipboard or if I
have to use javascript for this operation?

I suppose I have to use javascript as this occur on the client computer, but
I'm not 100% sure.. maybe C# has some feattures for this which I haven't
heard of...

anyway, I want some text which is not visible to the user to be copied to
the cliboard when the user clicks a hyperlink/linkbutton (if everything done
in C#). In my scenario, the text will be a contain hyperlink. So when link
is clicked it's copied to the clipboard...

any suggestions?
 
N

Nathan Sokalski

I know that if it can be done, it will be done using JavaScript; ASP.NET is
for writing code that gets run server-side. Whether there is a way to do it
in JavaScript, I really don't know, but I wouldn't get my hopes up, since
allowing JavaScript to edit the clipboard might be considered a security
risk (or more appropriately, an annoyance, do you want a website replacing
something you copied to the clipboard with something else?).
 
J

Jeff

do you want a website replacing something you copied to the clipboard with
something else?

Yes, I would like it to do that. In my code there will be a hyperlink the
user have to click on to initiate copying stuff to clipboard.
so the user is choosing it. Modifying clipboard content will not happend
without user asking for it. The hyperlink will have this text: "copy link to
clipboard"
 
A

Alexey Smirnov

hi

.NET 3.5

I'm wondering if I can use .NET/C# to copy stuff to user's clipboard or if I
have to use javascript for this operation?

I suppose I have to use javascript as this occur on the client computer, but
I'm not 100% sure.. maybe C# has some feattures for this which I haven't
heard of...

anyway, I want some text which is not visible to the user to be copied to
the cliboard when the user clicks a hyperlink/linkbutton (if everything done
in C#). In my scenario, the text will be a contain hyperlink. So when link
is clicked it's copied to the clipboard...

any suggestions?

Take a look at this trick
http://ajaxian.com/archives/auto-copy-to-clipboard

Here's an example on how this can be implemented in a real-life
http://www.developerfusion.com/tools/convert/vb-to-csharp/

Please look at the source code of the page
(in http://cdn.developerfusion.com/scripts/site.compressed.js)

Hope this helps
 
A

Alexey Smirnov

And then look at all the blog entries at the bottom about all the hoops you
have to jump through before this even has a chance of working...


This is still dependent on the browser security settings being lowered to
allow scripting to access the clipboard, which is a *MASSIVE* security and
privacy issue... Remember that if a script can write to your clipboard, it
can also read from your clipboard...

Mark, I agree with you regarding security settings. I will prompt
about executing that script if level is "medium high" and nothing
happens if level is "high". In the same time it should work if site is
in trusted sites or security level is "medium" or below. I am not sure
what he is doing and why the link has to be copied, maybe this is kind
of content management system dedicated to limited number of people and
in this case my answer could help to implement his idea. Of course, in
this case users have to modify their security settings to make it
working
 
A

Alexey Smirnov

Mark, I agree with you regarding security settings. I will prompt
about executing that script if level is "medium high" and nothing

***It*** will prompt about
 
J

Jeff

thanks guys, based on the input form you guys I'm redefining the design so
that access to clipboard isn't needed.
 

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