国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net基于Web Service實現遠程上傳圖片的方法

2024-07-10 12:47:31
字體:
來源:轉載
供稿:網友

本文實例講述了asp.net基于Web Service實現遠程上傳圖片的方法。,具體如下:

頁面調用代碼: 前提添加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;//將輸入流讀入二維數組中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(".") + "http://images" + fileName,FileMode.Create);  //將內存流的東西寫入FileStream流中  memory.WriteTo(stream);  stream.Close();  memory = null;  stream = null;  return "文件上傳成功!";}

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丹寨县| 涟水县| 闻喜县| 玉树县| 隆安县| 西和县| 伊金霍洛旗| 三门峡市| 昔阳县| 峨边| 南昌县| 永宁县| 绵竹市| 萝北县| 祁连县| 宜城市| 阿合奇县| 库尔勒市| 广灵县| 巴马| 肇庆市| 乌拉特中旗| 营山县| 如皋市| 客服| 淮阳县| 依安县| 旬邑县| 德安县| 晋城| 蓬溪县| 桦川县| 黄山市| 西安市| 新余市| 天津市| 明光市| 沙雅县| 盐城市| 慈利县| 疏勒县|