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.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblErrorMsg.Text = "";
if (!IsPostBack)
{
try
{
string path;
if (Request.QueryString["PATH"] == null)
path = @"\\Process Database\Process Repository\Best Practices";
else
path = Server.UrlDecode(Request.QueryString["PATH"].ToString());
GridView1.DataSource = fillGridView(path);
GridView1.DataBind();
if(path.Equals(@"//DATAGRP/QAv21/QMS/Delivery/Quality Pebbles/Articles"))
{
lblErrorMsg.Text = "Quality Pebbles Articles";
lblErrorMsg1.Visible = true;
lblErrorMsg1.Text = "Quality Pebbles Answers";
path = @"\\DATAGRP\QAv21\QMS\Delivery\Quality Pebbles\Answer";
GridView2.DataSource = fillGridView(path);
GridView2.DataBind();
}
}
catch(QMSExceptions qmsex)
{
HandleQmsException(qmsex);
}
catch (Exception ex)
{
HandleException(ex);
}
}
}
private Names[] fillGridView(string path)
{
try
{
Names names = null;
object[] obj = null;
int gridRow = 0;
int index, docIndex;
int fileCounter = -1;
int directoryCount = -1;
DirectoryInfo dirInfo = new DirectoryInfo(path);
DirectoryInfo[] aryDirInfo = dirInfo.GetDirectories();
FileInfo[] aryFi = dirInfo.GetFiles();
int cnt;
cnt = aryFi.Length + aryDirInfo.Length;
if (cnt == 0)
throw new QMSExceptions("Directory is Empty");
int totalDocs = aryFi.Length + aryDirInfo.Length - 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.Length - 1)
{
obj = (DirectoryInfo[])aryDirInfo;
docIndex = directoryCount + 1;
directoryCount++;
}
else
{
obj = (FileInfo[])aryFi;
docIndex = fileCounter + 1;
fileCounter++;
}
names = new Names();
names.Name1 = ((System.IO.FileSystemInfo)(obj[docIndex])).Name;
if (obj.GetType().Name == "DirectoryInfo[]")
{
string paths = ((System.IO.FileSystemInfo)(obj[docIndex])).FullName.ToString();
paths = Server.UrlPathEncode(paths);
paths = paths.Replace("\\", "/");
names.Path1 = "javascript
:openNewWindow('Test.aspx?PATH=" + paths + "')";
}
else
names.Path1 = ((System.IO.FileSystemInfo)(obj[docIndex])).FullName;
index += 1;
if (index > totalDocs)
{
nameList[gridRow] = names;
break;
}
if (index <= aryDirInfo.Length - 1)
{
obj = (DirectoryInfo[])aryDirInfo;
docIndex = directoryCount + 1;
directoryCount++;
}
else
{
obj = (FileInfo[])aryFi;
docIndex = fileCounter + 1;
fileCounter++;
}
names.Name2 = ((System.IO.FileSystemInfo)(obj[docIndex])).Name;
if (obj.GetType().Name == "DirectoryInfo[]")
{
string paths = ((System.IO.FileSystemInfo)(obj[docIndex])).FullName.ToString();
paths = Server.UrlPathEncode(paths);
paths = paths.Replace("\\", "/");
names.Path2 = "javascript
:openNewWindow('Test.aspx?PATH=" + paths + "')";
}
else
names.Path2 = ((System.IO.FileSystemInfo)(obj[docIndex])).FullName;
index += 1;
if (index > totalDocs)
{
nameList[gridRow] = names;
break;
}
if (index <= aryDirInfo.Length - 1)
{
obj = (DirectoryInfo[])aryDirInfo;
docIndex = directoryCount + 1;
directoryCount++;
}
else
{
obj = (FileInfo[])aryFi;
docIndex = fileCounter + 1;
fileCounter++;
}
names.Name3 = ((System.IO.FileSystemInfo)(obj[docIndex])).Name;
if (obj.GetType().Name == "DirectoryInfo[]")
{
string paths = ((System.IO.FileSystemInfo)(obj[docIndex])).FullName.ToString();
paths = Server.UrlPathEncode(paths);
paths = paths.Replace("\\", "/");
names.Path3 = "javascript
:openNewWindow('Test.aspx?PATH=" + paths + "')";
}
else
names.Path3 = ((System.IO.FileSystemInfo)(obj[docIndex])).FullName;
index += 1;
if (index > totalDocs)
{
nameList[gridRow] = names;
break;
}
if (index <= aryDirInfo.Length - 1)
{
obj = (DirectoryInfo[])aryDirInfo;
docIndex = directoryCount + 1;
directoryCount++;
}
else
{
obj = (FileInfo[])aryFi;
docIndex = fileCounter + 1;
fileCounter++;
}
names.Name4 = ((System.IO.FileSystemInfo)(obj[docIndex])).Name;
if (obj.GetType().Name == "DirectoryInfo[]")
{
string paths = ((System.IO.FileSystemInfo)(obj[docIndex])).FullName.ToString();
paths = Server.UrlPathEncode(paths);
paths = paths.Replace("\\", "/");
names.Path4 = "javascript
:openNewWindow('Test.aspx?PATH=" + paths + "')";
}
else
names.Path4 = ((System.IO.FileSystemInfo)(obj[docIndex])).FullName;
nameList[gridRow] = names;
gridRow = gridRow + 1;
}
return nameList;
}
catch (Exception ex)
{
Names[] temp = null;
HandleException(ex);
return temp;
}
}
private void HandleQmsException(QMSExceptions hqmsex)
{
lblErrorMsg.Text = hqmsex.Message.Replace(":", "-");
}
private void HandleException(Exception hex)
{
lblErrorMsg.Text = hex.Message.Replace(":", "-");
}
}