asp.net中怎么利用Web Service遠程上傳圖片,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

頁面調(diào)用代碼: 前提添加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;
//將輸入流讀入二維數(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(".") + "//images" + fileName,FileMode.Create);
//將內(nèi)存流的東西寫入FileStream流中
memory.WriteTo(stream);
stream.Close();
memory = null;
stream = null;
return "文件上傳成功!";
}看完上述內(nèi)容,你們掌握asp.net中怎么利用Web Service遠程上傳圖片的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
標題名稱:asp.net中怎么利用WebService遠程上傳圖片-創(chuàng)新互聯(lián)
文章URL:http://chinadenli.net/article12/hohgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、響應(yīng)式網(wǎng)站、全網(wǎng)營銷推廣、外貿(mào)網(wǎng)站建設(shè)、面包屑導(dǎo)航、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容