简单代码:
|
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
原文:http://www.cnblogs.com/lyuec/p/3581040.html