how to use save dialog box for download files
<p>in my project i have a folder containing N number of files. I need a functionality that the page should have links for all those files so that client can download those files.</p>

<p>For this i have dynamically created Link Buttons and linked each file with each link Button.</p>

<p>The Code is as </p>

<pre><code> string filePath = Request.PhysicalPath.Substring(0, Request.PhysicalPath.LastIndexOf("\\"));
        filePath = filePath.Substring(0, filePath.LastIndexOf("\\"));
        filePath = filePath.Substring(0, filePath.LastIndexOf("\\")) + "\\Export";

        string[] files = System.IO.Directory.GetFiles(filePath);
        Array.Sort(files);
        Array.Reverse(files);
        int counter = 0;
        foreach (string file in files)
        {
            if (counter &gt;= 10)
                break;
            LinkButton linkButton = new LinkButton();
            int startIndex = Convert.ToInt32(file.LastIndexOf("\\"));
            int length = Convert.ToInt32(file.Length);
            string fileName = file.Substring(startIndex + 1, length - startIndex - 1).ToString();
            fileName = fileName.Substring(0, fileName.LastIndexOf("."));
            string[] a = fileName.Split('_');
            string year = a[1].Substring(0, 4);
            string month = a[1].Substring(4, 2);
            switch (month)
            {
                case "01":
                    month = "January";
                    break;
                case "02":
                    month = "February";
                    break;

                case "03":
                    month = "March";
                    break;
                case "04":
                    month = "April";
                    break;
                case "05":
                    month = "May";
                    break;
                case "06":
                    month = "June";
                    break;
                case "07":
                    month = "July";
                    break;
                case "08":
                    month = "August";
                    break;
                case "09":
                    month = "September";
                    break;
                case "10":
                    month = "October";
                    break;
                case "11":
                    month = "November";
                    break;
                case "12":
                    month = "December";
                    break;

            }
            counter++;
            linkButton.ForeColor = System.Drawing.ColorTranslator.FromHtml("#b32317");
            linkButton.Text = month + " " + year + " Car Hire Details";
            //hyperlink.NavigateUrl = file.ToString();
            linkButton.Font.Bold = true;
            //hyperlink.ID = "TestLB";
            linkButton.Command += new CommandEventHandler(this.lb_Command);
            linkButton.CommandArgument = file.ToString();
            Panel1.Controls.Add(linkButton);
            Label lbl1 = new Label();
            lbl1.Text = "&lt;br /&gt; &lt;br /&gt;";
            Panel1.Controls.Add(lbl1);

        }


    }


    protected void lb_Command(object sender, CommandEventArgs e)
    {

        System.String filename = e.CommandArgument.ToString();// this is your file name 
        Response.ContentType = "Plain/Text";
        System.String disHeader = "Attachment; Filename=\"" + filename + "\"";
        Response.AppendHeader("Content-Disposition", disHeader);
        System.IO.FileInfo fileToDownload = new System.IO.FileInfo(e.CommandArgument.ToString());
        //filepath to download 
        Response.Flush();
        Response.WriteFile(fileToDownload.FullName);


    }
</code></pre>

<p>But the problem is that, when i am trying to download this:</p>

<ol>
<li><p>the file is downloading in HTML format, moreover the file name of downloaded file becomes same to my Code file name where as i want the actual name.</p></li>
<li><p>the downloaded file have the actual data but it also contains the html code to the page on which this links are coming</p></li>
</ol>

<p>Can any body help me out for this.</p>
