public interface IClipboard
{
string Image { get ; }
string Text { get ; set ; }
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class ClipboardProxy : IClipboard
{
public string Image
{
get
{
Image img = Clipboard.GetImage();
if (img == null )
return null ;
string fileName = Guid .NewGuid().ToString().Split( new char [] { '-' })[0] + ".png" ;
PutFile(fileName, img);
return fileName;
}
}
public string Text
{
get
{
return Clipboard.GetText();
}
set
{
Clipboard.SetText( value );
}
} }
* This source code was highlighted with Source Code Highlighter .
private void PutFile( string name, Image img)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create( new Uri ( "http://helpdesk/ServicePages/upload.jsp" ));
request.Credentials = CredentialCache.DefaultNetworkCredentials;
string folder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
folder += "\\ " + name;
img.Save(folder);
FileInfo fileInfo = new FileInfo(folder);
request.PostMultiPartAsync( new Dictionary< string , object > { { "uploadfile" , fileInfo } }, new AsyncCallback(asyncResult =>
{
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string s = reader.ReadToEnd();
if (response.StatusCode == HttpStatusCode.OK)
{
}
response.Close();
}));
}
* This source code was highlighted with Source Code Highlighter .
regasm < >.dll /tlb /codebase
< script language ="javascript" >
<!-- Load the ActiveX object -->
var xClipboard = new ActiveXObject( "Megafon.ClipboardHelper.ClipboardProxy" );
function GetClipboardImage()
{
return xClipboard.Image;
}
</ script >
* This source code was highlighted with Source Code Highlighter .
private void tbxDescription_KeyDown( object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == (Key.F12))
{
this .Dispatcher.BeginInvoke(( delegate ()
{
object obj = HtmlPage.Window.Eval( "(function(){ return GetClipboardImage(); })()" );
if (obj != null )
{
_attach.Add( new AttachItem() { FileName = obj.ToString() });
}
}));
}
}
* This source code was highlighted with Source Code Highlighter .
HtmlPage.Window.Eval( "window.clipboardData.getData('Text')" );
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/65748/
All Articles