Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sample
{
    public partial class Fileupload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            cl1 cl = new cl1();
            
            if (FileUpload1.HasFile)
                
               cl.check_save();     
            else
            {
                Label1.Text = "You have not specified a file";
            }
                
        }
        
            
        }

}

_______________________________________________________________________

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sample;

namespace Sample
{
    public class cl1 : Fileupload
    {
        public void check_save()
        {
            int conlen = FileUpload1.PostedFile.ContentLength;
            if (conlen != null && conlen != 0)
            {
                if (FileUpload1.PostedFile.ContentLength > 400000)
                {
                    Label1.Text = "Please select a low size file";
                }
                else
                {
                    try
                    {

                        FileUpload1.SaveAs("...................." + FileUpload1.FileName);
                        Label1.Text = "Filename:" + FileUpload1.PostedFile.FileName + "<br>" + "Content type:" + FileUpload1.PostedFile.ContentType;
                    }
                    catch (Exception ex)
                    {
                        Label1.Text = "Error" + ex.Message.ToString();
                    }

                }
            }
        }

    }
}
Posted
Updated 21-Sep-12 1:16am
v5
Comments
OriginalGriff 21-Sep-12 3:38am    
Where?
bbirajdar 21-Sep-12 3:40am    
where????
I.explore.code 21-Sep-12 3:50am    
ermmm...where?
07405 21-Sep-12 3:58am    
keep break point i ur code and check it out where u r getting that error and note it here.
Rickin Kane 21-Sep-12 4:05am    
lol u need answer , then tell me me what is cl1 cl = new cl1();
is it class file and do u have the code check_save(); written in your class file
Please tell me faster , i really want to enjoy my weekend

Why don't you try debugging / stepping through your source code?
That should help you track the error.
 
Share this answer
 
Comments
VavaKoshy 21-Sep-12 7:56am    
I debugged and when i click on the button i am gettin d error...
First, it appears that you shouldn't be declaring the class cl1. The check_save() method should be declared as part of the Fileupload class. When you create a new instance of cl1, it has no connection to the controls of the Fileupload class instance that created it. So, I'm guessing that the null reference comes from the referencing of Fileupload1 in check_save().

Next, in check_save() there's no reason to test if conlen != null. A variable of type int cannot be null. Also, after that test and the != 0 test, you no longer use conlen but instead reference FileUpload1.PostedFile.ContentLength. Just use conlen, it has the correct value.

And in the catch, ex.Message already is a string, ToString() is unnecessary.
 
Share this answer
 
Comments
VavaKoshy 22-Sep-12 2:17am    
Yes matt its working in dat way. But i just wanted to do it in creating a separate class and calling the method in the fileupload class.. Is dere any other way to do in the way i mentioned.. Please reply...

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