2

I want to use the Ajax-Upload script to upload multiple images. The kicker is I have to use Asp.net webforms, the way I've been doing ajax has been to have a simple page web method like so.

[WebMethod()]
public static string Method(string param)
{
    return "Hello World";
}

I am running into trouble figuring out how to upload an image without using the webforms FileUpload control so I can upload files asynchronously. I must be using the wrong search terms because I cannot find another example of someone doing this inside of webforms.

EDIT: To be more specific I am looking for help with the server side. The plugin I linked to handles all of the client side stuff. I am currently looking into writing a customer handler...

I'd prefer to avoid using update panel controls(like the AjaxToolkit) and just stick to the plugin if thats possible.

rick schott
  • 21,012
  • 5
  • 52
  • 81
peregrine
  • 205
  • 2
  • 9
  • I noticed this is your first question. If you solved this yourself, you should post your update as an answer and accept it. If one of the answers helped you solve it, you should accept that answer and/or upvote any additionally helpful answers. – Devin Burke Jun 10 '11 at 17:35
  • 1
    @Justin Satyr sorry about that, none of the answers really helped at all I will post my answer and accept it. Thanks for the help. – peregrine Jun 15 '11 at 19:55

2 Answers2

1

In asp.net- ajax you can Asyncupload which is part of the Ajax control toolkit. http://www.asp.net/ajax/ajaxcontroltoolkit/samples/AsyncFileUpload/AsyncFileUpload.aspx If you are looking at jquery plugins, take a look at uploadify http://www.uploadify.com.

Aravind
  • 4,125
  • 1
  • 28
  • 39
0

ANSWER:

What I did was wrote an Image Upload handler script that is pretty basic but it should get the job done. Here it is.

    public void ProcessRequest(HttpContext context)
    {
        string uploadDir = "C:\\Upload";
        try
        {
            Image i = Image.FromStream(context.Request.InputStream);
            string filename = context.Request.Params["qqfile"];

            if (i.RawFormat.Equals(ImageFormat.Png))
            {
                i.Save(uploadDir + "\\" + filename, ImageFormat.Png);
            }
            else if (i.RawFormat.Equals(ImageFormat.Jpeg))
            {
                i.Save(uploadDir + "\\" + filename, ImageFormat.Jpeg);
            }
            else if (i.RawFormat.Equals(ImageFormat.Gif))
            {
                i.Save(uploadDir + "\\" + filename, ImageFormat.Gif);
            }
            else if (i.RawFormat.Equals(ImageFormat.Bmp))
            {
                i.Save(uploadDir + "\\" + filename, ImageFormat.Bmp);
            }
        }
        catch (Exception e)
        {
            context.Response.Write("{'error':'"+e.Message+"'}");
        }

        context.Response.Write("{'success':true}");
    }

And this works with the Ajax-Upload script I linked to earlier. Thanks

peregrine
  • 205
  • 2
  • 9