wjgl.aspx.cs:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using DBUtility; namespace qhsy.DWJSC
{
public partial class wjgl : System.Web.UI.Page
{ protected string File_List = ""; protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{ if (Request.UrlReferrer.ToString().Contains("wjsc.aspx")==false)
{
//保存上一页的url传递到wjsc.aspx
HttpCookie cookie = new HttpCookie("back");
cookie.Values.Add("url", Request.UrlReferrer.ToString());
Response.AppendCookie(cookie);
} lb_title.Text = "文 件 管 理"; //是否查询
string sfcx = Request.QueryString["sfcx"];
if (sfcx == "")
{
//gridFileList.Columns[0].Visible = false;
bg.Visible = false; } ////是否图片
//string sftp = Request.QueryString["sftp"];
//if (sftp == "1")
//{
// //GridView中添加图片缩略图
// gridFileList.Columns[2].Visible = true;
//} //操作模块id,参数
ViewState["shmkid"] = Request.QueryString["shmkid"];
//路径信息 fj = "~/File/JYWJ/8910427356/5209168734/";
ViewState["fj"] = Request.QueryString["fj"]; string path = string.Format("{0}", (string)ViewState["fj"]);
path = Server.MapPath(path);
ixExit(path); //设定初始排序字段为文件修改时间FileLastWriteTime
gridFileList.Attributes.Add("SortExpression", "FileLastWriteTime");
gridFileList.Attributes.Add("SortDirection", "DESC");
BindGrid(); } } //绝对路径(目录)是否存在,不存在则创建
private void ixExit(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
} } //读取本地文件绑定到GridViewRow
protected void gridFileList_RowDataBound(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
Image Img = (Image)e.Row.Cells[].FindControl("ImgPath");
Img.ImageUrl = e.Row.Cells[].Text;
e.Row.Cells[].Text = ""; }
DataClass.Comm.gv_hbs(sender, e);
} //分页
protected void gridFileList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridFileList.PageIndex = e.NewPageIndex;
this.BindGrid();
} //绑定gridview
private void BindGrid()
{
//获取数据源
DataTable dtb = FileDataTable(); //排序
string SortDirection = gridFileList.Attributes["SortDirection"].ToString();
string SortExpression = gridFileList.Attributes["SortExpression"].ToString();
dtb.DefaultView.Sort = string.Format("{0} {1}", SortExpression, SortDirection); //赋数据源并绑定
gridFileList.DataSource = dtb;
gridFileList.DataBind();
gridFileList.Visible = gridFileList.Rows.Count > ;
gridFileList.Attributes.Add("BorderColor", "#000000"); } private DataTable FileDataTable()
{
string fj = (string)ViewState["fj"];
string path = Server.MapPath(fj);
GetFiles(path); //构造DataTABLE
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("FilePath", typeof(string)));
dt.Columns.Add(new DataColumn("FileName", typeof(string)));
dt.Columns.Add(new DataColumn("FileLength", typeof(string)));
dt.Columns.Add(new DataColumn("FileLastWriteTime", typeof(string)));
DataRow dr; //将文件数组集合切割到数组 string[] dtaArry = File_List.Split(','); for (int i = ; i < dtaArry.Length; i++)
{ if (dtaArry[i].Trim() != "")//判断是否为空
{ dr = dt.NewRow();
dr[] = dtaArry[i];//文件路径
dr[] = Path.GetFileName(dtaArry[i]);//文件名 //获取文件大小(Decimal.Round(Convert.ToDecimal(FI.Length), 2) string FIer = dtaArry[i].ToString();
FileInfo FI = new FileInfo(FIer);
dr[] = Convert.ToString(Decimal.Round(Convert.ToDecimal(FI.Length / ), )) + "KB";//获取的是字节byte,还需要转换为千字节KB dr[] = FI.LastWriteTime;
dt.Rows.Add(dr); } } return dt; } //遍文件夹下的所有子文件夹下的文件
public void GetFiles(string ObjDirPath)
{
DirectoryInfo SourceDir = new DirectoryInfo(ObjDirPath);
foreach (FileSystemInfo FSI in SourceDir.GetFileSystemInfos())
{ if (FSI is DirectoryInfo)
{ //如果是文件夹则递归
GetFiles(FSI.FullName);
} else
{
string FilePath = "";
FilePath = FSI.FullName.ToLower(); string fj = (string)ViewState["fj"];
string mc = fj.Substring(, ); //FilePath = FilePath.Substring(FilePath.LastIndexOf(mc));
File_List += FilePath + ","; } } } //排序
protected void gridFileList_Sorting(object sender, GridViewSortEventArgs e)
{ string sortExpression = e.SortExpression.ToString();
string sortdirection = "ASC"; if (sortExpression == gridFileList.Attributes["SortExpression"])
{ sortdirection = (gridFileList.Attributes["SortDirection"].ToString() == sortdirection ? "DESC" : "ASC"); } gridFileList.Attributes["SortExpression"] = sortExpression;
gridFileList.Attributes["SortDirection"] = sortdirection;
this.BindGrid(); } protected void btnDel_Click(object sender, EventArgs e)
{
try
{ FileInfo fileinfo;
bool IsSelect = false; for (int i = ; i < gridFileList.Rows.Count; i++)
{ GridViewRow row = gridFileList.Rows[i]; if (((CheckBox)row.FindControl("chkDel")).Checked)
{ IsSelect = true;
Image Img = (Image)gridFileList.Rows[i].Cells[].FindControl("ImgPath");
fileinfo = new FileInfo(Img.ImageUrl);
if (fileinfo.Exists)
{
fileinfo.Delete();
//根据ccid删除表jy_wj_wjccb中的数据
string str = string.Format("delete from jy_wj_wjccb where fj='{0}'", Img.ImageUrl.Substring(, Img.ImageUrl.Length-));
DbHelperSQL.Query(str);
}
}
}
if (IsSelect)
{
DataClass.Comm.Alert(Page, "删除成功!"); }
else
{ DataClass.Comm.Alert(Page, "请选择要删除的行!"); }
}
catch (Exception ex)
{
//DataClass.Comm.Alert(Page, ex.ToString());
} BindGrid();
} protected void btnAdd_Click(object sender, EventArgs e)
{ string s = string.Format("~/DWJSC/wjsc.aspx?shmkid={0}&&fj={1}&&sfcg={2}",(string)ViewState["shmkid"], (string)ViewState["fj"], );
Response.Redirect(s); } protected void btBack_Click(object sender, EventArgs e)
{ Response.Redirect((Request.Cookies["back"].Values["url"]).ToString()); //清空Cookies["back"]
Response.Cookies["back"].Expires = DateTime.Now.AddDays(-); } }
}

