473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Link Button C# - ASP.NET

davito
1
HI ive been having problems creating a link button in c# that starts a downlaod of the selected file from my upload folder, my delete button works and deletes whats selected. this is my code.
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.IO;
  12. using System.Text;
  13.  
  14. public partial class ViewFiles : System.Web.UI.Page
  15. {
  16.     private string ftpDirectory;
  17.  
  18.     protected void Page_Load(object sender, EventArgs e)
  19.     {
  20.         ftpDirectory = "C:/ADPT/David/Homework";
  21.         if (!this.IsPostBack)
  22.         {
  23.             CreateFileList();
  24.         }
  25.     }
  26.  
  27.     private void CreateFileList()
  28.     {
  29.         // Retrieve the list of files, and display it in the page.
  30.         // This code also disables the delete button, ensuring the
  31.         // user must view the file information before deleting it.
  32.         try
  33.         {
  34.             string[] fileList = Directory.GetFiles(ftpDirectory);
  35.             lstFiles.DataSource = fileList;
  36.             lstFiles.DataBind();
  37.             lblFileInfo.Text = "";
  38.         }
  39.         catch (Exception err)
  40.         {
  41.             lblFileInfo.Text = err.Message;
  42.         }
  43.         cmdDelete.Enabled = true;
  44.     }
  45.  
  46.     protected void cmdRefresh_Click(object sender, EventArgs e)
  47.     {
  48.         CreateFileList();
  49.     }
  50.     protected void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
  51.     {
  52.         // Display the selected file information.
  53.         // Use the StringBuilder for the fastest way to build the string
  54.         // that will be displayed.
  55.         try
  56.         {
  57.             StringBuilder displayText = new StringBuilder();
  58.             string fileName = lstFiles.SelectedItem.Text;
  59.             displayText.Append("<b>");
  60.             displayText.Append(fileName);
  61.             displayText.Append("</b><br /><br />");
  62.             displayText.Append("Created: ");
  63.             displayText.Append(File.GetCreationTime(fileName).ToString());
  64.             displayText.Append("<br />Last Accessed: ");
  65.             displayText.Append(File.GetLastAccessTime(fileName).ToString());
  66.             displayText.Append("<br />");
  67.  
  68.             // Show attribute information. GetAttributes() can return a combination
  69.             // of enumerated values, so you need to evaluate it with the
  70.             // bitwise and (&) operator.
  71.             FileAttributes attributes = File.GetAttributes(fileName);
  72.             if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
  73.             {
  74.                 displayText.Append("This is a hidden file.<br />");
  75.             }
  76.             if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
  77.             {
  78.                 displayText.Append("This is a read-only file.<br />");
  79.                 cmdDelete.Enabled = true;
  80.             }
  81.             else
  82.             {
  83.                 cmdDelete.Enabled = true;
  84.             }
  85.  
  86.             // Show the generated text in a label.
  87.             lblFileInfo.Text = displayText.ToString();
  88.         }
  89.         catch (Exception err)
  90.         {
  91.             lblFileInfo.Text = err.Message;
  92.             cmdDelete.Enabled = true;
  93.         }
  94.     }
  95.  
  96.  
  97.     protected void cmdDelete_Click(object  sender, EventArgs e)
  98.     {
  99.  
  100.         {
  101.             File.Delete(lstFiles.SelectedItem.Text);
  102.             CreateFileList();
  103.         }
  104.  
  105.  
  106.     }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.     protected void LinkButton1_Click(object sender, EventArgs e)
  113.     {
  114.         ResolveClientUrl(lstFiles.SelectedItem.Text);
  115.  
  116.     }
  117.  
  118.  
  119. }
Mar 21 '08 #1
0 1195

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

Similar topics

3
by: Steve | last post by:
Hi, I have a nice little script that works well displaying images on my website. It's a script where if you clik a thumbnail image a pop up window opens that contains a larger version of the same...
0
by: Dailan | last post by:
Hi, I create a tree view. Each node has link button associate with it, which includes add, edit, delete buttons. The way I did is for users who have very low capablity of using computer. Now I...
4
by: Miguel Dias Moura | last post by:
Hello, I created a datalist in an ASP.Net / VB page. I display the image and price of a few products. When a user clicks an image I want to load the page "detail.aspx?number=id" and send the...
2
by: mick79 | last post by:
hello, here's my problem, I'm using navigationbuttons in html code with the tag <button> in order to use them as a link to a new website I should use Java. I've succeeded in making the link work...
5
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...
2
by: wpollans | last post by:
Hello, I need to able to write JS that will click on a link with the middle mouse button - so that the link target will open in a new window or tab - using firefox. Or is there a better (more...
7
by: Steve Swift | last post by:
How close can you get to making a submit button look like a link? Answers to the inevitable questions: 1. Because I don't want my email address (which would have to be part of the URL in a...
3
by: =?Utf-8?B?UGxhdGVyaW90?= | last post by:
I have link buttons in a Gridview that, depending on the value in another column (Not the Key column) will need to be disabled. For example, (Column2 has link buttons) Column1 ...
6
by: liketofindoutwhy | last post by:
There is a link that encloses a span (or a div), but the link won't work in IE 7 (clicking on video image works, but not on the play button), while it works well in Firefox 2 and 3, and Safari 3....
0
by: Ty | last post by:
I have a page that has three gridviews on it. In each gridview the first column is a link button representing a Database ID field. What I'm trying to accomplish is to email that page and click on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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,...
0
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...

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.