Programmatically add text to the clipboard in C# - c#

Is there a way to programmatically add text to the clipboard in C# (3.5) or javascript ? Does the client machine type make a difference?
Edit: Sorry, forgot to mention am using asp.net.

You can use Clipboard.SetText(string) and Clipboard.GetText() to interact with the clipboard.
See the MSDN article
As long as the client supports .NET, it shouldn't make a difference.
Oh, for the web...
Then use something like this jQuery plugin:
http://plugins.jquery.com/project/clipboard
It will allow you to copy and paste from the clipboard across browsers.

C#: In System.Windows.Forms you have a Clipboard class and a SetText method which probably is what you're looking for. Example:
Clipboard.SetText("My text");
Edit: Since you're looking for a way to set clipboard text on a client computer, here's an updated answer:
There is no browser agnostic way of setting clipboard text. It's possible in Internet Explorer using the following snippet:
window.clipboardData.setData('Text', 'Your text');
In Firefox and Webkit browsers, for security reasons, you need to go via flash to set clipboard text. Zeroclipboard is a nice library for this.

As far as I'm aware in the web world it would be a security issue to access the clipboard without some sort of client side control, i.e. ActiveX control or Flash. So it would prompt for the user to allow the access. Here is something to get you started.

In WinForms there is a static Clipboard class with a SetText method. So you can use
Clipboard.SetText("whatever");
There are some differences to the default text format based on which operating system you are running on: http://msdn.microsoft.com/en-us/library/ydby206k.aspx

You can use Flash.

Related

Is it possible to run exe file with silverlight c# or javascript on client side?

Is it possible to run a .exe file on client side with Silverlight.
Or with javascript or something other.
Thanks
Assuming you mean from the context of a remote domain, most definitely not. Think of the ease with which you might deliver a virus by such a mechanism.
In general no - it would be a huge security hole.
It might be possible for specific browser using plug-ins or ActiveX components (in Internet Explorer) that add such a feature - that will leave the browser very exposed though.
See also this - one of the answers there suggest a clever trick if you want to start from the browser an application that you have control over: have the application installer associate a file extension with its EXE, and then you download from the browser a dummy file with that extension.
Yes, But not seemlessly and not cross browser
Browsers are specifically designed to prvent this sort of thing but....
You can do it in internet explorer through activex javascript
function runApp()
{
var shell = new ActiveXObject("WScript.shell");
shell.run("notepad.exe", 1, True);
}
You might be able to do it via plugin with firefox and chrome, but I don't know and I wouldn't be surprised if you can't

How to get copied text from memory without pasting?

I got one requirement which is when the user copy any text the system should get the copied text from the memory into the program without require the user to paste it in a txtbox or similar control. I searched on the internet but I didn't get any information. can somebody suggest or provide some references so that I can follow...????
any help would be highly appreciated...!!!!
From a web development standpoint, you can not access the clipboard directly. You will have to create either a Flash or Silverlight hook into the clipboard to get the data.
Example
Another Example
For security reasons, you will never be able to do that in Javascript.
As it is already pointed out accessing clipboard is either not possible or restricted for security reasons for all components running on a page in a browser (restricted == is unlikely to be enabled by anyone, especially for such "spy on clipboard" purpose).
For standalone application you can either scan clipboard all the time or use clipboard filters.
Native functions are around SetClipboardViewer and GetClipboardData.
Managed: Clipboard.

C# Flash - ExternalInterface

We are hosting the ActiveX control in a WinForms application to embed flash.
Is there a good way to get the list of visible ExternalInterface functions that are available for any given swf file?
We are working with a 3rd party swf file, and do not have access to source.
If it's not possible from C# (or code), is there a tool out there that can do it?
ANSWER: The only way I've found is to use a flash decompiler and then look for the line:
ExternalInterface.addCallback("methodName", methodName);
I'm marking the top answer as the answer for the help.
As far as I can tell, Flash does not expose its external interface "API" to the environment.
Use event FLASH_CALL on your Flash ActiveX object and decode XML like:
this example.

Drag and Drop a Groupwise Email to C# Winform

I have a need to be able to drag and drop a groupwise email to my winform application and am not having any luck at all.
I am able to get a filename as such but it is only a name, not a path.
Every time I call
e.Data.GetData("FileContents", true))
or
e.Data.GetData("FileContents", false))
or
e.Data.GetData("FileContents"))
I get null returned.
Also, the GetFormats returns something strange and a simple Google search returned nothing. One of the formats was WPOF_DBOBJ_DRN.
If anyone has some insight on this it would be greatly appreciated.
Update:
Just to add a few more details about this, there is also nothing on the clipboard from the drag and drop. Also took a look at the groupwise editor and word perfect isn't even installed on my pc and is most definatly not the editor.
Have a look at the following links (I know, some of them are for Delphi, but you should get the idea):
Drag and drop from an email file attachment in GroupWise to a .NET application
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21198933.html
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23015275.html
I'll take a look at trying that. I've also tried to implement the IStorage interface into an IDataObject interface using unmanaged code and still aren't having any luck. (The Interface is also used to get Outlook messages that are dragged and dropped and works fine.)
That format is most definatly one of the formats i get back from calling e.Data.GetFormats();
I'll take a look at that link. Thanks
WPOF_DBOBJ_DRN looks like WordPerfect Office Format - Database Object. I can't figure out what the DRN stands for though. See if you can open the unreadable file with Word, or WordPerfect if you have it. My guess is that the setup of GroupWise that you are using has WordPerfect as its editor.

Invoke client side MS Word - VS2008/C#3.0

I have a asp.net web site. I want to invoke MS word on a Client machine. Is there any easy way to do this with VS2008, C#3.0?
I can do this with Qt and with an ActiveX control but trying to avoid going this way...
would silverlight be a way to go?
You want to execute an application from the browser (without the evil ActiveX things, of course)?! If you could do that, probably you could wipe off the whole disk too.
And no, Silverlight runs in a partially trusted sandbox. It won't run unmanaged executables on the client machine.
If you are just trying to get Word open to view a document, you could just give your user a link to the .doc/.docx file and their browser would take care of opening the file. If you want to interact with Word, you're going to have a hard time doing that from the browser without using ActiveX.
Silverlight has the same locked down sandbox environment that the web browser has, so that won't help you get around this security limitation.
What are you trying to do with Word? Even if you could launch the app, I don't think you could do any kind of COM interaction from within your web page.
An easy way to merely launch Word would be to have the user download a Word file, but I don't think that's what you're asking and they might not open the file -- they could choose to save it instead.

Categories

Resources