Using Asp.net, I'm reading a path and showing all the files path in a runtime created Text box/boxes as follows:
These Files not just pdf but ppt, doc,docx, etc and the code which i used is:
protected void SearchButton_Click(object sender, EventArgs e)
{
string dir = @"D:\file path\";
SearchResultPanel.Visible = true;
try
{
//Set the current directory.
Directory.SetCurrentDirectory(dir);
//search all files in path
string[] directoryEntries = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories);
int fill = directoryEntries.Length - 1;
//Total count of files & Decoration
SearchResultPanel.Controls.Add(new LiteralControl("<br />"));
Label leb = new Label();
SearchResultPanel.Controls.Add(new LiteralControl("The total files count: "));
leb.Text = directoryEntries.Length.ToString();
this.SearchResultPanel.Controls.Add(leb);
SearchResultPanel.Controls.Add(new LiteralControl("<hr />"));
//retriving the files in new labels
for (int i = 0; i < fill; i++)
{
TextBox NewText = new TextBox();
NewText.BorderStyle = BorderStyle.NotSet;
NewText.TextMode = TextBoxMode.MultiLine;
NewText.Width = 380;
NewText.Height = 40;
TextBox NewTextP = new TextBox();
NewTextP.BorderStyle = BorderStyle.NotSet;
NewTextP.TextMode = TextBoxMode.MultiLine;
NewTextP.Width = 380;
NewTextP.Height = 40;
Button ButtonOpen = new Button();
ButtonOpen.Text = "Open";
//fill the text boxes with file entries
String path = directoryEntries[i];
NewText.Text = directoryEntries[i];
NewTextP.Text = "Dummy Paragraph";
**ButtonOpen.Click += OpenFile(path);**
//new line
SearchResultPanel.Controls.Add(new LiteralControl("<br />"));
//show the text box
this.SearchResultPanel.Controls.Add(NewText);
SearchResultPanel.Controls.Add(new LiteralControl("	"));
this.SearchResultPanel.Controls.Add(NewTextP);
SearchResultPanel.Controls.Add(new LiteralControl("	"));
this.SearchResultPanel.Controls.Add(ButtonOpen);
}//end of for
}//end of try
catch (DirectoryNotFoundException ex)
{
Console.WriteLine("The specified directory does not exist. {0}", ex);
}
I'm getting a problem @ ButtonOpen.Click += OpenFile(path);
as how to open the path associate file on the click of OPEN button.
Any Suggessions?