Click here to Skip to main content
15,888,257 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

1)upload the excel file.
2)view the upload file.

In view upload file, when we click on link button the uploaded file should be display. how can this be done?
What is wrong with the following code?
C#
protected void LinkButton1_Click(object sender, EventArgs e)
{
    try
    {
        DataSet objSuccFailDataSet = (DataSet)Session["objSuccFailDataSet"];

        string sFileDir = Convert.ToString(Session["sFileDir"]);

        //string strOutputExcelFile = Convert.ToString(Session["sFileName"]);

        string strOutputExcelFile = Convert.ToString(Session["strOutputExcelFile"]);

        bool retflagTmp = ExportToExcelTemp(objSuccFailDataSet, sFileDir + strOutputExcelFile);
    
        if (retflagTmp)
        {        
            Response.ContentType = "application/ms-excel";
            
            Response.AddHeader("content-disposition", "attachment; filename=" + strOutputExcelFile);
            
            FileStream sourceFile = new FileStream(sFileDir + strOutputExcelFile, FileMode.Open);
            
            long FileSize;
            
            FileSize = sourceFile.Length;
            
            byte[] getContent = new byte[(int)FileSize];
            
            sourceFile.Read(getContent, 0, (int)sourceFile.Length);
            
            sourceFile.Close();
            
            Response.OutputStream.Write(getContent, 0, getContent.Length);
            
            // Response.BinaryWrite(getContent);
            
            Response.Flush();
            
            Response.End();
            
            // File.Delete(sFileDir + strOutputExcelFile);            
        }        
        else        
        {        
            lblMessage.Text = "Error in writing the Excel Report.";
        
        }        
    }  
    catch (Exception ex)>>>empty file path 
    {    
        string strMsg = ex.Message;
        
        objError.SaveError("UploadFiles", MethodBase.GetCurrentMethod().Name, ex.Message + ex.InnerException);    
    }
}
Posted
Updated 6-Jul-12 8:46am
v2
Comments
db7uk 6-Jul-12 15:23pm    
What is wrong? what error?

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