wjgl.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="wjgl.aspx.cs" Inherits="qhsy.DWJSC.wjgl" %>

<!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 id="Head1" runat="server">
<title>文件管理</title>
<link href="../COMM/CSS/CSS.css" rel="stylesheet" type="text/css" />
<style type="text/css"> #wjgl
{
background:#F2FBE5; text-align:center; vertical-align:middle;
width:%;
height: 714px;
}
#div
{
height: 701px;
}
</style>
<script type="text/javascript">
function SelAllClick() {
var isSelAll = document.getElementById("gridFileList_ctl01_CheckAll").checked;
for (var i = ; i < ; i++) {
if (i < ) checkBoxId = "gridFileList_ctl0" + i + "_chkDel";
else checkBoxId = "gridFileList_ctl" + i + "_chkDel";
var checkBoxObj = document.getElementById(checkBoxId);
if (checkBoxObj == undefined || checkBoxObj == null) break;
checkBoxObj.checked = isSelAll;
}
}
</script>
</head> <body class="body">
<form id="form1" runat="server">
<div id="div" class="div"> <div id="wjgl"> <table width="100%"> <tr> <td> <div class="divtitle" >
<asp:Panel ID="Panel4" CssClass="pan" runat="server" >
<asp:Label ID="lb_title" runat="server" CssClass="lab" Text=""></asp:Label>
</asp:Panel>
</div> </td> </tr> <tr> <td> <asp:GridView runat="server" ID="gridFileList"
Width="100%" HeaderStyle-Height="" OnRowDataBound="gridFileList_RowDataBound" AllowPaging="True" PageSize="" OnPageIndexChanging="gridFileList_PageIndexChanging" onsorting="gridFileList_Sorting" BorderStyle="None"
AutoGenerateColumns="false" > <Columns> <asp:TemplateField ItemStyle-CssClass="divcheck" > <ItemStyle HorizontalAlign="Center" /> <HeaderTemplate>&nbsp;<input id="CheckAll" type="checkbox" onclick="SelAllClick();" runat="server"/></HeaderTemplate> <ItemTemplate> <asp:CheckBox runat="server" ID="chkDel" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="序号" InsertVisible="False"> <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# this.gridFileList.PageIndex * this.gridFileList.PageSize + this.gridFileList.Rows.Count + 1%>'/> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="图片" Visible="false" InsertVisible="False" > <ItemStyle HorizontalAlign="Center" /> <ItemTemplate> <asp:Image ID="ImgPath" runat="server" Width="" Height="" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="FileName" HeaderText="名称" SortExpression="FileName" > <ItemStyle HorizontalAlign="Center" /> </asp:BoundField> <asp:BoundField DataField="FileLength" HeaderText="大小" SortExpression="FileLength" > <ItemStyle HorizontalAlign="Center" /> </asp:BoundField> <asp:BoundField DataField="FilePath" SortExpression="FilePath"> <ItemStyle HorizontalAlign="Center" /> </asp:BoundField> <asp:BoundField DataField="FileLastWriteTime" HeaderText="修改时间" SortExpression="FileLastWriteTime" > <ItemStyle HorizontalAlign="Center" /> </asp:BoundField> </Columns> </asp:GridView> </td> </tr> <tr id="bg" runat="server">
<td align="center" class="sub_bg">
<asp:Button runat="server" ID="btnAdd" Text="添加文件" OnClick="btnAdd_Click" style="height: 26px" />&nbsp;
<asp:Button runat="server" ID="btnDel" Text="删除文件" OnClick="btnDel_Click" OnClientClick="return confirm('提示:确定要删除吗?');" />
&nbsp; <asp:Button ID="btBack" runat="server" Text="返回上一页" onclick="btBack_Click" /> </td>
</tr>
</table> </div>
</div>
</form>
</body>
</html>

