欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net基于Web Service實現(xiàn)遠程上傳圖片的方法

 更新時間:2015年12月03日 09:50:57   作者:happy664618843  
這篇文章主要介紹了asp.net基于Web Service實現(xiàn)遠程上傳圖片的方法,涉及asp.net調(diào)用Web Service的文件流操作與文件傳輸實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了asp.net基于Web Service實現(xiàn)遠程上傳圖片的方法。分享給大家供大家參考,具體如下:

頁面調(diào)用代碼: 前提添加Web 引用

HttpFileCollection files = HttpContext.Current.Request.Files;
string filePath = files[0].FileName;
string fileName = filePath.Substring(filePath.LastIndexOf("http://") + 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;
//將輸入流讀入二維數(shù)組中
fs.Read(datas, 0, files[0].ContentLength);
fs.Close();
Response.Write(web.UploadFile(datas,fileName));

Web Service中代碼

[WebMethod(Description="上傳服務(wù)器圖片信息,返回是否成功")]
public string UploadFile(byte[] fs,string fileName)
{
  //創(chuàng)建內(nèi)存流 將數(shù)組寫入內(nèi)存流中
  MemoryStream memory = new MemoryStream(fs);
  //把內(nèi)存的東西寫入文件流中
  FileStream stream = new FileStream(HttpContext.Current.Server.MapPath(".") + "http://images" + fileName,FileMode.Create);
  //將內(nèi)存流的東西寫入FileStream流中
  memory.WriteTo(stream);
  stream.Close();
  memory = null;
  stream = null;
  return "文件上傳成功!";
}

希望本文所述對大家asp.net程序設(shè)計有所幫助。

相關(guān)文章

最新評論