开发者

Jquery Ajax FileUploader & asp.net

I am trying to create a File Uploader with progress bar with Asp.net + Jquery.

important thing is I do not have a MVC webpage.

I have followed the instructions here: http://blog.stevensanderson.com/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/

However It just skips over the whole handler I need to create..

so far I have:

<script src="../../Scripts/swfupload.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-asyncUpload-0.1.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $("#yourID").makeAsyncUploader({
            upload_url: "/Controls/UploadHandler.ashx", // Important! This isn't a directory, it's a HANDLER such as an ASP.NET MVC action method, or a PHP file, or a Classic ASP file, or an ASP.NET .ASHX handler. The handler should save the file to disk (or database).
            flash_url: '../../Scripts/swfupload.swf',
            button_image_url: '../../Scripts/blankButton.png'
        });
    });
</script>

an开发者_开发问答d it all works as it should. However it obviously doesn't upload because I don't have a handler.. But I have no idea where to start with a ASHX handler..

I have tried unsuccessfully searching the net. Can someone point me in the right direction how to create this handler?


I sorted it

<%@ WebHandler Language="C#" Class="UploadHandler" %>

using System;
using System.Web;
using System.IO;

public class UploadHandler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {

        string strFileName = Path.GetFileName(context.Request.Files[0].FileName);
        string strExtension = Path.GetExtension(context.Request.Files[0].FileName).ToLower();
        string strLocation = context.Server.MapPath("~/SaveFile") + "/" + strFileName;
        context.Request.Files[0].SaveAs(strLocation);

        context.Response.ContentType = "text/plain";
        context.Response.Write("OK");
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