I am writing a code for a search function. I need to search the folders for the particular file/files(only excel files/ there may be several files with the same name) & display them. I should also be able to open each of the file by clicking it.
i have succeeded in displaying the results in a dynamic table. I am using link buttons to open the files.when i click the button there is no action.
my code
i have succeeded in displaying the results in a dynamic table. I am using link buttons to open the files.when i click the button there is no action.
my code
Code:
namespace WebApplication3
{
public partial class WebForm1 : System.Web.UI.Page
{
string sku;
string sku_trim;
string sku1;
string sku_uppercase;
string order_confirm;
string quoation;
string year;
string searchwithin;
string searchfor;
int match;
int number;
LinkButton lbn;
string path;
string path_quote;
private void Page_Load(object sender, EventArgs e)
{
year = Session["year"].ToString();
sku = Session["search"].ToString();
if (Session["search"] != null)
{
Label1.Text = Session["search"].ToString();
sku_trim = Label1.Text;
sku_uppercase = sku_trim.Replace(" ", "");
sku = sku_uppercase.ToUpper();
order_confirmation();
}
}
public void order_confirmation()
{
DirectoryInfo static1 = new DirectoryInfo(@"C:\Users\Dell\Desktop\SKU");
path = static1.FullName + @"\" + year + @"\OrderConfirmation";
DirectoryInfo dir = new DirectoryInfo(path);
// DirectoryInfo dir = new DirectoryInfo(@"C:\Users\Dell\Desktop\SKU\2010\OrderConfirmation");
FileInfo[] xlsxfiles = dir.GetFiles("*.xlsx", SearchOption.AllDirectories);
number = xlsxfiles.Count();
//Response.Write("Order Confirmation");
Table dynTable = new Table();
dynTable.ID = "order_confirmation";
dynTable.BorderWidth = 1;
// this.Controls.Add(dynTable);
this.form1.Controls.Add(dynTable);
foreach (FileInfo f in xlsxfiles)
{
searchwithin = f.Name;
searchfor = sku;
match = searchwithin.IndexOf(searchfor);
// sku1 = sku + ".xlsx";
Label confirm_label = new Label();
Label button_perform = new Label();
if (match >= 0)
{
confirm_label.Text = f.FullName;
order_confirm = f.FullName;
TableRow row = new TableRow();
row.BorderWidth = 1;
TableCell cell1 = new TableCell();
cell1.BorderWidth = 1;
cell1.Controls.Add(confirm_label);
row.Controls.Add(cell1);
dynTable.Controls.Add(row);
TableCell cell2 = new TableCell();
cell2.BorderWidth = 1;
lbn = new LinkButton();
lbn.ID = f.FullName;
lbn.Text = "Open";
lbn.Command += new System.Web.UI.WebControls.CommandEventHandler(btn_open_Click);
lbn.CommandName = f.FullName;
lbn.CommandArgument = f.FullName;
cell2.Controls.Add(lbn);
row.Controls.Add(cell2);
dynTable.Controls.Add(row);
// this.Controls.Add(new LiteralControl("<br>"));
//Response.Write("<br><a href=" + f.Name >" + f.FullName+ "</a>");
}
else
{
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void btn_open_Click(object sender,CommandEventArgs e)
{
//HttpContext.Current.Response.Clear();
//HttpContext.Current.Response.ClearHeaders();
//HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + order_confirm);
//HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
//HttpContext.Current.Response.WriteFile(order_confirm);
//HttpContext.Current.Response.End();
Response.Write("hello");
}
}
}
Comment