Asp.Net Klasördeki Dosyaları Listeleme

Asp.net ile bir klasörün içindeki dosyaların listesini öğrenebiliriz bunun için tasarım alanında form üzerine bir listbox, bir buton , bir textbox ve iki label ekliyoruz tasarım için gerekli kodlarımız..

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="klasordekidosyalar.aspx.cs" Inherits="dosyaveklasorislemleri.klasordekidosyalar" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2 style="color:Navy">asp.net örnekleri: Klasördeki dosyaların listesi</h2>  
        <asp:ListBox  ID="ListBox1"   
             runat="server"  BackColor="Teal"  ForeColor="Snow"   >  
        </asp:ListBox>  
        <br /><br />  
        <asp:Label    ID="Label1"  runat="server"   
            Text="Klasör"   ForeColor="DarkGreen"  Font-Bold="true" >  
        </asp:Label>  
        <asp:TextBox   ID="TextBox1"   runat="server"  ReadOnly="true"   BackColor="DarkGreen"  
             ForeColor="Ivory"  >  
        </asp:TextBox>  
        <br /><br />  
        <asp:Button   ID="Button1"   runat="server"  Font-Bold="true"   
            ForeColor="DarkBlue"  Text="Klasördeki Dosyaları Göster"  OnClick="Button1_Click"   />  
    </div>
    </form>
</body>
</html>

klasordekidosya
Butona basdığımız zaman klasördeki dosyaları listbox içerisine alacağız dosyalar üzerinde işlem yapabilmek için System.IO namespace’ini ekliyoruz klasördeki dosyaları alabilmek için Directory.GetFiles komutunu kullanacağız kodlarımız aşağıda..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;


namespace dosyaveklasorislemleri
{
    public partial class klasordekidosyalar : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string klasoryolu = Request.PhysicalApplicationPath;
            TextBox1.Text = klasoryolu; 
        }
        protected void Button1_Click(object sender, System.EventArgs e)
        {
            string klasorum = TextBox1.Text.ToString();
            string[] klasordekiler = Directory.GetFiles(klasorum);
            ListBox1.DataSource = klasordekiler;
            ListBox1.DataBind();
            ListBox1.Height = 250;
        }  
    }
}

You may also like...

Subscribe
Bildir
guest
1 Yorum
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ömer

teşekkürler paylaşım için peki bu klasördeki resimleri nasıl sildirebiliriz?

1
0
Yazı hakkındaki yorum, görüş ve önerilerinizi yazınx
()
x