首页 > 其他 > 详细

C# 客服端上传文件与服务器器端接收 (简单代码)

时间:2014-03-05 15:12:17      阅读:370      评论:0      收藏:0      [点我收藏+]

 简单代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*服务器端接收写入 可以实现断点续传*/
 public  string  ConnectUpload(string newfilename,string filepath,byte[] fileByte) 
 {
 try{
       string path = adpath + newfilename;                    
       FileStream fs = new FileStream(path, FileMode.Append);
       BinaryWriter w = new BinaryWriter(fs);                    
       fs.Position = fs.Length;                    
       fs.Write(fileByte, 0, fileByte.Length);                    
       w.Close();
       fs.Close();
       return "1";
    }
   catch{
     return "-1";   
    }
 }
 
 /*客户端循环添加*/
 int count = 0;
 int bufferSize = 256;       
 byte[] buffer = new byte[bufferSize];
 while (count < FileUpload1.FileContent.Length)       
 {           
     int bytes = FileUpload1.PostedFile.InputStream.Read(buffer, 0, bufferSize);           
     string result = ConnectUpload(newfilename, filepath, buffer);           
     if (result != "1") //报错           
     {        
          break;
     }    
}

  

C# 客服端上传文件与服务器器端接收 (简单代码),布布扣,bubuko.com

C# 客服端上传文件与服务器器端接收 (简单代码)

原文:http://www.cnblogs.com/lyuec/p/3581040.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!