无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了asp.net基于Web Service实现远程上传图片的方法。分享给大家供大家参考,具体如下:
页面调用代码: 前提添加Web 引用
HttpFileCollection files = HttpContext.Current.Request.Files; string filePath = files[0].FileName; string fileName = filePath.Substring(filePath.LastIndexOf("//") + 1); byte[] datas = new byte[files[0].ContentLength]; System.IO.Stream fs; localhost.WebService web = new localhost.WebService(); fs = (System.IO.Stream)files[0].InputStream; //将输入流读入二维数组中 fs.Read(datas, 0, files[0].ContentLength); fs.Close(); Response.Write(web.UploadFile(datas,fileName));
Web Service中代码
[WebMethod(Description="上传服务器图片信息,返回是否成功")] public string UploadFile(byte[] fs,string fileName) { //创建内存流 将数组写入内存流中 MemoryStream memory = new MemoryStream(fs); //把内存的东西写入文件流中 FileStream stream = new FileStream(HttpContext.Current.Server.MapPath(".") + "//images" + fileName,FileMode.Create); //将内存流的东西写入FileStream流中 memory.WriteTo(stream); stream.Close(); memory = null; stream = null; return "文件上传成功!"; }
希望本文所述对大家asp.net程序设计有所帮助。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月27日
2024年09月27日
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 金佩姗.1997-喜新恋旧【现代派】【WAV+CUE】
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 陈晓东.1997-在乎你感受(EP)【宝丽金】【WAV+CUE】
- 纯音入心系列纯音乐《云水禅心 - 佛曲古筝礼赞1-2》1CD[MP3][190MB]
- 纯音入心系列纯音乐《精心传神-古筝》1CD[MP3][363.1MB]
- 纯音入心系列纯音乐《琴瑟古风之古筝精选曲》1CD[MP3][354.1MB]
- 陈晓东.1997-在乎你感受(EP)【宝丽金】【WAV+CUE】
- 黄凯芹.1990-给你留念(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 张学友.1999-有个人【宝丽金】【WAV+CUE】
- 纯音入心系列纯音乐《古筝佛曲》1CD[MP3][411.1MB]
- 纯音入心系列纯音乐《古筝世界名曲》1CD[MP3][38.9MB]
- 纯音入心系列纯音乐《古筝新奏-菩提妙音》1CD[MP3][112.3MB]
- 陈思安.1993-怀念福建金曲5CD【歌丽美】【WAV+CUE】
- 张学友.1999-有个人【宝丽金】【WAV+CUE】