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.

2
  • 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. Commented Jun 10, 2011 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. Commented Jun 15, 2011 at 19:55

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.