Click here to Skip to main content
15,669,040 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I am using below code snippet to download an excel file in our website.

but my problem is : I have to download a password protected and encrypted excel file and decrypt it using any windows based software.

please help me to solve this problem.

Any type of help is highly appreciable.

Thanks in advance.....

string strQuery = @"select
                   isnull(TSED.Scholarship_Second,TSED.Scholarship_First) as [Amount],
                   (TSPR.First_Name+' '+TSPR.Middle_Name+' '+TSPR.Last_Name) as  [Name],
                   TSPR.Mobile,TDD.Disbursal_No As [Disbursal No],
               from tbl_Disbursal_Details TDD
                   inner join tbl_Proposal_Detail TPD
                       on TPD.Proposal_No = SUBSTRING(Disbursal_No,19,4)+ '/' +SUBSTRING(Disbursal_No,3,10) + '/' +SUBSTRING(Disbursal_No,14,1)+ '/' +SUBSTRING(Disbursal_No,16,2) + '/' + SUBSTRING(Disbursal_No,24,2)
                   inner join tbl_Proposal_Master TPM
                       on TPM.Proposal_No = tpd.Proposal_No
                   inner join tbl_Student_Personal_Registration TSPR
                       on TSPR.Student_Code = TPM.Student_Code
                   inner join tbl_Student_Educational_Details TSED
                       on TSED.Student_Code = TSPR.Student_Code and TSED.School_Code = TSPR.School_Code
                   inner join tbl_Dist_Master TDM
                       on TDM.Dist_Code = SUBSTRING(TDD.Disbursal_No,5,2)
                   inner join tbl_Block_Master TBM
                       on TBM.Dist_Code = TDm.Dist_Code and TBM.Block_Code = SUBSTRING(TDD.Disbursal_No,7,2)
                   inner join tbl_School_Master TSM
                       on tsm.School_Code = SUBSTRING(TDD.Disbursal_No,3,10)
               where Disbursal_No = @DisNo And TPM.flag_Rejected_ByBank = 0 ";

           SqlCommand cmd = new SqlCommand(strQuery);
           cmd.Parameters.Add("@DisNo", SqlDbType.NVarChar).Value = DNo;
           DataTable dt = GetData(cmd);

           //Create a dummy GridView
           GridView GridView1 = new GridView();
           GridView1.AllowPaging = false;
           GridView1.DataSource = dt;

           Response.Buffer = true;
           Response.AddHeader("content-disposition", "attachment;filename=" + DNo + ".xls");
           Response.Charset = "";
           Response.ContentType = "application/vnd.xls";
           StringWriter sw = new StringWriter();
           HtmlTextWriter hw = new HtmlTextWriter(sw);

           for (int i = 0; GridView1.Rows.Count; i++)
               //Apply text style to each Row
               GridView1.Rows[i].Attributes.Add("class", "textmode");


           //style to format numbers to string
           string style = @".textmode { mso-number-format:";
Updated 2-Feb-15 3:45am
Sergey Alexandrovich Kryukov 2-Feb-15 10:54am    
Why? Whats' the scenario? Who is encrypting is and who is decrypting, using what, who has access to what? Encryption only makes sense of some have access and some don't. How the access should be provided?
Arkadeep De 2-Feb-15 11:47am    
you can follow this link

and for password protection you can put it into a zip file with password protection. search it is google..its available.

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