Click here to Skip to main content
12,297,208 members (65,903 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.0 C# ASP.NET
hello friends,

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

<%@ 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 20-Nov-12 20:12pm
Edited 20-Nov-12 20:14pm
__TR__29K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

List<httppostedfile> files = (List<httppostedfile>)context.Session["Files"];
if (files == null)
{
    files = new List<httppostedfile>();
    context.Session["Files"] = files;
}
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100