This article describes the method of uploading files in jQuery with C#. Share it for your reference. The specific implementation method is as follows:
<html xmlns="http:///1999/xhtml"> <head runat="server"> <script src="jquery-1.7."></script> <script src=""></script> <script type="text/javascript"> function upload() { $("#form1").ajaxSubmit({ success: function (str) { alert(str); }, error: function (error) { alert(error); }, url: '', /*Set the page to which post is submitted*/ type: "post", /*Set the form to submit in post method*/ dataType: "text" /*Set the return value type to text*/ }); } </script> </head> <body> <form runat="server" enctype="multipart/form-data"> <input type="file" name="file" /> <asp:Button ID="Button1" runat="server" Text="Upload" OnClientClick="upload();return false;" /> </form> </body>
The code is as follows:
<%@ WebHandler Language="C#" Class="handler1" %> using System; using ; public class handler1 : IHttpHandler { public void ProcessRequest (HttpContext context) { = "text/plain"; HttpPostedFile file = [0]; String fileName = (); (("~/") + fileName); ("OK"); } public bool IsReusable { get { return false; } } }
I hope this article will be helpful to everyone's C# programming.