Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have gridview and i am exproting that gridview data to excel.

Before downloading i show popup as Open Save Cancel.

When user click the Open the excel is file open.

The excel open code as follows

C#
System.Threading.Thread.Sleep(3000);
           System.IO.StringWriter sw = new System.IO.StringWriter();
           HtmlTextWriter htw = new HtmlTextWriter(sw);
           gvEmpdetails.AllowPaging = false;
           BindGrid();
           //Applying stlye to gridview header cells
           for (int i = 0; i < gvEmpdetails.HeaderRow.Cells.Count; i++)
               gvEmpdetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
           gvEmpdetails.RenderControl(htw);
           Session["ResponseData"] = sw.ToString();
           iframe1.Attributes.Add("src", "Download.aspx");

When user the Open button in the popup excel is open it is working correctly.

Simliarily When user Click Save button in the popup the user select the path where excel is to be there and save the excel file.

for that saving the excel file what code i have to do.

What I have tried:

i have gridview and i am exproting that gridview data to excel.

Before downloading i show popup as  Open Save Cancel.

When user click the Open the excel is file open.

The excel open code as follows

<pre lang="C#">System.Threading.Thread.Sleep(3000);
           System.IO.StringWriter sw = new System.IO.StringWriter();
           HtmlTextWriter htw = new HtmlTextWriter(sw);
           gvEmpdetails.AllowPaging = false;
           BindGrid();
           //Applying stlye to gridview header cells
           for (int i = 0; i < gvEmpdetails.HeaderRow.Cells.Count; i++)
               gvEmpdetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
           gvEmpdetails.RenderControl(htw);
           Session["ResponseData"] = sw.ToString();
           iframe1.Attributes.Add("src", "Download.aspx");

When user the Open button in the popup excel is open it is working correctly.

Simliarily When user Click Save button in the popup the user select the path where excel is to be there and save the excel file.

for that saving the excel file what code i have to do.
Posted
Updated 4-May-16 23:23pm
Comments
F-ES Sitecore 5-May-16 5:11am    
Google "download file asp.net" for the proper code to send a file to the user, your code doesn't make much sense and it's hard to know what is going out without context.

If your question is how to specify the path that the file is to be saved at, you can't do that, it is up to the user to decide where the file is saved, if it is saved at all. If your question is that the file is saving but not opening when you double-click it that will be because you're not really generating an Excel file (there are a lot of code samples that claim to be creating Excel files but they're misleading).

1 solution

ASP.NET is unable to interact with client machine folder structure, as it has only access to browser only.
that's why, When you download any file from web application it ask you for the path to store the file. You can not directly put/download file in client machine it may treat as malicious activity.
 
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