سلام !
عزيزان من مي خواهم يك فايل رو بفرستم به حافظه موقتم (Clipboard) براي اين كار طبق گفته هاي سايت ام اس دي ان و گفته هاي آقا بهزاد از يه آريه براي خوندن فايل از نوع بايت اتفاده كردم . و اونو برابر كردم با يك فايل. سپس اين آرايه رو فرستادم به كليپ بورد اما اونجا خيري از فايل ارسالي نبوده :cry: حالا به نظر شما بايد چه كار كنم ؟؟؟؟؟؟؟؟؟؟؟
اين كار رو دارم با دات نت انجام مي دهم و اينم كل كدي كه به كار بردم
کد:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace CopyToClipBrd
{
public delegate void LineReceive(Form1 sender, string Data);
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
///
private byte[]bufer=new byte[255];
private FileStream s=new FileStream(@"C:\AA.TXT",FileMode.Open);
private string strName;
public string Names
{
get
{
return strName;
}
set
{
strName = value;
}
}
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(80, 104);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 56);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public event LineReceive LineReceived;
private void button1_Click(object sender, System.EventArgs e)
{
try
{
s.BeginRead(bufer,0,255,new AsyncCallback(StreamReceiver),null);
Clipboard.SetDataObject(bufer,true);
}
catch (System.Exception ea)
{
MessageBox.Show(ea.Message);
}
}
private void StreamReceiver(IAsyncResult ar)
{
int BytesRead;
string strMessage;
try
{
// Ensure that no other threads try to use the stream at the same time.
lock (s)
{
// Finish asynchronous read into readBuffer and get number of bytes read.
BytesRead =s.EndRead(ar);
}
// Convert the byte array the message was saved into, minus one for the
// Chr(13).
strMessage = Encoding.ASCII.GetString(bufer, 0, BytesRead - 1);
LineReceived(this, strMessage);
// Ensure that no other threads try to use the stream at the same time.
lock (s)
{
// Start a new asynchronous read into readBuffer.
s.BeginRead(bufer, 0,255, new AsyncCallback(StreamReceiver), null);
}
}
catch( Exception e)
{
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.Text=Clipboard.GetDataObject().ToString();
}
}
}
حالا اگه از اين كد سر در آورديد جوابم رو به زبان دات نت بگوييد ولي اگه نفهميدي ولي روش اصلي ارسال فايل به كليپ بودر رو مي دونيد برام شرح دهيد (لطفا !)
خيلي به كمكتون نيازمندم - با تشكر وحيد