Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Below is my problem scenario.

I have developed one web sie using ASP.net.

I am using Master page in this website and on that master page i have menu contorls, Log out button placed.

I have one web page which is having pdf downloading functionality.

Below is my pdf downloading code.

DirectoryInfo myDir = new DirectoryInfo("C:\\Bills" + billmonth);
                   FileInfo[] files = myDir.GetFiles(PDFName + "*.pdf");
                   byte[] bytes = null;
                   string path = files[0].FullName;
                   bytes = System.IO.File.ReadAllBytes(path);
                   Response.ClearHeaders();
                   Response.ClearContent();
                   Response.ContentType = "application\\pdf";
                   Response.ContentEncoding = System.Text.Encoding.UTF8;
                   Response.AddHeader("Content-disposition", "attachment; filename=" + files[0].Name);
                   Response.BinaryWrite(bytes);
                   Response.End();



Above code is working fine in browser.

But my problem starts here ,when my pdf download compltets and i try to log out from my web site then log out functionality not working. To logout from web site i need to refresh page every time.

Please help me

Thanks,
application
Posted
Updated 17-Dec-14 20:01pm
v3
Comments
What happens when you Log Out, any error or exceptions? Have you debugged on Log Out click?
ZurdoDev 17-Dec-14 9:34am    
Need more details. Why doesn't it work? Is there an error?
Manoj Kumar Choubey 17-Dec-14 10:01am    
I think your problem not related with above code please check on script of both side client side script or server side script , and try to reach login logout functionality, how you are doing this .....
Pro86 18-Dec-14 0:49am    
Hello Everyone,

As suggested I have debug the log out code but it is not going to debuger point.

However if I removed Response.End line from above code then it is working fine and i am able to debug also log out functionality.
Sinisa Hajnal 18-Dec-14 2:24am    
That means that your logout button binding code is probably "below" the download code and the button never gets bound. Work out on the event series and bind the button handler earlier. Or just leave out response.end if there is no consequences.

C#
protected void lnkfilepath_Click(object sender, EventArgs e) // ur link button
    {
        string filename = lnkfilepath.Text;
        string Filpath = Server.MapPath("~/Attachments/" + filename);
        DownLoad(Filpath);

    }
    public void DownLoad(string FName)
    {
        string path = FName;
        System.IO.FileInfo file = new System.IO.FileInfo(path);
        if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream"; // download all types of files..
            Response.WriteFile(file.FullName);
            Response.End();

        }
        else
        {
            Response.Write("This file does not exist.");
        }

    }

HTML



Can u use this above code..its support all types of file downloading
Reference Click Here
 
Share this answer
 
Hi shashikant86 , you can't understand what happening the code ,
just put the below code in after download code it refresh the page automatically

Respons.Redirect("yourpage.aspx")
 
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