Click here to Skip to main content
11,410,750 members (64,262 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 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 21:12pm
Edited 20-Nov-12 21: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 at 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 at 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
0 Sergey Alexandrovich Kryukov 239
1 Sascha Lefévre 85
2 Dave Kreskowiak 80
3 Maciej Los 68
4 RyanDev 50
0 Sergey Alexandrovich Kryukov 8,885
1 OriginalGriff 6,915
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2015
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