当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net基于Web Service实现远程上传图片的方法

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

1.bb5522.ws,陈家桥租房,官场中文网

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网