jQuery結(jié)合C#實(shí)現(xiàn)上傳文件的方法
更新時(shí)間:2015年04月25日 15:40:12 作者:work24
這篇文章主要介紹了jQuery結(jié)合C#實(shí)現(xiàn)上傳文件的方法,涉及C#文件上傳的相關(guān)技巧,需要的朋友可以參考下
本文實(shí)例講述了jQuery結(jié)合C#實(shí)現(xiàn)上傳文件的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
<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', /*設(shè)置post提交到的頁(yè)面*/
type: "post", /*設(shè)置表單以post方法提交*/
dataType: "text" /*設(shè)置返回值類型為文本*/
});
}
</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;
}
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- C#實(shí)現(xiàn)HTTP上傳文件的方法
- C# 通用文件上傳類
- asp.net(c#)開(kāi)發(fā)中的文件上傳組件uploadify的使用方法(帶進(jìn)度條)
- C# 文件上傳 默認(rèn)最大為4M的解決方法
- asp.net(C#)中上傳大文件的幾中常見(jiàn)應(yīng)用方法
- C#采用HttpWebRequest實(shí)現(xiàn)保持會(huì)話上傳文件到HTTP的方法
- ASP.NET(C#)實(shí)現(xiàn)一次性動(dòng)態(tài)上傳多張圖片的代碼(多個(gè)文件)
- C#實(shí)現(xiàn)Web文件上傳的兩種方法實(shí)例代碼
- C#判斷上傳文件是否是圖片以防止木馬上傳的方法
- C#實(shí)現(xiàn)文件上傳以及多文件上傳功能
相關(guān)文章
基于C#編寫經(jīng)理評(píng)分系統(tǒng)
最近接了這樣一個(gè)項(xiàng)目,要求使用c#編寫經(jīng)理評(píng)分系統(tǒng),需求,要顯示員工信息,實(shí)現(xiàn)項(xiàng)目經(jīng)理給員工評(píng)分功能,今天小編分步驟給大家介紹,需要的的朋友參考下2017-03-03
Unity實(shí)現(xiàn)物體弧線運(yùn)動(dòng)到規(guī)定的坐標(biāo)
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)物體以弧線的形式運(yùn)動(dòng)到規(guī)定的坐標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06

