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. jsp 分页, 判断是第一页,和最后一页.

    <% //页的行数 int pagesize =20; //当前页 int currentPage = 1; try { currentPage = Integer.parseInt(reque ...

  2. (学习笔记)HTML的&lt;link&gt;标签

    在HTML中<link>标签用于定义文档与外部资源的关系. <link>标签只存在于head部分. <head> <link rel="styles ...

  3. android: UriMatcher的用法

    ContentProvider是Android四大组件之一,网上也有不少关于它的文章,基本用法都可以查到,但关于UriMatcher在其中的作用,文章中都有例子,但我觉得还没有说清楚. 先说为什么用U ...

  4. POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)

    Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...

  5. linux 学习笔记 GNU工具链简介

    我们通常无法直接通过Linux内核,而需要借助Linux内核之上的GUN工具链来进行 文件处理 文本操作 进程管理 等操作. GNU/Linux shell为用户提供了 启动程序 管理文件系统上的文件 ...

  6. android jsonarray

    Json数组是子元素的有序集合,每个子元素都有一个下标,可以根据下标操纵Json数组的子元素.类JsonArray是bantouyan-json库对Json数组的抽象,提供操纵Json数组的各种方法. ...

  7. 《算法导论》Problem 2-4 Inversions

    在Merge Sort的基础上改改就好了. public class Inversions { public static int inversions(int [] A,int p, int r) ...

  8. Vue项目搭建完整剖析全过程

    Vue项目搭建完整剖析全过程 项目源码地址:https://github.com/ballyalex 有帮助的话就加个星星呗~!  项目技术栈:vue+webpack+bower+sass+axios ...

  9. CodeForces 97 E. Leaders(点双连通分量 + 倍增)

    题意 给你一个有 \(n\) 个点 \(m\) 条边的无向图,有 \(q\) 次询问,每次询问两个点 \(u, v\) 之间是否存在长度为奇数的简单路径. \(1 \le n, m, q \le 10 ...

  10. 神州数码OSPF基于端口认证(简单认证、MD5认证)

    实验要求:掌握OSPF基于端口认证方式 拓扑如下 简单认证 R1 enable 进入特权模式 config  进入全局模式 hostname R1 修改名称 interface s0/1 进入端口 i ...