Search Engine

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kbipul
    New Member
    • Nov 2006
    • 27

    Search Engine

    Hi

    In a web application , I need to create an aspx page(in C#) which can serach the files present on the server at the specified locations.

    The search parameter may be the file name, extn name, location, fully or partly. The resulting file names should be displayed in a datagrid.

    I am clueless about the functionality involved to create this search engine.

    Can anyone help me?
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Originally posted by kbipul
    Hi

    In a web application , I need to create an aspx page(in C#) which can serach the files present on the server at the specified locations.

    The search parameter may be the file name, extn name, location, fully or partly. The resulting file names should be displayed in a datagrid.

    I am clueless about the functionality involved to create this search engine.

    Can anyone help me?
    The way this is normally done is through the use of metadata:
    Metadata and Reflection in .NET

    Comment

    • kbipul
      New Member
      • Nov 2006
      • 27

      #3
      Originally posted by kenobewan
      The way this is normally done is through the use of metadata:
      Metadata and Reflection in .NET

      I could not get the task done . I have this sample code which is used to populate the gridview with the file names. This code is working fine


      How can the results be filtered? Someone please edit the code so that it can filter the data. I am clueless.


      using System;
      using System.Text;
      using System.Data;
      using System.Configur ation;
      using System.Collecti ons;
      using System.Web;
      using System.Web.Secu rity;
      using System.Web.UI;
      using System.Web.UI.W ebControls;
      using System.Web.UI.W ebControls.WebP arts;
      using System.Web.UI.H tmlControls;
      using System.IO;


      public partial class Test : System.Web.UI.P age
      {
      protected void Page_Load(objec t sender, EventArgs e)
      {
      lblErrorMsg.Tex t = "";

      if (!IsPostBack)
      {
      try
      {
      string path;

      if (Request.QueryS tring["PATH"] == null)
      path = @"\\Process Database\Proces s Repository\Best Practices";
      else
      path = Server.UrlDecod e(Request.Query String["PATH"].ToString());

      GridView1.DataS ource = fillGridView(pa th);
      GridView1.DataB ind();

      if(path.Equals( @"//DATAGRP/QAv21/QMS/Delivery/Quality Pebbles/Articles"))
      {
      lblErrorMsg.Tex t = "Quality Pebbles Articles";
      lblErrorMsg1.Vi sible = true;
      lblErrorMsg1.Te xt = "Quality Pebbles Answers";
      path = @"\\DATAGRP\QAv 21\QMS\Delivery \Quality Pebbles\Answer" ;
      GridView2.DataS ource = fillGridView(pa th);
      GridView2.DataB ind();
      }

      }
      catch(QMSExcept ions qmsex)
      {
      HandleQmsExcept ion(qmsex);
      }
      catch (Exception ex)
      {
      HandleException (ex);
      }

      }

      }

      private Names[] fillGridView(st ring path)
      {
      try
      {
      Names names = null;
      object[] obj = null;
      int gridRow = 0;
      int index, docIndex;
      int fileCounter = -1;
      int directoryCount = -1;

      DirectoryInfo dirInfo = new DirectoryInfo(p ath);

      DirectoryInfo[] aryDirInfo = dirInfo.GetDire ctories();
      FileInfo[] aryFi = dirInfo.GetFile s();

      int cnt;
      cnt = aryFi.Length + aryDirInfo.Leng th;
      if (cnt == 0)
      throw new QMSExceptions(" Directory is Empty");

      int totalDocs = aryFi.Length + aryDirInfo.Leng th - 1;
      if (cnt % 4 == 0)
      cnt = cnt / 4;
      else
      cnt = (cnt / 4) + 1;
      Names[] nameList = new Names[cnt];

      for (index = 0; index <= totalDocs; index++)
      {
      if (index <= aryDirInfo.Leng th - 1)
      {
      obj = (DirectoryInfo[])aryDirInfo;
      docIndex = directoryCount + 1;
      directoryCount+ +;
      }
      else
      {
      obj = (FileInfo[])aryFi;
      docIndex = fileCounter + 1;
      fileCounter++;
      }

      names = new Names();
      names.Name1 = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).Name;
      if (obj.GetType(). Name == "DirectoryI nfo[]")
      {
      string paths = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).FullName.ToS tring();
      paths = Server.UrlPathE ncode(paths);
      paths = paths.Replace(" \\", "/");
      names.Path1 = "javascript:ope nNewWindow('Tes t.aspx?PATH=" + paths + "')";
      }
      else
      names.Path1 = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).FullName;

      index += 1;
      if (index > totalDocs)
      {
      nameList[gridRow] = names;
      break;
      }

      if (index <= aryDirInfo.Leng th - 1)
      {
      obj = (DirectoryInfo[])aryDirInfo;
      docIndex = directoryCount + 1;
      directoryCount+ +;
      }
      else
      {
      obj = (FileInfo[])aryFi;
      docIndex = fileCounter + 1;
      fileCounter++;
      }

      names.Name2 = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).Name;
      if (obj.GetType(). Name == "DirectoryI nfo[]")
      {
      string paths = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).FullName.ToS tring();
      paths = Server.UrlPathE ncode(paths);
      paths = paths.Replace(" \\", "/");
      names.Path2 = "javascript:ope nNewWindow('Tes t.aspx?PATH=" + paths + "')";
      }
      else
      names.Path2 = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).FullName;

      index += 1;
      if (index > totalDocs)
      {
      nameList[gridRow] = names;
      break;
      }

      if (index <= aryDirInfo.Leng th - 1)
      {
      obj = (DirectoryInfo[])aryDirInfo;
      docIndex = directoryCount + 1;
      directoryCount+ +;
      }
      else
      {
      obj = (FileInfo[])aryFi;
      docIndex = fileCounter + 1;
      fileCounter++;
      }

      names.Name3 = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).Name;
      if (obj.GetType(). Name == "DirectoryI nfo[]")
      {
      string paths = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).FullName.ToS tring();
      paths = Server.UrlPathE ncode(paths);
      paths = paths.Replace(" \\", "/");
      names.Path3 = "javascript:ope nNewWindow('Tes t.aspx?PATH=" + paths + "')";
      }
      else
      names.Path3 = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).FullName;

      index += 1;
      if (index > totalDocs)
      {
      nameList[gridRow] = names;
      break;
      }

      if (index <= aryDirInfo.Leng th - 1)
      {
      obj = (DirectoryInfo[])aryDirInfo;
      docIndex = directoryCount + 1;
      directoryCount+ +;
      }
      else
      {
      obj = (FileInfo[])aryFi;
      docIndex = fileCounter + 1;
      fileCounter++;
      }

      names.Name4 = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).Name;
      if (obj.GetType(). Name == "DirectoryI nfo[]")
      {
      string paths = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).FullName.ToS tring();
      paths = Server.UrlPathE ncode(paths);
      paths = paths.Replace(" \\", "/");
      names.Path4 = "javascript:ope nNewWindow('Tes t.aspx?PATH=" + paths + "')";
      }
      else
      names.Path4 = ((System.IO.Fil eSystemInfo)(ob j[docIndex])).FullName;

      nameList[gridRow] = names;
      gridRow = gridRow + 1;
      }
      return nameList;

      }
      catch (Exception ex)
      {
      Names[] temp = null;
      HandleException (ex);
      return temp;
      }
      }

      private void HandleQmsExcept ion(QMSExceptio ns hqmsex)
      {
      lblErrorMsg.Tex t = hqmsex.Message. Replace(":", "-");
      }

      private void HandleException (Exception hex)
      {
      lblErrorMsg.Tex t = hex.Message.Rep lace(":", "-");
      }
      }

      Comment

      Working...