华域联盟 .Net asp.net基于Web Service实现远程上传图片的方法

asp.net基于Web Service实现远程上传图片的方法

本文实例讲述了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程序设计有所帮助。

您可能感兴趣的文章:

  • .Net Core实现图片文件上传下载功能
  • ASP.NET MVC图片上传前预览简单实现
  • ASP.NET MVC实现图片上传、图片预览显示
  • asp.net图片文件的上传与删除方法
  • asp.net+jquery.form实现图片异步上传的方法(附jquery.form.js下载)
  • .Net 实现图片缩略图上传通用方法

本文由 华域联盟 原创撰写:华域联盟 » asp.net基于Web Service实现远程上传图片的方法

转载请保留出处和原文链接:https://www.cnhackhy.com/60840.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部