.NET 读取本地文件绑定到GridViewRow的更多相关文章

  1. 【转】flash air中读取本地文件的三种方法

    actionscript中读取本地文件操作有两种代码如下 1.使用File和FileStream两个类,FileStream负责读取数据的所以操作:(同步操作) var stream:FileStre ...

  2. 前台JS(type=‘file’)读取本地文件的内容,兼容各种浏览器

    [自己测了下,能兼容各种浏览器,但是读取中文会出现乱码.自己的解决方法是用notepad++把txt文件编码改为utf-8(应该是和浏览器编码保持一致吧?..)] 原文  http://blog.cs ...

  3. 手工创建tomcat应用,以及实现js读取本地文件内容

    手工创建tomcat应用: 1.在webapps下面新建应用目录文件夹 2.在文件夹下创建或是从其他应用中复制:META-INF,WEB-INF这两个文件夹, 其中META-INF清空里面,WEB-I ...

  4. H5读取本地文件操作

    H5读取本地文件操作 本文转自:转:http://hushicai.com/2014/03/29/html5-du-qu-ben-di-wen-jian.html感谢大神分享. 常见的语言比如php. ...

  5. python 读取本地文件批量插入mysql

    Uin_phone.txt 本地文件内容 有1000条,这里只是展示前几条,供参考 133584752 133584759 133584764 133584773 133584775 13358477 ...

  6. FileReader读取本地文件

    FileReader是一种异步读取文件机制,结合input:file可以很方便的读取本地文件. 一.input:type[file] file类型的input会渲染为一个按钮和一段文字.点击按钮可打开 ...

  7. spark读取本地文件

    /** * Read a text file from HDFS, a local file system (available on all nodes), or any * Hadoop-supp ...

  8. 让Chrome支持Ajax/$http方式读取本地文件

    在开发中经常写些小demo调试一下插件什么的 数据源又经常手动构造分离为一个单独的文件.用ajax或$http去访问时总是拒绝访问.这个时候可以给Chrome的快捷图标加启动参数,让浏览器允许js访问 ...

  9. android红米等关于读取本地文件夹图片获取路径的问题的解决

    在Android开发中,有从本地文件夹中读取图片的功能,使用一下代码打开图片选择列表: Intent intent = new Intent();   intent.setAction(Intent. ...

随机推荐

  1. mac 快捷键拾遗

    1.隐藏所有其它窗口 (hide) 窗口太多太乱,按下Command+Option/alt+H组合键,除了当前窗口以外的其它窗口会自动隐藏(不是缩小). 2. Command X        留意, ...

  2. Linux搭建Nginx

    1.Nginx安装 1.1 pcre (1)下载编译包 http://www.pcre.org/ (注意需要的是pcce,而非pcre2) (2)tar -zxvf pcre-8.36.tar.gz  ...

  3. C++程序设计基础

    01 1 预编译常用的有,宏定义和包含库.2 库:是实用工具的集和,由程序员编写,可以完成一些特定的功能.3 <> 系统库 ""用户自定义库.4 宏定义:定义符号常量, ...

  4. [Python] from scipy import sparse 报 DLL load failed:找不到指定模块错误

    依赖vc运行环境.需要安装 vc_redist Py3.5要安装2015版 传送门: https://www.microsoft.com/zh-CN/download/details.aspx?id= ...

  5. poi2015 bzoj4377-4386训练

    就按时间顺序写吧 完成度:10/10 3.30 bzoj4385 首先一定是删去连续d个数,然后枚举终点,起点显然有单调性,用单调队列乱搞搞就可以啦 bzoj4378 首先才结论:可行当且仅当把所有大 ...

  6. C语言 活动安排问题之二

    有若干个活动,第i个开始时间和结束时间是[Si,fi),活动之间不能交叠,要把活动都安排完,至少需要几个教室? #include <stdio.h> #include <string ...

  7. powershell批量设置权限

    批量设置权限 $acl=get-acl .\demo Get-ChildItem .\Documents -Recurse -Force|Set-Acl -AclObject $acl

  8. 得到 window.open 新页面中的数据

    1.htm 页面 单击按  '钮后'  调用window.open方法,开启新窗口  2.htm 想实现---------------------- 在2.htm页面单击按钮 将相应的数据返回到 1. ...

  9. ExecutorService线程池

    ExecutorService 建立多线程的步骤: 1.定义线程类 class Handler implements Runnable{} 2.建立ExecutorService线程池 Executo ...

  10. il c井

    base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 将resource 替换成 fileComplier 生成的 resx(可以 ...