Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am trying to upload an image to a website, but I am not successful. I want to read the path of the picture in handler method from somewhere... I used Session, but in the handler the Session is null, even when I write something to the Session in a Page_Load of a page where is a button, which starts the handler or when I write it to the button_click method it still null.
I want to know, how can I give the Path of the image to the handler and how the code will looks like.

I have something like this, but it's unuseable and when I write some path of an existing image to parameters of the Write Method it downloads the handler, but I don't want it. I want to upload an image, which I choose to the website, does anyone know how? Thanks for replies!

C#
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "image/jpeg";
        string savedFileName = "";

        foreach (string file in context.Request.Files)
        {
            HttpPostedFile hpf = context.Request.Files[file] as HttpPostedFile;
            if (hpf.ContentLength == 0)
                continue;
            savedFileName = context.Server.MapPath(context.Session["FileUpload"].ToString());
            hpf.SaveAs(savedFileName);
        }
        context.Response.Write(savedFileName);
    }
Posted
Updated 22-Dec-12 9:09am
v2

1 solution

Hi, first of all you must mark you handler with IRequiresSessionState interface.
This is only markable attribute, hence you don't need to inherit some additional methods in your handler.
Try to do that , and in fact you will reach access to Session data within your HttpHandler.
 
Share this answer
 
Comments
Pepin z Hane 23-Dec-12 14:14pm    
From which library IRequiresSessionState is? It didn't find any...
Oleksandr Kulchytskyi 23-Dec-12 14:32pm    
Is it so hard to open MSDN and search all about IRequiresSessionState ?)
Namespace: System.Web.SessionState, Assembly :System.Web.dll.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900