Asp.net源码专业站
首页->上传下载->精美的WEB在线文件管理源码>>Web/Default.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:精美的WEB在线文件管理源码
当前文件:文件类型 WebFileManager/Web/Default.aspx.cs[9K,2009-6-12 11:58:19]打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Collections.Generic; 6using System.Web; 7using System.Web.Security; 8using System.Web.UI; 9using System.Web.UI.WebControls; 10using System.Web.UI.WebControls.WebParts; 11using System.Web.UI.HtmlControls; 12using System.IO; 13using System.Web.Services; 14 15using FileManager; 16 17public partial class _Default : System.Web.UI.Page 18{ 19 protected void Page_Load(object sender, EventArgs e) 20 { 21 if (!IsPostBack) 22 { 23 BindGrid(); 24 } 25 } 26 27 BindGrid() 44 45 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 46 { 47 if (e.Row.RowType == DataControlRowType.DataRow) 48 { 49 LinkButton lb = (LinkButton)e.Row.Cells[1].FindControl("LinkButton1"); 50 if (lb.Text != "[根目录]" && lb.Text != "[上一级]") 51 { 52 if (Directory.Exists(lb.CommandArgument.ToString())) 53 { 54 lb.Text = string.Format("<img src=\"images/file/folder.gif\" style=\"border:none; vertical-align:middle;\" /> {0}", lb.Text); 55 } 56 else 57 { 58 string ext = lb.CommandArgument.ToString().Substring(lb.CommandArgument.LastIndexOf(".") + 1); 59 if (File.Exists(Server.MapPath(string.Format("images/file/{0}.gif", ext)))) 60 { 61 lb.Text = string.Format("<img src=\"images/file/{0}.gif\" style=\"border:none; vertical-align:middle;\" /> {1}", ext, lb.Text); 62 } 63 else 64 { 65 lb.Text = string.Format("<img src=\"images/file/other.gif\" style=\"border:none; vertical-align:middle;\" /> {0}", lb.Text); 66 } 67 } 68 } 69 else 70 { 71 e.Row.Cells[0].Controls.Clear(); 72 } 73 } 74 } 75 76 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 77 { 78 if (Directory.Exists(e.CommandArgument.ToString())) 79 { 80 BindGrid(e.CommandArgument.ToString()); 81 } 82 else 83 { 84 string path = e.CommandArgument.ToString(); 85 path = path.Replace(FileSystemManager.GetRootPath(), "~"); 86 path = path.Replace("\\", "/"); 87 Response.Redirect(path); 88 } 89 } 90 91 /// <summary> 92 /// 删除 93 /// </summary> 94 /// <param name="sender"></param> 95 /// <param name="e"></param> 96 protected void btnDelete_Click(object sender, EventArgs e) 97 { 98 foreach (GridViewRow row in GridView1.Rows) 99 { 100 if (row.RowType == DataControlRowType.DataRow) 101 { 102 CheckBox cb = (CheckBox)row.Cells[0].FindControl("CheckBox1"); 103 if (cb.Checked) 104 { 105 LinkButton lb = (LinkButton)row.Cells[1].FindControl("LinkButton1"); 106 if (Directory.Exists(lb.CommandArgument)) 107 { 108 FileSystemManager.DeleteFolder(lb.CommandArgument); 109 } 110 else 111 { 112 FileSystemManager.DeleteFile(lb.CommandArgument); 113 } 114 } 115 } 116 } 117 BindGrid(lblCurrentPath.Text); 118 } 119 120 /// <summary> 121 /// 新建文件夹 122 /// </summary> 123 /// <param name="sender"></param> 124 /// <param name="e"></param> 125 protected void btnCreateFolder_Click(object sender, EventArgs e) 126 { 127 FileSystemManager.CreateFolder(TextBox2.Text, lblCurrentPath.Text); 128 BindGrid(lblCurrentPath.Text); 129 } 130 131 /// <summary> 132 /// 新建文件 133 /// </summary> 134 /// <param name="sender"></param> 135 /// <param name="e"></param> 136 protected void btnCreateFile_Click(object sender, EventArgs e) 137 { 138 FileSystemManager.CreateFile(TextBox4.Text, lblCurrentPath.Text); 139 BindGrid(lblCurrentPath.Text); 140 } 141 142 /// <summary> 143 /// 上传 144 /// </summary> 145 /// <param name="sender"></param> 146 /// <param name="e"></param> 147 protected void btnUpload_Click(object sender, EventArgs e) 148 { 149 if (FileUpload1.HasFile) 150 { 151 string path = lblCurrentPath.Text + "\\"; 152 path += Path.GetFileName(FileUpload1.FileName); 153 FileUpload1.PostedFile.SaveAs(path); 154 BindGrid(lblCurrentPath.Text); 155 } 156 } 157 158 /// <summary> 159 /// 剪切 160 /// </summary> 161 /// <param name="sender"></param> 162 /// <param name="e"></param> 163 protected void btnCut_Click(object sender, EventArgs e) 164 { 165 List<string> items = new List<string>(); 166 foreach (GridViewRow row in GridView1.Rows) 167 { 168 if (row.RowType == DataControlRowType.DataRow) 169 { 170 CheckBox cb = (CheckBox)row.Cells[0].FindControl("CheckBox1"); 171 if (cb.Checked) 172 { 173 LinkButton lb = (LinkButton)row.Cells[1].FindControl("LinkButton1"); 174 items.Add(lb.CommandArgument); 175 } 176 } 177 } 178 ViewState["clipboard"] = items; 179 ViewState["action"] = "cut"; 180 } 181 182 /// <summary> 183 /// 粘贴 184 /// </summary> 185 /// <param name="sender"></param> 186 /// <param name="e"></param> 187 protected void btnPaste_Click(object sender, EventArgs e) 188 { 189 if (ViewState["clipboard"] != null) 190 { 191 if (ViewState["action"].ToString() == "cut") 192 { 193 List<string> items = (List<string>)ViewState["clipboard"]; 194 foreach (string s in items) 195 { 196 if (Directory.Exists(s)) 197 { 198 Directory.Move(s, lblCurrentPath.Text + s.Substring(s.LastIndexOf("\\"))); 199 } 200 else 201 { 202 File.Move(s, lblCurrentPath.Text + "\\" + Path.GetFileName(s)); 203 } 204 } 205 } 206 else 207 { 208 List<string> items = (List<string>)ViewState["clipboard"]; 209 foreach (string s in items) 210 { 211 if (Directory.Exists(s)) 212 { 213 DirectoryInfo di = new DirectoryInfo(s); 214 FileSystemManager.CopyFolder(s, lblCurrentPath.Text + "\\" + di.Name); 215 } 216 else 217 { 218 File.Copy(s, lblCurrentPath.Text + "\\复件 " + Path.GetFileName(s), true); 219 } 220 } 221 } 222 } 223 ViewState["clipboard"] = null; 224 ViewState["action"] = null; 225 BindGrid(lblCurrentPath.Text); 226 } 227 228 /// <summary> 229 /// 复制 230 /// </summary> 231 /// <param name="sender"></param> 232 /// <param name="e"></param> 233 protected void btnCopy_Click(object sender, EventArgs e) 234 { 235 List<string> items = new List<string>(); 236 foreach (GridViewRow row in GridView1.Rows) 237 { 238 if (row.RowType == DataControlRowType.DataRow) 239 { 240 CheckBox cb = (CheckBox)row.Cells[0].FindControl("CheckBox1"); 241 if (cb.Checked) 242 { 243 LinkButton lb = (LinkButton)row.Cells[1].FindControl("LinkButton1"); 244 items.Add(lb.CommandArgument); 245 } 246 } 247 } 248 ViewState["clipboard"] = items; 249 ViewState["action"] = "copy"; 250 } 251 252 /// <summary> 253 /// 重命名 254 /// </summary> 255 /// <param name="sender"></param> 256 /// <param name="e"></param> 257 protected void btnRename_Click(object sender, EventArgs e) 258 { 259 string src = ""; 260 string dest = ""; 261 foreach (GridViewRow row in GridView1.Rows) 262 { 263 if (row.RowType == DataControlRowType.DataRow) 264 { 265 CheckBox cb = (CheckBox)row.Cells[0].FindControl("CheckBox1"); 266 if (cb.Checked) 267 { 268 LinkButton lb = (LinkButton)row.Cells[1].FindControl("LinkButton1"); 269 src = lb.CommandArgument; 270 } 271 } 272 } 273 if (src.Length > 0) 274 { 275 dest = src.Substring(0, src.LastIndexOf('\\')); 276 dest = dest + "\\" + TextBox3.Text; 277 if (Directory.Exists(src)) 278 { 279 FileSystemManager.MoveFolder(src, dest); 280 } 281 else 282 { 283 FileSystemManager.MoveFile(src, dest); 284 } 285 BindGrid(lblCurrentPath.Text); 286 } 287 } 288}
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:精美的WEB在线文件管理源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146