Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,

Please See this code, and suggest me where m i wrong....

C#
<%@ WebHandler Language="C#" Class="UploadCS" %>
using System;
using System.Web;
using System.IO;
using System.Web.SessionState;
using System.Collections.Generic;
public class UploadCS : IHttpHandler, IRequiresSessionState {
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;
        try
        {
            List<httppostedfile> files = (List<httppostedfile>)context.Session["Files"];
            HttpPostedFile postedFile = context.Request.Files["Filedata"];
            files.Add(postedFile);
            
            string filename = postedFile.FileName;
            context.Response.Write(filename);
            context.Response.StatusCode = 200;
        }
        catch (Exception ex)
        {
            context.Response.Write("Error: " + ex.Message);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}

i use multi file uploader but i cant get list of posted file in files List
when i debug code i found one error when debuger reach this line "files.Add(postedFile);" Exception like
Object reference not set to an instance of an object.

Please help me to solve this issue
Posted
Updated 20-Nov-12 20:14pm
v2

1 solution

It seems like the Files entry of your Session isn't initialized. Try to initialize it if it is null. Something like:


C#
List<httppostedfile> files = (List<httppostedfile>)context.Session["Files"];
if (files == null)
{
    files = new List<httppostedfile>();
    context.Session["Files"] = files;
}
 
Share this answer
 
Comments
Shingala Anil 21-Nov-12 2:58am    
Hello frnd,
thanks for you replay,
sorry your solution does not work for me...
still i count zero in files list
Shingala Anil 21-Nov-12 3:07am    
I solve error but i cant get session value in code behind please help me for that

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