[CLOSED] How can i download Excel file from the server side with Ext.Net with C#

  1. #1

    [CLOSED] How can i download Excel file from the server side with Ext.Net with C#

    Hi all,

    My case is, I try to generate my report with an excel file by getting information from my database and then write it into the excel file and after that i need to download that excel file into client machine but this kind of code work properly when it use ASP.Net only. When i try it with Ext.Net it doesn't work. Any help about this would be appreciate and thank in advanced because i'm stucking with this now....


    Here is my code:
    protected void SaveYearPDFClick(object sender,EventArgs e)
        {
    Microsoft.Office.Interop.Excel.Application appExl;
            Microsoft.Office.Interop.Excel.Workbook workbook;
            Microsoft.Office.Interop.Excel.Worksheet NwSheet;
            appExl = new Microsoft.Office.Interop.Excel.ApplicationClass();
    
    
            //Opening Excel file(myData.xlsx)
            workbook = appExl.Workbooks.Open(Server.MapPath(@"~/Reports/CertifyTemplate.xlsx"), Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
    
            NwSheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets.get_Item(1);
    
            StudentCertify myStudent = StudentPB_CADB.GetCertifyInformation();
            
            
            NwSheet.Cells[12, 3] = myStudent.FullName.ToString();
            NwSheet.Cells[12, 14] = myStudent.FullNameLatin.ToString();
            
            NwSheet.Cells[14, 2] = myStudent.SexName.ToString();
            NwSheet.Cells[14, 5] = myStudent.Identity.ToString();
            NwSheet.Cells[14, 9] = myStudent.NationalityName.ToString();
            
            NwSheet.Cells[14, 12] = myStudent.SexNameLatin.ToString();
            NwSheet.Cells[14, 15] = myStudent.Identity.ToString();
            NwSheet.Cells[14, 20] = myStudent.NationalityNameLatin.ToString();
    
            NwSheet.Cells[16, 4] = myStudent.DateBirth.ToString();
            NwSheet.Cells[16, 14] = myStudent.DateBirthLatin.ToShortDateString();
            NwSheet.Range["N16"].NumberFormat = "dd/mm/yyyy";
    
            workbook.Save();
            workbook.Close();
            appExl.Quit();
    
    
            try
            {
                string XlsPath = Server.MapPath(@"~/Reports/CertifyTemplate.xlsx");
                FileInfo fileDet = new System.IO.FileInfo(XlsPath);
                Response.Clear();
                Response.Charset = "UTF-8";
                Response.ContentEncoding = Encoding.UTF8;
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileDet.Name));
                Response.AddHeader("Content-Length", fileDet.Length.ToString());
                Response.ContentType = "application/ms-excel";
                Response.WriteFile(fileDet.FullName);
                Response.End();
            }
            catch (Exception ex)
            {
                throw ex;
            }
    }
    Last edited by Baidaly; Aug 09, 2013 at 2:30 AM. Reason: [CLOSED]
  2. #2
    If that method is DirectEvent handler then set IsUpload="true" for DirectEvent
  3. #3
    Hi Vladimir,

    Thank you very much, it work now..!

    Quote Originally Posted by Vladimir View Post
    If that method is DirectEvent handler then set IsUpload="true" for DirectEvent
  4. #4
    Hello!

    Please, don't forget to wrap your code in CODE tag: http://forums.ext.net/showthread.php?3440

    Thank you!

Similar Threads

  1. [CLOSED] multiple file upload and file size at client side
    By mirwais in forum 1.x Legacy Premium Help
    Replies: 24
    Last Post: Dec 15, 2014, 5:44 AM
  2. 2.1 zip file download
    By gdog_5021 in forum 2.x Help
    Replies: 4
    Last Post: Dec 03, 2012, 11:14 AM
  3. Replies: 39
    Last Post: Dec 27, 2011, 10:39 AM
  4. [CLOSED] Download a file in an MVC app
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 02, 2010, 9:01 PM
  5. File download
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 05, 2008, 7:22 AM

Posting Permissions