当前位置: 首页 > news >正文

郑州市网站建设_网站建设公司_无障碍设计_seo优化

先做网站再付款,网搜网,wordpress主题loading动画,小型网站开发 论文原来使用asp.net上传控件上传 那个虽然简单但是页面不是很友好 然后就用了uploadify上传控件 这个控件虽然界面友好 但是大文件还是不能上传 而且在不同的浏览器会出现session丢失问题 所以我到了个ftp上传的方法 以下是具体代码 View Code?11 using System; 2 using System…      原来使用asp.net上传控件上传 那个虽然简单但是页面不是很友好 然后就用了uploadify上传控件  这个控件虽然界面友好 但是大文件还是不能上传 而且在不同的浏览器会出现session丢失问题 所以我到了个ftp上传的方法     以下是具体代码 View Code? 1     1 using System; 2 using System.Configuration; 3 using System.Data; 4 using System.Linq; 5 using System.Web; 6 using System.Web.Security; 7 using System.Web.UI; 8 using System.Web.UI.HtmlControls; 9 using System.Web.UI.WebControls; 10 using System.Web.UI.WebControls.WebParts; 11 using System.Xml.Linq; 12 using System.IO; 13 using System.Net; 14 using System.Text; 15 16 public partial class _Default : System.Web.UI.Page 17 { 18 //以下字段配置在web.config 19 private string ftpServerIP 127.0.0.1;//服务器ip 20 private string ftpUserID FTPTEST;//用户名FTPTEST 21 private string ftpPassword ftptest;//密码 22 protected void Page_Load(object sender, EventArgs e) 23 { 24 25 if (MyFile.Value ! ) 26 { 27 //string a MyFile.; 28 } 29 30 } 31 32 33 34 35 36 37 38 39 //ftp的上传功能 40 private void Upload(string filename) 41 { 42 FileInfo fileInf new FileInfo(filename); 43 44 string uri ftp:// ftpServerIP / fileInf.Name; 45 FtpWebRequest reqFTP; 46 47 // 根据uri创建FtpWebRequest对象 48 reqFTP (FtpWebRequest)FtpWebRequest.Create(new Uri(ftp:// ftpServerIP / fileInf.Name)); 49 50 // ftp用户名和密码 51 reqFTP.Credentials new NetworkCredential(ftpUserID, ftpPassword); 52 53 // 默认为true连接不会被关闭 54 // 在一个命令之后被执行 55 reqFTP.KeepAlive false; 56 57 // 指定执行什么命令 58 reqFTP.Method WebRequestMethods.Ftp.UploadFile; 59 60 // 指定数据传输类型 61 reqFTP.UseBinary true; 62 63 // 上传文件时通知服务器文件的大小 64 reqFTP.ContentLength fileInf.Length; 65 66 // 缓冲大小设置为2kb 67 int buffLength 2048; 68 69 byte[] buff new byte[buffLength]; 70 int contentLen; 71 72 // 打开一个文件流 (System.IO.FileStream) 去读上传的文件 73 FileStream fs fileInf.OpenRead(); 74 try 75 { 76 // 把上传的文件写入流 77 Stream strm reqFTP.GetRequestStream(); 78 79 // 每次读文件流的2kb 80 contentLen fs.Read(buff, 0, buffLength); 81 82 // 流内容没有结束 83 while (contentLen ! 0) 84 { 85 // 把内容从file stream 写入 upload stream 86 strm.Write(buff, 0, contentLen); 87 88 contentLen fs.Read(buff, 0, buffLength); 89 } 90 91 // 关闭两个流 92 strm.Close(); 93 fs.Close(); 94 this.Page.RegisterStartupScript(, scriptalert(成功)/script); 95 } 96 catch (Exception ex) 97 { 98 // MessageBox.Show(ex.Message, Upload Error); 99 Response.Write(Upload Error ex.Message);100 }101 }102 103 104 //从ftp服务器上下载文件的功能105 private void Download(string filePath, string fileName)106 {107 FtpWebRequest reqFTP;108 109 try110 {111 FileStream outputStream new FileStream(filePath \\ fileName, FileMode.Create);112 113 reqFTP (FtpWebRequest)FtpWebRequest.Create(new Uri(ftp:// ftpServerIP / fileName));114 115 reqFTP.Method WebRequestMethods.Ftp.DownloadFile;116 117 reqFTP.UseBinary true;118 119 reqFTP.Credentials new NetworkCredential(ftpUserID, ftpPassword);120 121 FtpWebResponse response (FtpWebResponse)reqFTP.GetResponse();122 123 Stream ftpStream response.GetResponseStream();124 125 long cl response.ContentLength;126 127 int bufferSize 2048;128 129 int readCount;130 131 byte[] buffer new byte[bufferSize];132 133 readCount ftpStream.Read(buffer, 0, bufferSize);134 135 while (readCount 0)136 {137 outputStream.Write(buffer, 0, readCount);138 139 readCount ftpStream.Read(buffer, 0, bufferSize);140 }141 142 ftpStream.Close();143 144 outputStream.Close();145 146 response.Close();147 }148 catch (Exception ex)149 {150 Response.Write(Download Error ex.Message);151 }152 }153 154 //从ftp服务器上获得文件列表155 public string[] GetFileList()156 {157 string[] downloadFiles;158 StringBuilder result new StringBuilder();159 FtpWebRequest reqFTP;160 // HttpWebRequest reqFTP;161 try162 {163 reqFTP (FtpWebRequest)FtpWebRequest.Create(new Uri(ftp:// ftpServerIP /));164 reqFTP.UseBinary true;165 reqFTP.Credentials new NetworkCredential(ftpUserID, ftpPassword);166 reqFTP.Method WebRequestMethods.Ftp.ListDirectory;167 WebResponse response reqFTP.GetResponse();168 StreamReader reader new StreamReader(response.GetResponseStream());169 string line reader.ReadLine();170 while (line ! null)171 {172 result.Append(line);173 result.Append(\n);174 line reader.ReadLine();175 }176 // to remove the trailing \n 177 result.Remove(result.ToString().LastIndexOf(\n), 1);178 reader.Close();179 response.Close();180 return result.ToString().Split(\n);181 }182 catch (Exception ex)183 {184 downloadFiles null;185 return downloadFiles;186 }187 }188 189 protected void Button1_Click(object sender, EventArgs e)190 {191 Upload(F:\\美国队长DVD中字.rmvb);192 }193 protected void Button2_Click(object sender, EventArgs e)194 {195 196 }197 } 转载于:https://www.cnblogs.com/29ing/archive/2013/01/06/2847606.html
http://www.ihoyoo.com/news/26969.html

相关文章:

  • 图书管理系统网站开发设计过程运营一个网站要多少钱
  • 可信网站免费认证做的好点的外贸网站
  • 织梦房产网站模板群晖部署wordpress
  • 网站开发使用语言腾讯企业邮箱的优惠活动
  • 网站优化需要工具WordPress推送服务
  • 网站开发过程阶段慈溪建设集团网站
  • 如何做网站信息sketch wordpress 主题
  • 企业网站建设的开放方式一般有网站信息化建设
  • 网站搜索出来有图片注册资金
  • 网站维护要求广西住房城乡建设厅官方网站
  • 遵义网站建设公司电话多少框架网页怎么制作
  • 网站没备案可以做商城吗网站建站教程
  • 怎么样自己做最简单的网站wordpress 中介
  • 网站用什么图片格式好wordpress分权限浏览
  • 百度云虚拟主机做网站社区网站建设公司
  • 网站建设与设计ppt模板网络推广营销团队
  • 机械网站案例分析网站一个人可以做吗
  • o2o网站建设多少钱佛山seo网站优化
  • 华为云速建站高端办公室设计装修公司
  • 网站导航怎么做外链国内做的好的游艇网站
  • 企业网站建设的意义网络营销专员是干嘛的
  • 网页设计代码模板网站北京网站设计合理刻
  • 天津网站制作哪家好薇wordpress自动还原
  • 电商网站建设毕业设计温州手机网站制作公司电话
  • 电商有哪些类目天津关键词优化网站
  • 网站qq 微信分享怎么做的自己动手制作网站
  • 织梦开发网站山东微道商网络技术有限公司
  • C 做的窗体怎么变成网站陕西网站建设陕icp备
  • 做做网站已更新购买域名网站好
  • 网站建设在哪里进行企业网站静态模板下载