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

首頁 > 編程 > C# > 正文

jQuery結合C#實現上傳文件的方法

2020-01-24 01:55:39
字體:
來源:轉載
供稿:網友

本文實例講述了jQuery結合C#實現上傳文件的方法。分享給大家供大家參考。具體實現方法如下:

<html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <script src="jquery-1.7.1.min.js"></script> <script src="jquery.form.js"></script> <script type="text/javascript"> function upload() { $("#form1").ajaxSubmit({ success: function (str) { alert(str); }, error: function (error) { alert(error); }, url: 'handler1.ashx', /*設置post提交到的頁面*/ type: "post", /*設置表單以post方法提交*/ dataType: "text" /*設置返回值類型為文本*/ }); } </script></head><body> <form id="form1" runat="server" enctype="multipart/form-data"> <input type="file" id="file" name="file" /> <asp:Button ID="Button1" runat="server" Text="上傳"  OnClientClick="upload();return false;" /> </form></body>

handler1.ashx代碼如下:

<%@ WebHandler Language="C#" Class="handler1" %>using System;using System.Web;public class handler1 : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; HttpPostedFile file = context.Request.Files[0]; String fileName = System.IO.Path.GetFileName(file.FileName); file.SaveAs(context.Server.MapPath("~/") + fileName); context.Response.Write("OK"); } public bool IsReusable { get { return false; } }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玛纳斯县| 康定县| 汉中市| 邻水| 罗平县| 昌图县| 盐源县| 麻江县| 铜梁县| 娄烦县| 西青区| 太仓市| 新营市| 札达县| 江安县| 绍兴市| 武威市| 正阳县| 临夏市| 鱼台县| 富阳市| 封开县| 古浪县| 景泰县| 新竹县| 深州市| 永和县| 兴化市| 桦川县| 玉环县| 木兰县| 教育| 墨玉县| 长丰县| 天等县| 高碑店市| 柘荣县| 郯城县| 莱州市| 宝丰县| 施甸县|