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

1.its an Intranet application ..all the files(pdf,excel,text...etc) are maintained in an folder called "DAL"
2.in my home page i have an search button...when i search files it should only search in "DAL" Directory and have to display the searched files in a page..(upto here its working).
3.after displaying in an page i should have to download those searched files.

upto 2nd point its working ..just like read only...but i cant able to download..
i want to download those files after searching and displaying in the page..
here am attaching those .aspx and .aspx.cs files for referance.
* i feel those files should display in grid,repeater or as a links. but when i click file it should download.


c#.net :

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SEARCH : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        {
            string search = TextBox1.Text;
            string[] files = Directory.GetFiles(@"F:\\abcd.co.in\DAL\", "*.*", SearchOption.AllDirectories);
            int Flag = 0;
            string dir = @"F:\\abcd.co.in\DAL\";
            string[] files1;
            int numFiles;
            files1 = Directory.GetFiles(dir);

            numFiles = files.Length;
            Response.Write("Files searched : " + numFiles + "<br>");
            for (int i = 0; i < numFiles; i++)
            {


                string file = files[i].ToString();

                int file1 = file.IndexOf(search, StringComparison.CurrentCultureIgnoreCase);
                if (file1 != -1)
                {
                                      Response.Write("<br>" + file);
                    ////GridView1.DataSource = file;
                    ////GridView1.DataBind();


                    Flag = 1;


                }

            }
            if (Flag == 0)
            {
                Response.Write("No Matches Found");
            }
        }
    }
}


XML
inline code :
<pre lang="xml">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;SEARCH.aspx.cs&quot; Inherits=&quot;SEARCH&quot; %&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;

        &lt;asp:TextBox ID=&quot;TextBox1&quot; runat=&quot;server&quot;&gt;&lt;/asp:TextBox&gt;
        &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; onclick=&quot;Button1_Click&quot; Text=&quot;Button&quot; /&gt;

        &lt;br /&gt;
        &lt;br /&gt;

    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
Posted
Updated 2-Jun-13 22:32pm
v2

1 solution

At first I suggest you that use repeater. It is better than response.write.
To download there are two different way came to my mind.

The first way drag the folder under your website folder and give relative path according to your website base folder.

The second way is when button clicked create a streaming for this file and use response.write to send data or just use response.writefile. here is the example :
http://www.dotnetperls.com/response-writefile[^]
 
Share this answer
 
v2
Comments
kalyan ved 3-Jun-13 4:52am    
osman ,
yeah i have the idea that repeater can use.....
but i want the idea how to do that using repeater by downloading file...
Osman24 3-Jun-13 6:47am    
I do not understand what you need but as you must create a button or link button to download and when this clicked you can get the name from its item index and give the link or write the file. If you exatcly tell your problem I can be more helpful.

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