网站大量收购独家精品文档,联系QQ:2885784924

本地上传下载文件或文件夹.docx

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
本地上传下载文件或文件夹

/// summary/// WebClient上传文件至服务器(不带进度条)/// /summary/// param name=fileNameFullPath要上传的文件(全路径格式)/param/// param name=strUrlDirPathWeb服务器文件夹路径/param/// returnsTrue/False是否上传成功/returns[WebMethod]public bool UpLoadFile(string fileNameFullPath, string strUrlDirPath){ //得到要上传的文件文件名 string fileName = fileNameFullPath.Substring(fileNameFullPath.LastIndexOf(\\) + 1);if (strUrlDirPath.EndsWith(/) == false) strUrlDirPath = strUrlDirPath + /;//保存在服务器上strUrlDirPath = strUrlDirPath + fileName;if (File.Exists(strUrlDirPath)) { MessageBox.Show(文件已存在,你想继续上传则要更改文件名!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } // 创建WebClient实例 WebClient myWebClient = new WebClient(); myWebClient.Credentials = CredentialCache.DefaultCredentials; // 将要上传的文件打开读进文件流 FileStream myFileStream = new FileStream(fileNameFullPath, FileMode.Open, FileAccess.Read); BinaryReader myBinaryReader = new BinaryReader(myFileStream); try { byte[] postArray = myBinaryReader.ReadBytes((int)myFileStream.Length); //打开远程Web地址,将文件流写入 Stream postStream = myWebClient.OpenWrite(strUrlDirPath, PUT); if (postStream.CanWrite) { postStream.Write(postArray, 0, postArray.Length); } else {MessageBox.Show(Web服务器文件目前不可写入,请检查Web服务器目录权限设置!, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Information);} postStream.Close();//关闭流 MessageBox.Show(上传成功,系统提示, MessageBoxButtons.OK, MessageBoxIcon.Information); return true; } catch (Exception exp) { MessageBox.Show(文件上传失败: + exp.Message, 系统提示, MessageBoxButtons.OK, MessageBoxIcon.Information); return false; }}bool b = false;/// summary/// 上传文件夹到服务器/// /summary/// param name=varFromDirectory传来的路径/param/// param name=varToDirectory服务器存放的路径/param[WebMethod]public void UpLoadFolder(string varFromDirectory, string varToDirectory){ if (b == false) { varToDirectory = varToDirectory + varFromDirectory.Substring(varFromDirectory.LastInd

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档