473,787 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening a file using dynamically created link button

1 New Member
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
Expand|Select|Wrap|Line Numbers
  1. namespace WebApplication3
  2. {
  3.     public partial class WebForm1 : System.Web.UI.Page
  4.     {
  5.         string sku;
  6.         string sku_trim;
  7.         string sku1;
  8.         string sku_uppercase;
  9.         string order_confirm;
  10.         string quoation;
  11.         string year;
  12.         string searchwithin;
  13.         string searchfor;
  14.         int match;
  15.         int number;
  16.        LinkButton lbn;
  17.        string path;
  18.        string path_quote;
  19.  
  20.        private void Page_Load(object sender, EventArgs e)
  21.        {
  22.            year = Session["year"].ToString();
  23.            sku = Session["search"].ToString();
  24.            if (Session["search"] != null)
  25.            {
  26.  
  27.                Label1.Text =  Session["search"].ToString();
  28.                sku_trim = Label1.Text;
  29.                sku_uppercase = sku_trim.Replace(" ", "");
  30.                sku = sku_uppercase.ToUpper();
  31.                order_confirmation();
  32.  
  33.            }
  34.        }
  35.  
  36.         public void order_confirmation()
  37.         {
  38.  
  39.                 DirectoryInfo static1 = new DirectoryInfo(@"C:\Users\Dell\Desktop\SKU");
  40.                 path = static1.FullName + @"\" + year + @"\OrderConfirmation";
  41.  
  42.                 DirectoryInfo dir = new DirectoryInfo(path);
  43.                 //  DirectoryInfo  dir = new DirectoryInfo(@"C:\Users\Dell\Desktop\SKU\2010\OrderConfirmation");
  44.                 FileInfo[] xlsxfiles = dir.GetFiles("*.xlsx", SearchOption.AllDirectories);
  45.                 number = xlsxfiles.Count();
  46.                 //Response.Write("Order Confirmation");
  47.                 Table dynTable = new Table();
  48.                 dynTable.ID = "order_confirmation";
  49.                 dynTable.BorderWidth = 1;
  50.                 //   this.Controls.Add(dynTable);
  51.                 this.form1.Controls.Add(dynTable);
  52.  
  53.                 foreach (FileInfo f in xlsxfiles)
  54.                 {
  55.  
  56.  
  57.                     searchwithin = f.Name;
  58.                     searchfor = sku;
  59.                     match = searchwithin.IndexOf(searchfor);
  60.                     // sku1 = sku + ".xlsx";
  61.                     Label confirm_label = new Label();
  62.                     Label button_perform = new Label();
  63.                     if (match >= 0)
  64.                     {
  65.  
  66.                         confirm_label.Text = f.FullName;
  67.                         order_confirm = f.FullName;
  68.                         TableRow row = new TableRow();
  69.                         row.BorderWidth = 1;
  70.                         TableCell cell1 = new TableCell();
  71.                         cell1.BorderWidth = 1;
  72.                         cell1.Controls.Add(confirm_label);
  73.                         row.Controls.Add(cell1);
  74.                         dynTable.Controls.Add(row);
  75.  
  76.                         TableCell cell2 = new TableCell();
  77.                         cell2.BorderWidth = 1;
  78.  
  79.                         lbn = new LinkButton();
  80.                         lbn.ID = f.FullName;
  81.                         lbn.Text = "Open";
  82.                         lbn.Command += new System.Web.UI.WebControls.CommandEventHandler(btn_open_Click);
  83.  
  84.                         lbn.CommandName = f.FullName;
  85.                         lbn.CommandArgument = f.FullName;
  86.  
  87.                         cell2.Controls.Add(lbn);
  88.                         row.Controls.Add(cell2);
  89.                         dynTable.Controls.Add(row);
  90.  
  91.                         //  this.Controls.Add(new LiteralControl("<br>"));
  92.                          //Response.Write("<br><a href=" + f.Name >" + f.FullName+ "</a>");
  93.  
  94.                     }
  95.                     else
  96.                     {
  97.  
  98.                     }
  99.  
  100.                 }         
  101.  
  102.         }
  103.  
  104.  
  105.         protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  106.         {
  107.  
  108.         }
  109.  
  110.         protected void btn_open_Click(object sender,CommandEventArgs e)
  111.         {
  112.  
  113.             //HttpContext.Current.Response.Clear();
  114.             //HttpContext.Current.Response.ClearHeaders();
  115.             //HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + order_confirm);
  116.             //HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
  117.             //HttpContext.Current.Response.WriteFile(order_confirm);
  118.             //HttpContext.Current.Response.End();
  119.  
  120.             Response.Write("hello");
  121.  
  122.  
  123.         }
  124.  
  125.  
  126.     }
  127.  
  128. }
  129.  
Sep 7 '10 #1
1 3078
MartijnHoekstra
39 New Member
I would check the following 2 things:
1) What happens with the "Click" event handler instead of "Command" handler
2) What happens if you make the handler public instead of protected.
Sep 7 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
10801
by: simon | last post by:
On code behind file: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then Dim ctrl As New LinkButton ctrl.ID = "link1" ctrl.Text = "link create" ctrl.CommandArgument = "myargument"
1
2590
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows LinkButton myLB = new LinkButton(); ......... .........
1
3325
by: Karthick Kumar | last post by:
Hi, I have the following code which displays all the images from a specific folder with a Radio button in it: Dim objFile i = 1 For Each objFile In objFolder.Files If (i = 1) Then Response.Write("<TR>")
0
950
by: Nathan Sokalski | last post by:
I am making a webform that allows the user to add another textbox by clicking a button to allow them to enter however many names they need. The procedure that does this uses information entered in the currently existing textboxes. This works fine the first time they click the button, since the first textbox is hardcoded. However, the second time they click the button I recieve an error saying: ...
2
5051
by: showens | last post by:
I have a table that has rows appended dynamically, based on the item selected from a dropdownlist. The rows have a number of cells, one with a literal control using the text of the dropdownlist, several checkboxes, and a button. I am trying to use the button to delete the newly-added row if it was added by mistake. The row with its checkboxes, label and button gets added to the table, but the onclick event doesn't fire. Here's the...
0
2412
by: prashantnurvi | last post by:
I have programaticaaly created several Link Buttons on my ASPX page, I would like to raise the Click event of these Link buttons, passing in appropriate parameters depending on the Link button I click. Below is the code I have written to create the Link Buttons For i as integer = 0 to 10 Dim lnkbtn as new linkbutton lnkbtn.ID = lnkbtn&i.tostring() lnkbtn.Text = Test&i.tostring(() me.controls.add(lnkbtn) Next Since the Link buttons...
3
8527
by: Mark | last post by:
Assume you want to dynamically add one to many link button controls to a web page dynamically at run time. Each link button needs to post back and execute code. As the link buttons are created at run time and the number may vary, we can't statically tie to the event to a control. I'm assuming I need to dynamically add event handlers at run time, and that one method could act as the event handler, with unique event args being created for...
5
6763
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created link buttons to stay wired up to their click events. I have what is basically a simply survey question generation page. The page first displays a few static fields and a dropdownlist of various options for the user to select. When the user...
10
2584
by: Jess | last post by:
Hello, If I create a temporary object using a dynamically created object's pointer, then when the temporary object is destroyed, will the dynamically created object be destroyed too? My guess is that it's not destroyed, but I'm not sure. I have the following program: #include<iostream>
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.