Click here to Skip to main content
15,889,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi try to pass the data to a data layer take the data back from another methods. But fails. I use get set method in another c# class to get the value but it return null

C#
  public partial class _Default : Page
    {
        private string strFile = HttpContext.Current.Server.MapPath("~/Output/");
        private string strUpload = HttpContext.Current.Server.MapPath("~/Data/");
        private string strOutput = "" + DateTime.Now.ToString("ddMMyyy_hhmmss") + ".xls";
        private ReadExcel readExcel = new ReadExcel();
        private ExcelData excelData;
        private string sFileName;

        protected void Page_Load(object sender, EventArgs e)
        {
            excelData = new ExcelData();
            sFileName = string.Empty;
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if ((fileUploadDialog.PostedFile != null) && (fileUploadDialog.PostedFile.ContentLength > 0))
            {
                string fn = Path.GetFileName(fileUploadDialog.PostedFile.FileName);
                excelData.fileName = fn;
                sFileName = fn;
                string saveLocation = strUpload + "\\" + fn;
                try
                {
                    fileUploadDialog.PostedFile.SaveAs(saveLocation);
                   // Response.Write("");
                    lblStatus.Text = "Upload Status: The file has been uploaded. " + excelData.fileName ;

                }
                catch (Exception ex)
                {
                    Response.Write(ex);
                }
            }
            else
            {
                lblStatus.Text = "Please select a file to upload";
            }
        }

        protected void btnDisplay_Click(object sender, EventArgs e)
        {

            lblStatus.Text = "test" + sFileName  ;
//bothe sFileName and excelData.fileName will return null Why?
            //DataTable dt = readExcel.readCutomManualID(excelData.fileName);
        }
    }
}


C#
namespace TGSTax.Models
{
    public class ExcelData
    {
       // public string fileName { get; set; }
        string _fileName;
        public string fileName
        {
            get
            {
                return this._fileName;
            }
            set
            {
                this._fileName = value;
            }
        }

        //public ExcelData()
        //{
        // public string fileName { get; set; }
        //}
    }
}



Do anyone have any idea?
Posted

1 solution

This logic works only in windows and not web because web is disconnected so your object are lost once the request is processed. The solution is to store the object and then reuse. You can think of session or cache object depending upon your requirement.
 
Share this answer
 

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