.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

view file info

Posted By:papsantony       Posted Date: August 13, 2010    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

view file info
 

<%@ Page language="c#" src="ViewFiles.aspx.cs" AutoEventWireup="false" Inherits="ViewFiles" %>
<HTML>
  <body>
    <form id="Form1" method="post" runat="server">
      "Label1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server" Font-Names="Verdana" Font-Bold="True">Files in the FTP Directory:
      "lstFiles" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 56px" runat="server" Width="256px" Height="264px" AutoPostBack="True" Font-Names="Verdana">
      "cmdRefresh" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 328px" runat="server" Width="72px" Height="32px" Text="Refresh">
      "Label2" style="Z-INDEX: 104; LEFT: 296px; POSITION: absolute; TOP: 24px" runat="server" Width="248px" Height="24px" Font-Names="Verdana" Font-Bold="True">Selected File Information:
      "lblFileInfo" style="Z-INDEX: 105; LEFT: 296px; POSITION: absolute; TOP: 56px" runat="server" Width="312px" Height="264px" BorderStyle="Groove" BorderWidth="2px" Font-Names="Verdana" Font-Size="X-Small">
      "cmdDelete" style="Z-INDEX: 106; LEFT: 520px; POSITION: absolute; TOP: 328px" runat="server" Width="89px" Height="32px" Text="Delete File">
    form>
  body>
HTML>

<%--
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

  public class ViewFiles : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.ListBox lstFiles;
    protected System.Web.UI.WebControls.Button cmdRefresh;
    protected System.Web.UI.WebControls.Label Label2;
    protected System.Web.UI.WebControls.Label lblFileInfo;
    protected System.Web.UI.WebControls.Button cmdDelete;

    string ftpDirectory = System.Web.HttpContext.Current.Server.MapPath("yourfolderHere");//@"c:\Temp";

    private void Page_Load(object sender, System.EventArgs e)
    {
      if (!this.IsPostBack)
      {
        CreateFileList();
      }
    }

    private void CreateFileList()
    {
      string[] fileList = Directory.GetFiles(ftpDirectory);
      lstFiles.DataSource = fileList;
      lstFiles.DataBind();
      lblFileInfo.Text = "";
      cmdDelete.Enabled = false;
    }


    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      InitializeComponent();
      base.OnInit(e);
    }
    
    private void InitializeComponent()
    {    
      this.lstFiles.SelectedIndexChanged += new System.EventHandler(this.lstFiles_SelectedIndexChanged);
      this.cmdRefresh.Click += new System.EventHandler(this.cmdRefresh_Click);
      this.cmdDelete.Click += new System.EventHandler(this.cmdDelete_Click);
      this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void cmdRefresh_Click(object sender, System.EventArgs e)
    {
          CreateFileList();
    }

    private void cmdDelete_Click(object sender, System.EventArgs e)
    {
    //  File.Delete(lstFiles.SelectedItem.Text);
      //CreateFileList();

    }

    private void lstFiles_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      string fileName = lstFiles.SelectedItem.Text;
      lblFileInfo.Text = "+ fileName + "
"
;
      lblFileInfo.Text += "Created : ";
      lblFileInfo.Text += File.GetCreationTime(fileName).ToString();
      lblFileInfo.Text += "
Last Accessed : "
;
      lblFileInfo.Text += File.GetLastAccessTime(fileName).ToString();
      lblFileInfo.Text += "
"
;

      FileAttributes attributes = File.GetAttributes(fileName);
      if ((attributes & FileAttributes.Hidden== FileAttributes.Hidden)
      {
        lblFileInfo.Text += "This is a hidden file." "
"
;
      }
      if ((attributes & FileAttributes.ReadOnly== FileAttributes.ReadOnly)
      {
        lblFileInfo.Text += "This is a read-only file." "
"
;
      }

      if ((attributes & FileAttributes.ReadOnly!= FileAttributes.ReadOnly)
      {
        cmdDelete.Enabled = true;
      }
      else
      {
        cmdDelete.Enabled = false;
      }

    }
  }



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend