下载中心┊文章中心┊软件分类┊更新软件┊推荐下载┊热门软件┊更新文章┊热门文章
 
《拓文asp.net网站内容管理系统》官方演示站。
 设为首页    
 收藏本站
 作者:黄振安
 
网站首页 开源拓文 .NET编程 网站编程 网页设计 图形图像 数据库 软件工程留言本
    站内搜索:   
您现在的位置: 拓文网络 → 文章中心 → .NET编程 → ASP.NET → 用 WebClient.UploadData 方法 上载文件数据[正文]

热 门 文 章

相 关 文 章
没有相关文章!
用 WebClient.UploadData 方法 上载文件数据
 
[作者:宝玉    转贴自:http://blog.joycode.com/dotey    点击数:    字体:【大 中 小】    更新时间:2006-2-24 20:53:49]


   
   /**////
   /// 获取普通表单区域二进制数组
   ///

   /// 表单名
   /// 表单值
   ///
   ///
   /// -----------------------------7d52ee27210a3c\r\nContent-Disposition: form-data; name=\"表单名\"\r\n\r\n表单值\r\n
   ///

   public byte[] CreateFieldData(string fieldName, string fieldValue)
   ...{
   string textTemplate = Boundary + "\r\nContent-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}\r\n";
   string text = String.Format(textTemplate, fieldName, fieldValue);
   byte[] bytes = encoding.GetBytes(text);
   return bytes;
   }
  
  
   /**////
   /// 获取文件上传表单区域二进制数组
   ///

   /// 表单名
   /// 文件名
   /// 文件类型
   /// 文件长度
   /// 文件流
   /// 二进制数组
   public byte[] CreateFieldData(string fieldName, string filename,string contentType, byte[] fileBytes)
   ...{
   string end = "\r\n";
   string textTemplate = Boundary + "\r\nContent-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n";
  
   // 头数据
   string data = String.Format(textTemplate, fieldName, filename, contentType);
   byte[] bytes = encoding.GetBytes(data);
  
  
  
   // 尾数据
   byte[] endBytes = encoding.GetBytes(end);
  
   // 合成后的数组
   byte[] fieldData = new byte[bytes.Length + fileBytes.Length + endBytes.Length];
  
   bytes.CopyTo(fieldData, 0); // 头数据
   fileBytes.CopyTo(fieldData, bytes.Length); // 文件的二进制数据
   endBytes.CopyTo(fieldData, bytes.Length + fileBytes.Length); // \r\n
  
   return fieldData;
   }
  
  
   属性#region 属性
   public string Boundary
   ...{
   get
   ...{
   string[] bArray, ctArray;
   string contentType = ContentType;
   ctArray = contentType.Split(';');
   if (ctArray[0].Trim().ToLower() == "multipart/form-data")
   ...{
   bArray = ctArray[1].Split('=');
   return "--" + bArray[1];
   }
   return null;
   }
   }
  
   public string ContentType
   ...{
   get ...{
   if (HttpContext.Current == null)
   ...{
   return "multipart/form-data; boundary=---------------------
------7d5b915500cee";
   }
   return HttpContext.Current.Request.ContentType;
   }
   }
   #endregion
   }
  } 
   
   
页次:3/5  1篇/页  首页   上一页   下一页   尾页  合计 5 篇 Go:
 
上一篇:没有文章
下一篇:ASP.NET Cache
winner 打印本页 关闭窗口

     文 章 评 论
评论人 查看该文章的评论 发表时间
   笔 名* : 0 50分 60分 70分 80分 90分 100分
评论内容 *: (最多600字。当前字数:0)


没有相关评论,欢迎您参与!

- 关于本站 - 网站帮助 - 下载声明 - 友情连接 - 网站地图 -
Copyright © 2005-2006 rtht.Com. All Rights Reserved . [桂ICP备06004496号]程序设计: 拓文ASP.NET网站内容管理系统 V2.6 SQL版