遍历文件夹所有文件!



None.gif < asp:GridView ID = " GridView1 "  runat = " server "  Width = " 632px "  AutoGenerateColumns = " False " >
None.gif            
< Columns >
None.gif                
< asp:TemplateField HeaderText = " 文件名 " >
None.gif                    
< ItemTemplate >
None.gif                        
< a href = ' <%#Eval("FileShowPath") %> '  target = " _blank " ><% #Eval( " FileName " %></ a >
None.gif                    
</ ItemTemplate >
None.gif                
</ asp:TemplateField >
None.gif                
< asp:TemplateField HeaderText = " 文件类型 " >
None.gif                     
< ItemTemplate >
None.gif                        
<% #Eval( " FileType " %>
None.gif                    
</ ItemTemplate >
None.gif                
</ asp:TemplateField >
None.gif                
< asp:TemplateField HeaderText = " 文件大小 " >
None.gif                     
< ItemTemplate >
None.gif                        
<% #Eval( " FileSize " %>
None.gif                    
</ ItemTemplate >
None.gif                
</ asp:TemplateField >
None.gif                
< asp:TemplateField HeaderText = " 文件修改时间 " >
None.gif                     
< ItemTemplate >
None.gif                        
<% #Eval( " FileLastWrite " %>
None.gif                     
</ ItemTemplate >
None.gif                
</ asp:TemplateField >
None.gif            
</ Columns >
None.gif        
</ asp:GridView >


None.gif public   class  AppCom
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public AppCom()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//
InBlock.gif        
// TODO: 在此处添加构造函数逻辑
InBlock.gif        
//
ExpandedSubBlockEnd.gif
    }

InBlock.gif    
private string fileName;
InBlock.gif
InBlock.gif    
public string FileName
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn fileName; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ fileName = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif    
private string fileType;
InBlock.gif
InBlock.gif    
public string FileType
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn fileType; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ fileType=value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif    
private string fileSize;
InBlock.gif
InBlock.gif    
public string FileSize
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn fileSize; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ fileSize = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif    
private string fileLastWrite;
InBlock.gif    
public string FileLastWrite
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn fileLastWrite; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ fileLastWrite = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif    
private string fileShowPath;
InBlock.gif    
public string FileShowPath
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn fileShowPath; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ fileShowPath = value; }
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Configuration;
None.gif
using  System.Collections;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.IO;
None.gif
using  System.Collections.Generic;
None.gif
using  System.Text.RegularExpressions;
None.gif
public   partial   class  UploadFileManage : System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (!IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.GridView1.DataSource = bindGridView();
InBlock.gif            
this.GridView1.DataBind();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
private List<AppCom> bindGridView()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
string strPath = Server.MapPath(@"~/Images/");
InBlock.gif        
string showPath = AppDomain.CurrentDomain.BaseDirectory.Substring(0,AppDomain.CurrentDomain.BaseDirectory.Length-1);
InBlock.gif        showPath
=showPath.Substring(showPath.LastIndexOf("\\")+1);
InBlock.gif        showPath 
= @"http://" + Request.Url.Authority + "/"+showPath + "/Images/";
InBlock.gif        
//string showPath = Request.Url.AbsoluteUri.Substring(0, 31) + "/Images/"+Request.Url.Authority;
InBlock.gif        
//string showPath = Page.Request.PhysicalApplicationPath + "Images\\";
InBlock.gif
        List<AppCom> fileList = new List<AppCom>();
InBlock.gif        DirectoryInfo di 
= new DirectoryInfo(strPath);
InBlock.gif        FileInfo[] files;
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            files 
= di.GetFiles();
InBlock.gif            
foreach (FileInfo fi in files)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                AppCom ac 
= new AppCom();
InBlock.gif                ac.FileName 
= fi.Name;
InBlock.gif                ac.FileSize 
= Convert.ToString(fi.Length);
InBlock.gif                ac.FileType 
= fi.Extension;
InBlock.gif                ac.FileLastWrite 
= fi.LastWriteTime.ToString();
InBlock.gif                ac.FileShowPath 
= showPath + fi.Name;
InBlock.gif                fileList.Add(ac);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return fileList;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch (Exception)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
throw;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//string fileName = this.GridView1.DataKeys[e.RowIndex].Values[0].ToString();
InBlock.gif       
// string fileName = this.GridView1.Rows[e.RowIndex].Cells[0].Text+this.GridView1.Rows[e.RowIndex].Cells[1].Text;
InBlock.gif
        string fileName = ((DataBoundLiteralControl)(this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.Trim();
InBlock.gif        Match m 
= Regex.Match(fileName, @"(?<=<a[^>]*>)[\s\S]+?(?=</a>)", RegexOptions.IgnoreCase);
InBlock.gif        
if (m.Success)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            fileName 
= m.Value;
ExpandedSubBlockEnd.gif        }

InBlock.gif        File.Delete(Server.MapPath(
@"~/Images/"+ fileName);
InBlock.gif        
this.GridView1.DataSource = bindGridView();
InBlock.gif        
this.GridView1.DataBind();
InBlock.gif        
//List<AppCom> la = new List<AppCom>();
InBlock.gif
        
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/xiazhi33/articles/1119925.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值