易截截图软件、单文件、免安装、纯绿色、仅160KB

c# 文件传输

send :
string path = "E:\\c#\\convey_file\\convey_file\\Form1.cs"; //要传输的文件
TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("192.168.0.52"),9999);
FileStream file = new FileStream(path,FileMode.Open,FileAccess.Read); //注意与receive的filestream的区别
BinaryReader binaryreader = new BinaryReader(file);
byte[] b = new byte[4098];
int data;
Console.WriteLine("正在发送文件");
while ((data = binaryreader.Read(b, 0, 4098)) != 0) //这个注意是将文件写成流的形式
{
client.Client.Send(b,data,SocketFlags.None); //发送文件流到目标机器
}
client.Client.Shutdown(SocketShutdown.Both);
binaryreader.Close();
file.Close();
receive:
private Socket s;
TcpListener tl;
public void lis()
{
string path = "d:\\1.cs"; //要传入文件的路径
tl = new TcpListener(9999);
tl.Start();
Console.WriteLine("等待接受");
s = tl.AcceptSocket();
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write); //注意这个的属性和send端有所不同
BinaryWriter binarywrite = new BinaryWriter(fs);
int count;
byte[] b = new byte[4098];
while ((count = s.Receive(b, 4098, SocketFlags.None)) != 0) //这个是接受文件流
{
binarywrite.Write(b,0,count); //将接收的流用写成文件
}
binarywrite.Close();
fs.Close();
s.Close();
tl.Stop();
Console.WriteLine("文件传输完毕");


相关文档:

C#与Flash交互

C#与Flash交互 (转自小磊在线)
C#与Flash交互
前段日子公司要求做一个C#与Flash交互的东西,用来C#与短信猫通讯将数据传到Flash上显示与操作的应用。
第一步C#添加组件
打开VS2005-工具-选择工具箱项-COM组件-选择Shockwave Flash Object-确定
添加好组件往场景上拖放,如果提示注册需求注册
c# 注册控件-在运行输 ......

C# asp.net如何使用MD5加密,解密

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;namespace md5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(UserMd5("8"));
Console.WriteLine(GetMd5Str("8"));
}
/**//// <summary>
/// MD5 16位加密 ......

在c#中的取得sql server存储过程的output参数

private void Create_Pz(string Sourcename)
        {
            string OutMsg;
            SqlParameter[] sortPara = { new SqlParameter("@ps_IsType", Pz ......

测试语法高亮的 C# 代码的 html fragment 生成

测试语法高亮的 C# 代码的 html fragment 生成:
用csdn blog API 发布.
下面是:
public class HtmlWriter
{
   static Dictionary _colors;
   static int _colorNum;
   static StringBuilder _colorString;

将TXT文档中数据导入XML文件中 C#

对于将TXT文档中数据导入XML中的程序网上不多,但是有很多是先将TXT导入到DataSet中,在用XML进行传输。所以本人就在这里与大家分享一下直接导入的这种方式。
本程序也可以应用于ASP.NET中,那么下面的命名空间及一些地方就得改改了,还有要将程序都放于Page_Load中。
using System;
using System.Collections.Generic; ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号