内联网应用程序中的搜索框,Asp.net [英] Search Box in Intranet Application, Asp.net

查看:75
本文介绍了内联网应用程序中的搜索框,Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



1.是一个Intranet应用程序..所有文件(pdf,excel,text ...等)都保存在一个文件夹中名为DAL

2.在我的主页上我有一个搜索按钮...当我搜索文件时,它应该只搜索DAL目录并且必须在页面中显示搜索到的文件。 (在这里它的工作)。

3.在页面显示之后我应该下载搜索到的文件。



upto 2nd指出它的工作..就像只读...但我无法下载..

i想在页面中搜索并显示后下载这些文件..

这里附上那些.aspx和.aspx.cs文件用于referance。

*我觉得这些文件应该显示在网格,转发器或链接中。但是当我点击文件时它应该下载。





c#.net:



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 :

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");
            }
        }
    }
}







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>

推荐答案

首先,我建议您使用转发器。它比response.write更好。

下载有两种不同的方式来到我的脑海。



第一种方法是拖动你网站文件夹下的文件夹,根据你的网站基础文件夹给出相对路径。



第二种方法是当点击按钮为该文件创建流媒体并使用response.write发送数据或只使用response.writefile。以下是示例:

http://www.dotnetperls.com/response-writefile [ ^ ]
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[^]


这篇关于内联网应用程序中的搜索框,Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