首页 新闻 搜索 专区 学院

winform 上传

0
悬赏园豆:100 [已解决问题] 解决于 2011-01-08 10:11

最近新一编辑器,需要将本地的文件上传到远程服务器..比如有个上传按钮,点击按钮后,可以把我本地E:\upload\文件里的一个或者多个文件夹上传到服务器指定的文件里,请教各位,该怎么解决...来者给分...

comeonfyz的主页 comeonfyz | 初学一级 | 园豆:14
提问于:2011-01-05 18:20
< >
分享
最佳答案
0

哥们儿,我帮帮你。这是我的FTP帮助类,对你一定有帮助的。

照我这个没得错。

 

1 #region 版权信息
2  /*---------------------------------------------------------------------*
3 // Copyright (C) 2009 http://www.cnblogs.com/huyong
4 // 版权所有。
5 // 项目 名称:《Winform通用控件库》
6 // 文 件 名: FTPHelper.cs
7 // 类 全 名: DotNet.Common.FTPHelper
8 // 描 述: FTP处理操作类
9 // 创建 时间: 2009-03-21
10 // 创建人信息: [**** 姓名:胡勇 QQ:80368704 E-Mail:80368704@qq.com *****]
11 *----------------------------------------------------------------------*/
12  #endregion
13
14 using System;
15 using System.Collections.Generic;
16 using System.Text;
17 using System.Net;
18 using System.IO;
19 using System.Globalization;
20 using System.Text.RegularExpressions;
21
22 namespace DotNet.Common
23 {
24 /// <summary>
25 /// FTP处理操作类
26 /// 修改纪录:
27 /// 2009-03-21 胡勇 创建“FTP处理操作类”
28 /// </summary>
29 /// <remarks>
30 /// 功能:
31 /// 下载文件
32 /// 上传文件
33 /// 上传文件的进度信息
34 /// 下载文件的进度信息
35 /// 删除文件
36 /// 列出文件
37 /// 列出目录
38 /// 进入子目录
39 /// 退出当前目录返回上一层目录
40 /// 判断远程文件是否存在
41 /// 判断远程文件是否存在
42 /// 删除远程文件
43 /// 建立目录
44 /// 删除目录
45 /// 文件(目录)改名
46 /// </remarks>
47 /// <author>
48 /// <name>胡勇</name>
49 /// <QQ>80368704</QQ>
50 /// <Email>80368704@qq.com</Email>
51 /// </author>
52 /// </summary>
53 public class FTPHelper
54 {
55 #region 属性信息
56 /// <summary>
57 /// FTP请求对象
58 /// </summary>
59 FtpWebRequest Request = null;
60 /// <summary>
61 /// FTP响应对象
62 /// </summary>
63 FtpWebResponse Response = null;
64 /// <summary>
65 /// FTP服务器地址
66 /// </summary>
67 private Uri _Uri;
68 /// <summary>
69 /// FTP服务器地址
70 /// </summary>
71 public Uri Uri
72 {
73 get
74 {
75 if (_DirectoryPath == "/")
76 {
77 return _Uri;
78 }
79 else
80 {
81 string strUri = _Uri.ToString();
82 if (strUri.EndsWith("/"))
83 {
84 strUri = strUri.Substring(0, strUri.Length - 1);
85 }
86 return new Uri(strUri + this.DirectoryPath);
87 }
88 }
89 set
90 {
91 if (value.Scheme != Uri.UriSchemeFtp)
92 {
93 throw new Exception("Ftp 地址格式错误!");
94 }
95 _Uri = new Uri(value.GetLeftPart(UriPartial.Authority));
96 _DirectoryPath = value.AbsolutePath;
97 if (!_DirectoryPath.EndsWith("/"))
98 {
99 _DirectoryPath += "/";
100 }
101 }
102 }
103
104 /// <summary>
105 /// 当前工作目录
106 /// </summary>
107 private string _DirectoryPath;
108
109 /// <summary>
110 /// 当前工作目录
111 /// </summary>
112 public string DirectoryPath
113 {
114 get { return _DirectoryPath; }
115 set { _DirectoryPath = value; }
116 }
117
118 /// <summary>
119 /// FTP登录用户
120 /// </summary>
121 private string _UserName;
122 /// <summary>
123 /// FTP登录用户
124 /// </summary>
125 public string UserName
126 {
127 get { return _UserName; }
128 set { _UserName = value; }
129 }
130
131 /// <summary>
132 /// 错误信息
133 /// </summary>
134 private string _ErrorMsg;
135 /// <summary>
136 /// 错误信息
137 /// </summary>
138 public string ErrorMsg
139 {
140 get { return _ErrorMsg; }
141 set { _ErrorMsg = value; }
142 }
143
144 /// <summary>
145 /// FTP登录密码
146 /// </summary>
147 private string _Password;
148 /// <summary>
149 /// FTP登录密码
150 /// </summary>
151 public string Password
152 {
153 get { return _Password; }
154 set { _Password = value; }
155 }
156
157 /// <summary>
158 /// 连接FTP服务器的代理服务
159 /// </summary>
160 private WebProxy _Proxy = null;
161 /// <summary>
162 /// 连接FTP服务器的代理服务
163 /// </summary>
164 public WebProxy Proxy
165 {
166 get
167 {
168 return _Proxy;
169 }
170 set
171 {
172 _Proxy = value;
173 }
174 }
175
176 /// <summary>
177 /// 是否需要删除临时文件
178 /// </summary>
179 private bool _isDeleteTempFile = false;
180 /// <summary>
181 /// 异步上传所临时生成的文件
182 /// </summary>
183 private string _UploadTempFile = "";
184 #endregion
185
186 #region 事件
187 public delegate void De_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e);
188 public delegate void De_DownloadDataCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
189 public delegate void De_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e);
190 public delegate void De_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e);
191
192 /// <summary>
193 /// 异步下载进度发生改变触发的事件
194 /// </summary>
195 public event De_DownloadProgressChanged DownloadProgressChanged;
196 /// <summary>
197 /// 异步下载文件完成之后触发的事件
198 /// </summary>
199 public event De_DownloadDataCompleted DownloadDataCompleted;
200 /// <summary>
201 /// 异步上传进度发生改变触发的事件
202 /// </summary>
203 public event De_UploadProgressChanged UploadProgressChanged;
204 /// <summary>
205 /// 异步上传文件完成之后触发的事件
206 /// </summary>
207 public event De_UploadFileCompleted UploadFileCompleted;
208 #endregion
209
210 #region 构造析构函数
211 /// <summary>
212 /// 构造函数
213 /// </summary>
214 /// <param name="FtpUri">FTP地址</param>
215 /// <param name="strUserName">登录用户名</param>
216 /// <param name="strPassword">登录密码</param>
217 public FTPHelper(Uri FtpUri, string strUserName, string strPassword)
218 {
219 this._Uri = new Uri(FtpUri.GetLeftPart(UriPartial.Authority));
220 _DirectoryPath = FtpUri.AbsolutePath;
221 if (!_DirectoryPath.EndsWith("/"))
222 {
223 _DirectoryPath += "/";
224 }
225 this._UserName = strUserName;
226 this._Password = strPassword;
227 this._Proxy = null;
228 }
229 /// <summary>
230 /// 构造函数
231 /// </summary>
232 /// <param name="FtpUri">FTP地址</param>
233 /// <param name="strUserName">登录用户名</param>
234 /// <param name="strPassword">登录密码</param>
235 /// <param name="objProxy">连接代理</param>
236 public FTPHelper(Uri FtpUri, string strUserName, string strPassword, WebProxy objProxy)
237 {
238 this._Uri = new Uri(FtpUri.GetLeftPart(UriPartial.Authority));
239 _DirectoryPath = FtpUri.AbsolutePath;
240 if (!_DirectoryPath.EndsWith("/"))
241 {
242 _DirectoryPath += "/";
243 }
244 this._UserName = strUserName;
245 this._Password = strPassword;
246 this._Proxy = objProxy;
247 }
248 /// <summary>
249 /// 构造函数
250 /// </summary>
251 public FTPHelper()
252 {
253 this._UserName = "anonymous"; //匿名用户
254 this._Password = "@anonymous";
255 this._Uri = null;
256 this._Proxy = null;
257 }
258
259 /// <summary>
260 /// 析构函数
261 /// </summary>
262 ~FTPHelper()
263 {
264 if (Response != null)
265 {
266 Response.Close();
267 Response = null;
268 }
269 if (Request != null)
270 {
271 Request.Abort();
272 Request = null;
273 }
274 }
275 #endregion
276
277 #region 建立连接
278 /// <summary>
279 /// 建立FTP链接,返回响应对象
280 /// </summary>
281 /// <param name="uri">FTP地址</param>
282 /// <param name="FtpMathod">操作命令</param>
283 private FtpWebResponse Open(Uri uri, string FtpMathod)
284 {
285 try
286 {
287 Request = (FtpWebRequest)WebRequest.Create(uri);
288 Request.Method = FtpMathod;
289 Request.UseBinary = true;
290 Request.Credentials = new NetworkCredential(this.UserName, this.Password);
291 if (this.Proxy != null)
292 {
293 Request.Proxy = this.Proxy;
294 }
295 return (FtpWebResponse)Request.GetResponse();
296 }
297 catch (Exception ep)
298 {
299 ErrorMsg = ep.ToString();
300 throw ep;
301 }
302 }
303 /// <summary>
304 /// 建立FTP链接,返回请求对象
305 /// </summary>
306 /// <param name="uri">FTP地址</param>
307 /// <param name="FtpMathod">操作命令</param>
308 private FtpWebRequest OpenRequest(Uri uri, string FtpMathod)
309 {
310 try
311 {
312 Request = (FtpWebRequest)WebRequest.Create(uri);
313 Request.Method = FtpMathod;
314 Request.UseBinary = true;
315 Request.Credentials = new NetworkCredential(this.UserName, this.Password);
316 if (this.Proxy != null)
317 {
318 Request.Proxy = this.Proxy;
319 }
320 return Request;
321 }
322 catch (Exception ep)
323 {
324 ErrorMsg = ep.ToString();
325 throw ep;
326 }
327 }
328 #endregion
329
330 #region 下载文件
331 /// <summary>
332 /// 从FTP服务器下载文件,使用与远程文件同名的文件名来保存文件
333 /// </summary>
334 /// <param name="RemoteFileName">远程文件名</param>
335 /// <param name="LocalPath">本地路径</param>
336
337 public bool DownloadFile(string RemoteFileName, string LocalPath)
338 {
339 return DownloadFile(RemoteFileName, LocalPath, RemoteFileName);
340 }
341 /// <summary>
342 /// 从FTP服务器下载文件,指定本地路径和本地文件名
343 /// </summary>
344 /// <param name="RemoteFileName">远程文件名</param>
345 /// <param name="LocalPath">本地路径</param>
346 /// <param name="LocalFilePath">保存文件的本地路径,后面带有"\"</param>
347 /// <param name="LocalFileName">保存本地的文件名</param>
348 public bool DownloadFile(string RemoteFileName, string LocalPath, string LocalFileName)
349 {
350 byte[] bt = null;
351 try
352 {
353 if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(LocalFileName) || !IsValidPathChars(LocalPath))
354 {
355 throw new Exception("非法文件名或目录名!");
356 }
357 if (!Directory.Exists(LocalPath))
358 {
359 throw new Exception("本地文件路径不存在!");
360 }
361
362 string LocalFullPath = Path.Combine(LocalPath, LocalFileName);
363 if (File.Exists(LocalFullPath))
364 {
365 throw new Exception("当前路径下已经存在同名文件!");
366 }
367 bt = DownloadFile(RemoteFileName);
368 if (bt != null)
369 {
370 FileStream stream = new FileStream(LocalFullPath, FileMode.Create);
371 stream.Write(bt, 0, bt.Length);
372 stream.Flush();
373 stream.Close();
374 return true;
375 }
376 else
377 {
378 return false;
379 }
380 }
381 catch (Exception ep)
382 {
383 ErrorMsg = ep.ToString();
384 throw ep;
385 }
386 }
387
388 /// <summary>
389 /// 从FTP服务器下载文件,返回文件二进制数据
390 /// </summary>
391 /// <param name="RemoteFileName">远程文件名</param>
392 public byte[] DownloadFile(string RemoteFileName)
393 {
394 try
395 {
396 if (!IsValidFileChars(RemoteFileName))
397 {
398 throw new Exception("非法文件名或目录名!");
399 }
400 Response = Open(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.DownloadFile);
401 Stream Reader = Response.GetResponseStream();
402
403 MemoryStream mem = new MemoryStream(1024 * 500);
404 byte[] buffer = new byte[1024];
405 int bytesRead = 0;
406 int TotalByteRead = 0;
407 while (true)
408 {
409 bytesRead = Reader.Read(buffer, 0, buffer.Length);
410 TotalByteRead += bytesRead;
411 if (bytesRead == 0)
412 break;
413 mem.Write(buffer, 0, bytesRead);
414 }
415 if (mem.Length > 0)
416 {
417 return mem.ToArray();
418 }
419 else
420 {
421 return null;
422 }
423 }
424 catch (Exception ep)
425 {
426 ErrorMsg = ep.ToString();
427 throw ep;
428 }
429 }
430 #endregion
431
432 #region 异步下载文件
433 /// <summary>
434 /// 从FTP服务器异步下载文件,指定本地路径和本地文件名
435 /// </summary>
436 /// <param name="RemoteFileName">远程文件名</param>
437 /// <param name="LocalPath">保存文件的本地路径,后面带有"\"</param>
438 /// <param name="LocalFileName">保存本地的文件名</param>
439 public void DownloadFileAsync(string RemoteFileName, string LocalPath, string LocalFileName)
440 {
441 //byte[] bt = null;
442 try
443 {
444 if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(LocalFileName) || !IsValidPathChars(LocalPath))
445 {
446 throw new Exception("非法文件名或目录名!");
447 }
448 if (!Directory.Exists(LocalPath))
449 {
450 throw new Exception("本地文件路径不存在!");
451 }
452
453 string LocalFullPath = Path.Combine(LocalPath, LocalFileName);
454 if (File.Exists(LocalFullPath))
455 {
456 throw new Exception("当前路径下已经存在同名文件!");
457 }
458 DownloadFileAsync(RemoteFileName, LocalFullPath);
459
460 }
461 catch (Exception ep)
462 {
463 ErrorMsg = ep.ToString();
464 throw ep;
465 }
466 }
467
468 /// <summary>
469 /// 从FTP服务器异步下载文件,指定本地完整路径文件名
470 /// </summary>
471 /// <param name="RemoteFileName">远程文件名</param>
472 /// <param name="LocalFullPath">本地完整路径文件名</param>
473 public void DownloadFileAsync(string RemoteFileName, string LocalFullPath)
474 {
475 try
476 {
477 if (!IsValidFileChars(RemoteFileName))
478 {
479 throw new Exception("非法文件名或目录名!");
480 }
481 if (File.Exists(LocalFullPath))
482 {
483 throw new Exception("当前路径下已经存在同名文件!");
484 }
485 MyWebClient client = new MyWebClient();
486
487 client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
488 client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(client_DownloadFileCompleted);
489 client.Credentials = new NetworkCredential(this.UserName, this.Password);
490 if (this.Proxy != null)
491 {
492 client.Proxy = this.Proxy;
493 }
494 client.DownloadFileAsync(new Uri(this.Uri.ToString() + RemoteFileName), LocalFullPath);
495 }
496 catch (Exception ep)
497 {
498 ErrorMsg = ep.ToString();
499 throw ep;
500 }
501 }
502
503 /// <summary>
504 /// 异步下载文件完成之后触发的事件
505 /// </summary>
506 /// <param name="sender">下载对象</param>
507 /// <param name="e">数据信息对象</param>
508 void client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
509 {
510 if (DownloadDataCompleted != null)
511 {
512 DownloadDataCompleted(sender, e);
513 }
514 }
515
516 /// <summary>
517 /// 异步下载进度发生改变触发的事件
518 /// </summary>
519 /// <param name="sender">下载对象</param>
520 /// <param name="e">进度信息对象</param>
521 void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
522 {
523 if (DownloadProgressChanged != null)
524 {
525 DownloadProgressChanged(sender, e);
526 }
527 }
528 #endregion
529
530 #region 上传文件
531 /// <summary>
532 /// 上传文件到FTP服务器
533 /// </summary>
534 /// <param name="LocalFullPath">本地带有完整路径的文件名</param>
535 public bool UploadFile(string LocalFullPath)
536 {
537 return UploadFile(LocalFullPath, Path.GetFileName(LocalFullPath), false);
538 }
539 /// <summary>
540 /// 上传文件到FTP服务器
541 /// </summary>
542 /// <param name="LocalFullPath">本地带有完整路径的文件</param>
543 /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>
544 public bool UploadFile(string LocalFullPath, bool OverWriteRemoteFile)
545 {
546 return UploadFile(LocalFullPath, Path.GetFileName(LocalFullPath), OverWriteRemoteFile);
547 }
548 /// <summary>
549 /// 上传文件到FTP服务器
550 /// </summary>
551 /// <param name="LocalFullPath">本地带有完整路径的文件</param>
552 /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
553 public bool UploadFile(string LocalFullPath, string RemoteFileName)
554 {
555 return UploadFile(LocalFullPath, RemoteFileName, false);
556 }
557 /// <summary>
558 /// 上传文件到FTP服务器
559 /// </summary>
560 /// <param name="LocalFullPath">本地带有完整路径的文件名</param>
561 /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
562 /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>
563 public bool UploadFile(string LocalFullPath, string RemoteFileName, bool OverWriteRemoteFile)
564 {
565 try
566 {
567 if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(Path.GetFileName(LocalFullPath)) || !IsValidPathChars(Path.GetDirectoryName(LocalFullPath)))
568 {
569 throw new Exception("非法文件名或目录名!");
570 }
571 if (File.Exists(LocalFullPath))
572 {
573 FileStream Stream = new FileStream(LocalFullPath, FileMode.Open, FileAccess.Read);
574 byte[] bt = new byte[Stream.Length];
575 Stream.Read(bt, 0, (Int32)Stream.Length); //注意,因为Int32的最大限制,最大上传文件只能是大约2G多一点
576 Stream.Close();
577 return UploadFile(bt, RemoteFileName, OverWriteRemoteFile);
578 }
579 else
580 {
581 throw new Exception("本地文件不存在!");
582 }
583 }
584 catch (Exception ep)
585 {
586 ErrorMsg = ep.ToString();
587 throw ep;
588 }
589 }
590 /// <summary>
591 /// 上传文件到FTP服务器
592 /// </summary>
593 /// <param name="FileBytes">上传的二进制数据</param>
594 /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
595 public bool UploadFile(byte[] FileBytes, string RemoteFileName)
596 {
597 if (!IsValidFileChars(RemoteFileName))
598 {
599 throw new Exception("非法文件名或目录名!");
600 }
601 return UploadFile(FileBytes, RemoteFileName, false);
602 }
603 /// <summary>
604 /// 上传文件到FTP服务器
605 /// </summary>
606 /// <param name="FileBytes">文件二进制内容</param>
607 /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
608 /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>
609 public bool UploadFile(byte[] FileBytes, string RemoteFileName, bool OverWriteRemoteFile)
610 {
611 try
612 {
613 if (!IsValidFileChars(RemoteFileName))
614 {
615 throw new Exception("非法文件名!");
616 }
617 if (!OverWriteRemoteFile && FileExist(RemoteFileName))
618 {
619 throw new Exception("FTP服务上面已经存在同名文件!");
620 }
621 Response = Open(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.UploadFile);
622 Stream requestStream = Request.GetRequestStream();
623 MemoryStream mem = new MemoryStream(FileBytes);
624
625 byte[] buffer = new byte[1024];
626 int bytesRead = 0;
627 int TotalRead = 0;
628 while (true)
629 {
630 bytesRead = mem.Read(buffer, 0, buffer.Length);
631 if (bytesRead == 0)
632 break;
633 TotalRead += bytesRead;
634 requestStream.Write(buffer, 0, bytesRead);
635 }
636 requestStream.Close();
637 Response = (FtpWebResponse)Request.GetResponse();
638 mem.Close();
639 mem.Dispose();
640 FileBytes = null;
641 return true;
642 }
643 catch (Exception ep)
644 {
645 ErrorMsg = ep.ToString();
646 throw ep;
647 }
648 }
649 #endregion
650
651 #region 异步上传文件
652 /// <summary>
653 /// 异步上传文件到FTP服务器
654 /// </summary>
655 /// <param name="LocalFullPath">本地带有完整路径的文件名</param>
656 public void UploadFileAsync(string LocalFullPath)
657 {
658 UploadFileAsync(LocalFullPath, Path.GetFileName(LocalFullPath), false);
659 }
660 /// <summary>
661 /// 异步上传文件到FTP服务器
662 /// </summary>
663 /// <param name="LocalFullPath">本地带有完整路径的文件</param>
664 /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>
665 public void UploadFileAsync(string LocalFullPath, bool OverWriteRemoteFile)
666 {
667 UploadFileAsync(LocalFullPath, Path.GetFileName(LocalFullPath), OverWriteRemoteFile);
668 }
669 /// <summary>
670 /// 异步上传文件到FTP服务器
671 /// </summary>
672 /// <param name="LocalFullPath">本地带有完整路径的文件</param>
673 /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
674 public void UploadFileAsync(string LocalFullPath, string RemoteFileName)
675 {
676 UploadFileAsync(LocalFullPath, RemoteFileName, false);
677 }
678 /// <summary>
679 /// 异步上传文件到FTP服务器
680 /// </summary>
681 /// <param name="LocalFullPath">本地带有完整路径的文件名</param>
682 /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
683 /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>
684 public void UploadFileAsync(string LocalFullPath, string RemoteFileName, bool OverWriteRemoteFile)
685 {
686 try
687 {
688 if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(Path.GetFileName(LocalFullPath)) || !IsValidPathChars(Path.GetDirectoryName(LocalFullPath)))
689 {
690 throw new Exception("非法文件名或目录名!");
691 }
692 if (!OverWriteRemoteFile && FileExist(RemoteFileName))
693 {
694 throw new Exception("FTP服务上面已经存在同名文件!");
695 }
696 if (File.Exists(LocalFullPath))
697 {
698 MyWebClient client = new MyWebClient();
699
700 client.UploadProgressChanged += new UploadProgressChangedEventHandler(client_UploadProgressChanged);
701 client.UploadFileCompleted += new UploadFileCompletedEventHandler(client_UploadFileCompleted);
702 client.Credentials = new NetworkCredential(this.UserName, this.Password);
703 if (this.Proxy != null)
704 {
705 client.Proxy = this.Proxy;
706 }
707 client.UploadFileAsync(new Uri(this.Uri.ToString() + RemoteFileName), LocalFullPath);
708
709 }
710 else
711 {
712 throw new Exception("本地文件不存在!");
713 }
714 }
715 catch (Exception ep)
716 {
717 ErrorMsg = ep.ToString();
718 throw ep;
719 }
720 }
721 /// <summary>
722 /// 异步上传文件到FTP服务器
723 /// </summary>
724 /// <param name="FileBytes">上传的二进制数据</param>
725 /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
726 public void UploadFileAsync(byte[] FileBytes, string RemoteFileName)
727 {
728 if (!IsValidFileChars(RemoteFileName))
729 {
730 throw new Exception("非法文件名或目录名!");
731 }
732 UploadFileAsync(FileBytes, RemoteFileName, false);
733 }
734 /// <summary>
735 /// 异步上传文件到FTP服务器
736 /// </summary>
737 /// <param name="FileBytes">文件二进制内容</param>
738 /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
739 /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>
740 public void UploadFileAsync(byte[] FileBytes, string RemoteFileName, bool OverWriteRemoteFile)
741 {
742 try
743 {
744
745 if (!IsValidFileChars(RemoteFileName))
746 {
747 throw new Exception("非法文件名!");
748 }
749 if (!OverWriteRemoteFile && FileExist(RemoteFileName))
750 {
751 throw new Exception("FTP服务上面已经存在同名文件!");
752 }
753 string TempPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Templates);
754 if (!TempPath.EndsWith("\\"))
755 {
756 TempPath += "\\";
757 }
758 string TempFile = TempPath + Path.GetRandomFileName();
759 TempFile = Path.ChangeExtension(TempFile, Path.GetExtension(RemoteFileName));
760 FileStream Stream = new FileStream(TempFile, FileMode.CreateNew, FileAccess.Write);
761 Stream.Write(FileBytes, 0, FileBytes.Length); //注意,因为Int32的最大限制,最大上传文件只能是大约2G多一点
762 Stream.Flush();
763 Stream.Close();
764 Stream.Dispose();
765 _isDeleteTempFile = true;
766 _UploadTempFile = TempFile;
767 FileBytes = null;
768 UploadFileAsync(TempFile, RemoteFileName, OverWriteRemoteFile);
769
770
771
772 }
773 catch (Exception ep)
774 {
775 ErrorMsg = ep.ToString();
776 throw ep;
777 }
778 }
779
780 /// <summary>
781 /// 异步上传文件完成之后触发的事件
782 /// </summary>
783 /// <param name="sender">下载对象</param>
784 /// <param name="e">数据信息对象</param>
785 void client_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
786 {
787 if (_isDeleteTempFile)
788 {
789 if (File.Exists(_UploadTempFile))
790 {
791 File.SetAttributes(_UploadTempFile, FileAttributes.Normal);
792 File.Delete(_UploadTempFile);
793 }
794 _isDeleteTempFile = false;
795 }
796 if (UploadFileCompleted != null)
797 {
798 UploadFileCompleted(sender, e);
799 }
800 }
801
802 /// <summary>
803 /// 异步上传进度发生改变触发的事件
804 /// </summary>
805 /// <param name="sender">下载对象</param>
806 /// <param name="e">进度信息对象</param>
807 void client_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
808 {
809 if (UploadProgressChanged != null)
810 {
811 UploadProgressChanged(sender, e);
812 }
813 }
814 #endregion
815
816 #region 列出目录文件信息
817 /// <summary>
818 /// 列出FTP服务器上面当前目录的所有文件和目录
819 /// </summary>
820 public FileStruct[] ListFilesAndDirectories()
821 {
822 Response = Open(this.Uri, WebRequestMethods.Ftp.ListDirectoryDetails);
823 StreamReader stream = new StreamReader(Response.GetResponseStream(), Encoding.Default);
824 string Datastring = stream.ReadToEnd();
825 FileStruct[] list = GetList(Datastring);
826 return list;
827 }
828 /// <summary>
829 /// 列出FTP服务器上面当前目录的所有文件
830 /// </summary>
831 public FileStruct[] ListFiles()
832 {
833 FileStruct[] listAll = ListFilesAndDirectories();
834 List<FileStruct> listFile = new List<FileStruct>();
835 foreach (FileStruct file in listAll)
836 {
837 if (!file.IsDirectory)
838 {
839 listFile.Add(file);
840 }
841 }
842 return listFile.ToArray();
843 }
844
845 /// <summary>
846 /// 列出FTP服务器上面当前目录的所有的目录
847 /// </summary>
848 public FileStruct[] ListDirectories()
849 {
850 FileStruct[] listAll = ListFilesAndDirectories();
851 List<FileStruct> listDirectory = new List<FileStruct>();
852 foreach (FileStruct file in listAll)
853 {
854 if (file.IsDirectory)
855 {
856 listDirectory.Add(file);
857 }
858 }
859 return listDirectory.ToArray();
860 }
861 /// <summary>
862 /// 获得文件和目录列表
863 /// </summary>
864 /// <param name="datastring">FTP返回的列表字符信息</param>
865 private FileStruct[] GetList(string datastring)
866 {
867 List<FileStruct> myListArray = new List<FileStruct>();
868 string[] dataRecords = datastring.Split('\n');
869 FileListStyle _directoryListStyle = GuessFileListStyle(dataRecords);
870 foreach (string s in dataRecords)
871 {
872 if (_directoryListStyle != FileListStyle.Unknown && s != "")
873 {
874 FileStruct f = new FileStruct();
875 f.Name = "..";
876 switch (_directoryListStyle)
877 {
878 case FileListStyle.UnixStyle:
879 f = ParseFileStructFromUnixStyleRecord(s);
880 break;
881 case FileListStyle.WindowsStyle:
882 f = ParseFileStructFromWindowsStyleRecord(s);
883 break;
884 }
885 if (!(f.Name == "." || f.Name == ".."))
886 {
887 myListArray.Add(f);
888 }
889 }
890 }
891 return myListArray.ToArray();
892 }
893
894 /// <summary>
895 /// 从Windows格式中返回文件信息
896 /// </summary>
897 /// <param name="Record">文件信息</param>
898 private FileStruct ParseFileStructFromWindowsStyleRecord(string Record)
899 {
900 FileStruct f = new FileStruct();
901 string processstr = Record.Trim();
902 string dateStr = processstr.Substring(0, 8);
903 processstr = (processstr.Substring(8, processstr.Length - 8)).Trim();
904 string timeStr = processstr.Substring(0, 7);
905 processstr = (processstr.Substring(7, processstr.Length - 7)).Trim();
906 DateTimeFormatInfo myDTFI = new CultureInfo("en-US", false).DateTimeFormat;
907 myDTFI.ShortTimePattern = "t";
908 f.CreateTime = DateTime.Parse(dateStr + " " + timeStr, myDTFI);
909 if (processstr.Substring(0, 5) == "<DIR>")
910 {
911 f.IsDirectory = true;
912 processstr = (processstr.Substring(5, processstr.Length - 5)).Trim();
913 }
914 else
915 {
916 string[] strs = processstr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // true);
917 processstr = strs[1];
918 f.IsDirectory = false;
919 }
920 f.Name = processstr;
921 return f;
922 }
923
924
925 /// <summary>
926 /// 判断文件列表的方式Window方式还是Unix方式
927 /// </summary>
928 /// <param name="recordList">文件信息列表</param>
929 private FileListStyle GuessFileListStyle(string[] recordList)
930 {
931 foreach (string s in recordList)
932 {
933 if (s.Length > 10
934 && Regex.IsMatch(s.Substring(0, 10), "(-|d)(-|r)(-|w)(-|x)(-|r)(-|w)(-|x)(-|r)(-|w)(-|x)"))
935 {
936 return FileListStyle.UnixStyle;
937 }
938 else if (s.Length > 8
939 && Regex.IsMatch(s.Substring(0, 8), "[0-9][0-9]-[0-9][0-9]-[0-9][0-9]"))
940 {
941 return FileListStyle.WindowsStyle;
942 }
943 }
944 return FileListStyle.Unknown;
945 }
946
947 /// <summary>
948 /// 从Unix格式中返回文件信息
949 /// </summary>
950 /// <param name="Record">文件信息</param>
951 private FileStruct ParseFileStructFromUnixStyleRecord(string Record)
952 {
953 FileStruct f = new FileStruct();
954 string processstr = Record.Trim();
955 f.Flags = processstr.Substring(0, 10);
956 f.IsDirectory = (f.Flags[0] == 'd');
957 processstr = (processstr.Substring(11)).Trim();
958 _cutSubstringFromStringWithTrim(ref processstr, ' ', 0); //跳过一部分
959 f.Owner = _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);
960 f.Group = _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);
961 _cutSubstringFromStringWithTrim(ref processstr, ' ', 0); //跳过一部分
962 string yearOrTime = processstr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[2];
963 if (yearOrTime.IndexOf(":") >= 0) //time
964 {
965 processstr = processstr.Replace(yearOrTime, DateTime.Now.Year.ToString());
966 }
967 f.CreateTime = DateTime.Parse(_cutSubstringFromStringWithTrim(ref processstr, ' ', 8));
968 f.Name = processstr; //最后就是名称
969 return f;
970 }
971
972 /// <summary>
973 /// 按照一定的规则进行字符串截取
974 /// </summary>
975 /// <param name="s">截取的字符串</param>
976 /// <param name="c">查找的字符</param>
977 /// <param name="startIndex">查找的位置</param>
978 private string _cutSubstringFromStringWithTrim(ref string s, char c, int startIndex)
979 {
980 int pos1 = s.IndexOf(c, startIndex);
981 string retString = s.Substring(0, pos1);
982 s = (s.Substring(pos1)).Trim();
983 return retString;
984 }
985 #endregion
986
987 #region 目录或文件存在的判断
988 /// <summary>
989 /// 判断当前目录下指定的子目录是否存在
990 /// </summary>
991 /// <param name="RemoteDirectoryName">指定的目录名</param>
992 public bool DirectoryExist(string RemoteDirectoryName)
993 {
994 try
995 {
996 if (!IsValidPathChars(RemoteDirectoryName))
997 {
998 throw new Exception("目录名非法!");
999 }
1000 FileStruct[] listDir = ListDirectories();
1001 foreach (FileStruct dir in listDir)
1002 {
1003 if (dir.Name == RemoteDirectoryName)
1004 {
1005 return true;
1006 }
1007 }
1008 return false;
1009 }
1010 catch (Exception ep)
1011 {
1012 ErrorMsg = ep.ToString();
1013 throw ep;
1014 }
1015 }
1016 /// <summary>
1017 /// 判断一个远程文件是否存在服务器当前目录下面
1018 /// </summary>
1019 /// <param name="RemoteFileName">远程文件名</param>
1020 public bool FileExist(string RemoteFileName)
1021 {
1022 try
1023 {
1024 if (!IsValidFileChars(RemoteFileName))
1025 {
1026 throw new Exception("文件名非法!");
1027 }
1028 FileStruct[] listFile = ListFiles();
1029 foreach (FileStruct file in listFile)
1030 {
1031 if (file.Name == RemoteFileName)
1032 {
1033 return true;
1034 }
1035 }
1036 return false;
1037 }
1038 catch (Exception ep)
1039 {
1040 ErrorMsg = ep.ToString();
1041 throw ep;
1042 }
1043 }
1044 #endregion
1045
1046 #region 删除文件
1047 /// <summary>
1048 /// 从FTP服务器上面删除一个文件
1049 /// </summary>
1050 /// <param name="RemoteFileName">远程文件名</param>
1051 public void DeleteFile(string RemoteFileName)
1052 {
1053 try
1054 {
1055 if (!IsValidFileChars(RemoteFileName))
1056 {
1057 throw new Exception("文件名非法!");
1058 }
1059 Response = Open(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.DeleteFile);
1060 }
1061 catch (Exception ep)
1062 {
1063 ErrorMsg = ep.ToString();
1064 throw ep;
1065 }
1066 }
1067 #endregion
1068
1069 #region 重命名文件
1070 /// <summary>
1071 /// 更改一个文件的名称或一个目录的名称
1072 /// </summary>
1073 /// <param name="RemoteFileName">原始文件或目录名称</param>
1074 /// <param name="NewFileName">新的文件或目录的名称</param>
1075 public bool ReName(string RemoteFileName, string NewFileName)
1076 {
1077 try
1078 {
1079 if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(NewFileName))
1080 {
1081 throw new Exception("文件名非法!");
1082 }
1083 if (RemoteFileName == NewFileName)
1084 {
1085 return true;
1086 }
1087 if (FileExist(RemoteFileName))
1088 {
1089 Request = OpenRequest(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.Rename);
1090 Request.RenameTo = NewFileName;
1091 Response = (FtpWebResponse)Request.GetResponse();
1092
1093 }
1094 else
1095 {
1096 throw new Exception("文件在服务器上不存在!");
1097 }
1098 return true;
1099 }
1100 catch (Exception ep)
1101 {
1102 ErrorMsg = ep.ToString();
1103 throw ep;
1104 }
1105 }
1106 #endregion
1107
1108 #region 拷贝、移动文件
1109 /// <summary>
1110 /// 把当前目录下面的一个文件拷贝到服务器上面另外的目录中,注意,拷贝文件之后,当前工作目录还是文件原来所在的目录
1111 /// </summary>
1112 /// <param name="RemoteFile">当前目录下的文件名</param>
1113 /// <param name="DirectoryName">新目录名称。
1114 /// 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ;
1115 /// 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如: ./NewDirectory/SubDirectory1/SubDirectory2
1116 /// </param>
1117 /// <returns></returns>
1118 public bool CopyFileToAnotherDirectory(string RemoteFile, string DirectoryName)
1119 {
1120 string CurrentWorkDir = this.DirectoryPath;
1121 try
1122 {
1123 byte[] bt = DownloadFile(RemoteFile);
1124 GotoDirectory(DirectoryName);
1125 bool Success = UploadFile(bt, RemoteFile, false);
1126 this.DirectoryPath = CurrentWorkDir;
1127 return Success;
1128 }
1129 catch (Exception ep)
1130 {
1131 this.DirectoryPath = CurrentWorkDir;
1132 ErrorMsg = ep.ToString();
1133 throw ep;
1134 }
1135 }
1136 /// <summary>
1137 /// 把当前目录下面的一个文件移动到服务器上面另外的目录中,注意,移动文件之后,当前工作目录还是文件原来所在的目录
1138 /// </summary>
1139 /// <param name="RemoteFile">当前目录下的文件名</param>
1140 /// <param name="DirectoryName">新目录名称。
1141 /// 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ;
1142 /// 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如: ./NewDirectory/SubDirectory1/SubDirectory2
1143 /// </param>
1144 /// <returns></returns>
1145 public bool MoveFileToAnotherDirectory(string RemoteFile, string DirectoryName)
1146 {
1147 string CurrentWorkDir = this.DirectoryPath;
1148 try
1149 {
1150 if (DirectoryName == "")
1151 return false;
1152 if (!DirectoryName.StartsWith("/"))
1153 DirectoryName = "/" + DirectoryName;
1154 if (!DirectoryName.EndsWith("/"))
1155 DirectoryName += "/";
1156 bool Success = ReName(RemoteFile, DirectoryName + RemoteFile);
1157 this.DirectoryPath = CurrentWorkDir;
1158 return Success;
1159 }
1160 catch (Exception ep)
1161 {
1162 this.DirectoryPath = CurrentWorkDir;
1163 ErrorMsg = ep.ToString();
1164 throw ep;
1165 }
1166 }
1167 #endregion
1168
1169 #region 建立、删除子目录
1170 /// <summary>
1171 /// 在FTP服务器上当前工作目录建立一个子目录
1172 /// </summary>
1173 /// <param name="DirectoryName">子目录名称</param>
1174 public bool MakeDirectory(string DirectoryName)
1175 {
1176 try
1177 {
1178 if (!IsValidPathChars(DirectoryName))
1179 {
1180 throw new Exception("目录名非法!");
1181 }
1182 if (DirectoryExist(DirectoryName))
1183 {
1184 throw new Exception("服务器上面已经存在同名的文件名或目录名!");
1185 }
1186 Response = Open(new Uri(this.Uri.ToString() + DirectoryName), WebRequestMethods.Ftp.MakeDirectory);
1187 return true;
1188 }
1189 catch (Exception ep)
1190 {
1191 ErrorMsg = ep.ToString();
1192 throw ep;
1193 }
1194 }
1195 /// <summary>
1196 /// 从当前工作目录中删除一个子目录
1197 /// </summary>
1198 /// <param name="DirectoryName">子目录名称</param>
1199 public bool RemoveDirectory(string DirectoryName)
1200 {
1201 try
1202 {
1203 if (!IsValidPathChars(DirectoryName))
1204 {
1205 throw new Exception("目录名非法!");
1206 }
1207 if (!DirectoryExist(DirectoryName))
1208 {
1209 throw new Exception("服务器上面不存在指定的文件名或目录名!");
1210 }
1211 Response = Open(new Uri(this.Uri.ToString() + DirectoryName), WebRequestMethods.Ftp.RemoveDirectory);
1212 return true;
1213 }
1214 catch (Exception ep)
1215 {
1216 ErrorMsg = ep.ToString();
1217 throw ep;
1218 }
1219 }
1220 #endregion
1221
1222 #region 文件、目录名称有效性判断
1223 /// <summary>
1224 /// 判断目录名中字符是否合法
1225 /// </summary>
1226 /// <param name="DirectoryName">目录名称</param>
1227 public bool IsValidPathChars(string DirectoryName)
1228 {
1229 char[] invalidPathChars = Path.GetInvalidPathChars();
1230 char[] DirChar = DirectoryName.ToCharArray();
1231 foreach (char C in DirChar)
1232 {
1233 if (Array.BinarySearch(invalidPathChars, C) >= 0)
1234 {
1235 return false;
1236 }
1237 }
1238 return true;
1239 }
1240 /// <summary>
1241 /// 判断文件名中字符是否合法
1242 /// </summary>
1243 /// <param name="FileName">文件名称</param>
1244 public bool IsValidFileChars(string FileName)
1245 {
1246 char[] invalidFileChars = Path.GetInvalidFileNameChars();
1247 char[] NameChar = FileName.ToCharArray();
1248 foreach (char C in NameChar)
1249 {
1250 if (Array.BinarySearch(invalidFileChars, C) >= 0)
1251 {
1252 return false;
1253 }
1254 }
1255 return true;
1256 }
1257 #endregion
1258
1259 #region 目录切换操作
1260 /// <summary>
1261 /// 进入一个目录
1262 /// </summary>
1263 /// <param name="DirectoryName">
1264 /// 新目录的名字。
1265 /// 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ;
1266 /// 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如: ./NewDirectory/SubDirectory1/SubDirectory2
1267 /// </param>
1268 public bool GotoDirectory(string DirectoryName)
1269 {
1270 string CurrentWorkPath = this.DirectoryPath;
1271 try
1272 {
1273 DirectoryName = DirectoryName.Replace("\\", "/");
1274 string[] DirectoryNames = DirectoryName.Split(new char[] { '/' });
1275 if (DirectoryNames[0] == ".")
1276 {
1277 this.DirectoryPath = "/";
1278 if (DirectoryNames.Length == 1)
1279 {
1280 return true;
1281 }
1282 Array.Clear(DirectoryNames, 0, 1);
1283 }
1284 bool Success = false;
1285 foreach (string dir in DirectoryNames)
1286 {
1287 if (dir != null)
1288 {
1289 Success = EnterOneSubDirectory(dir);
1290 if (!Success)
1291 {
1292 this.DirectoryPath = CurrentWorkPath;
1293 return false;
1294 }
1295 }
1296 }
1297 return Success;
1298
1299 }
1300 catch (Exception ep)
1301 {
1302 this.DirectoryPath = CurrentWorkPath;
1303 ErrorMsg = ep.ToString();
1304 throw ep;
1305 }
1306 }
1307 /// <summary>
1308 /// 从当前工作目录进入一个子目录
1309 /// </summary>
1310 /// <param name="DirectoryName">子目录名称</param>
1311 private bool EnterOneSubDirectory(string DirectoryName)
1312 {
1313 try
1314 {
1315 if (DirectoryName.IndexOf("/") >= 0 || !IsValidPathChars(DirectoryName))
1316 {
1317 throw new Exception("目录名非法!");
1318 }
1319 if (DirectoryName.Length > 0 && DirectoryExist(DirectoryName))
1320 {
1321 if (!DirectoryName.EndsWith("/"))
1322 {
1323 DirectoryName += "/";
1324 }
1325 _DirectoryPath += DirectoryName;
1326 return true;
1327 }
1328 else
1329 {
1330 return false;
1331 }
1332 }
1333 catch (Exception ep)
1334 {
1335 ErrorMsg = ep.ToString();
1336 throw ep;
1337 }
1338 }
1339 /// <summary>
1340 /// 从当前工作目录往上一级目录
1341 /// </summary>
1342 public bool ComeoutDirectory()
1343 {
1344 if (_DirectoryPath == "/")
1345 {
1346 ErrorMsg = "当前目录已经是根目录!";
1347 throw new Exception("当前目录已经是根目录!");
1348 }
1349 char[] sp = new char[1] { '/' };
1350
1351 string[] strDir = _DirectoryPath.Split(sp, StringSplitOptions.RemoveEmptyEntries);
1352 if (strDir.Length == 1)
1353 {
1354 _DirectoryPath = "/";
1355 }
1356 else
1357 {
1358 _DirectoryPath = String.Join("/", strDir, 0, strDir.Length - 1);
1359 }
1360 return true;
1361
1362 }
1363 #endregion
1364
1365 #region 重载WebClient,支持FTP进度
1366 internal class MyWebClient : WebClient
1367 {
1368 protected override WebRequest GetWebRequest(Uri address)
1369 {
1370 FtpWebRequest req = (FtpWebRequest)base.GetWebRequest(address);
1371 req.UsePassive = false;
1372 return req;
1373 }
1374 }
1375 #endregion
1376 }
1377
1378 #region 文件信息结构
1379 public struct FileStruct
1380 {
1381 public string Flags;
1382 public string Owner;
1383 public string Group;
1384 public bool IsDirectory;
1385 public DateTime CreateTime;
1386 public string Name;
1387 }
1388 public enum FileListStyle
1389 {
1390 UnixStyle,
1391 WindowsStyle,
1392 Unknown
1393 }
1394 #endregion
1395 }
1396
收获园豆:50
.NET敏捷开发框架 | 小虾三级 |园豆:946 | 2011-01-05 22:21
兄弟你的 代码很给力,单个上传是可以了,但是我批量的时候,就不行,我放循环里,循环上传结果报错了
comeonfyz | 园豆:14 (初学一级) | 2011-01-07 09:40
其他回答(5)
0

