Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I am using Response.WriteFile method for downloading an excel sheet from a desired location to client machine.Below is the code:-
// Checking if file exists
                if (myfile.Exists)
                {
                    // Clear the content of the response  
                    HttpContext.Current.Response.ClearContent();
 
                    // Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
 
                    // Add the file size into the response header
                    HttpContext.Current.Response.AddHeader("Content-Length", myfile.Length.ToString());
 
                    // Set the ContentType
                    HttpContext.Current.Response.ContentType = ReturnExtension(myfile.Extension.ToLower());
 
                    // Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
                    HttpContext.Current.Response.WriteFile(myfile.FullName);
 
                    // End the response
                    HttpContext.Current.Response.End();
                }
private string ReturnExtension(string fileExtension)
        {
            switch (fileExtension)
            {
                case ".xlsx":
                    return "application/excel";
                default:
                    return "application/octet-stream";
            }
        }
 
I want that once the download pop up will appear and asking for Save/Open/Cancel and the end user select his option then after completion of that task a post back happen to the webpage from where it is been invoked. Suppose if user click save then the file get saved and after saving a post back will happen.Same if user select open then the file will be opened and then a post back happen to the webpage from where this Download function is invoked.
Posted 2-Mar-12 0:36am
Comments
dimpledevani at 2-Mar-12 5:56am
   
well you can redirect it back to your desired page after your task complete
Dharmenrda Kumar Singh at 2-Mar-12 6:00am
   
I had tried this but once i am redirecting to the same page , the download pop up is getting disappear.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

it is very easy man you can add button with visible = "false" property and with
OnClick="button1_Click" property
button1_Click((object sender, System.EventArgs e)
{
   //and leave it empty;
}
 
the after you finish your code at the end call this button event
as follows:
button1_Click(null,null);
 
ex: as you say if user select open then the file will be opened and then a post back happen ok at the end of this code (and the file opened)call the empty function...easy
 
regard
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

i have a same problem plz help me
solution1 does't work
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<pre lang="c#"><pre lang="text"><pre lang="text"></pre></pre></pre>All You Can Do.You Should Use JavaScript Method Before Exporting Your Excel.To Call The Server Side Event. Or If You Can Handle it in Your JavaScript It Will Better..
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 PIEBALDconsult 150
2 BillWoodruff 148
3 Jochen Arndt 135
4 DamithSL 130
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100