最简单的方法用FTP上传就行了,FTP操作的代码相信网上可以找到很多

或者如果由于某些原因不能用FTP也可以考虑在远程服务器上写个文件管理的服务,这个相对麻烦一点了,还得再写个服务程序

收获园豆:20
七月霄雨 | 园豆:1282 (小虾三级) | 2011-01-05 21:44
0

ftp的话你要开ftp权限,还要有ftp服务。。。

收获园豆:5
顾晓北 | 园豆:10819 (专家六级) | 2011-01-06 10:59
0

ftp是很容易 不用开发服务器程序,只要设置就可以了

不过.net下面的ftp组件bug比较多, 而且服务器允许不允许设置也是一个问题,

另外服务器没法及时的知道客户端已经上传了

 

建议小文件直接用Http Post的方式上传, 服务器弄个页面就好了 开发简单

或者用Socket上行 效率高 定制性强 ,开发稍微有点麻烦,而且要自己照顾服务器程序

收获园豆:20
听说读写 | 园豆:777 (小虾三级) | 2011-01-06 14:10
0

利用WebService进行上传,在远程WEB服务建立上传图片的WebService,Winform提交上传就可以了。

收获园豆:5
Astar | 园豆:40805 (高人七级) | 2011-01-07 16:12
0

使用webclient

guoxuefeng | 园豆:240 (菜鸟二级) | 2011-01-08 10:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册