Default2.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:6k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.IO;
- public partial class web_pos_c_Default2 : System.Web.UI.Page
- {
- string StrFilePath = "~/web/oa_upload";
- protected void Page_Load(object sender, EventArgs e)
- {
- int flag = 0;
- Button3.Attributes.Add("onclick","return confirm('確定要刪除該文件嗎?')");
- string filePath = Server.MapPath(StrFilePath);
- if (Directory.Exists(filePath))
- {
- DirectoryInfo[] arrfile = new DirectoryInfo(filePath).GetDirectories();
- foreach (DirectoryInfo s in arrfile)
- {
- flag = 0;
- for (int i = 0; i < DropDownList1.Items.Count;i++ )
- {
- if (s.Name.Equals(Convert.ToString(DropDownList1.Items[i].Text)))
- {
- flag = flag + 1;
- }
- }
- if (flag == 0)
- {
- DropDownList1.Items.Add(s.Name);
- }
- }
- }
- string str = StrFilePath + "/" + DropDownList1.Text;
- InitFolderInfo(str);
- }
- private void InitFolderInfo(string s)
- {
- int count = 0;
- //将虚拟路径转换为物理路径
- string strFilePath = Server.MapPath(s);
- //声明文件夹已经使用的容量
- double iFolderCurrentSize = 0;
- //获取文件夹中的所有文件
- FileInfo[] arrFiles = new DirectoryInfo(strFilePath).GetFiles();
- //循环文件获已经使用的容量
- foreach (FileInfo fi in arrFiles)
- {
- iFolderCurrentSize += Convert.ToInt32(fi.Length / 1024);
- count = count + 1;
- }
- //把文件夹容量和以用文件夹容量赋值给标签
- lbl_FolderInfo.Text = string.Format("文件夹文件数目:{0}个,已用容量:{1}KB", count, iFolderCurrentSize);
- }
- protected void ShowMessageBox(string strMessage)
- {
- Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
- }
- protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
- {
- TextBox1.Text = "";
- ListBox1.Items.Clear();
- string str = StrFilePath + "/" + DropDownList1.Text;
- string filePath = Server.MapPath(StrFilePath + "/" + DropDownList1.Text);
- if (Directory.Exists(filePath))
- {
- FileInfo[] arrfile = new DirectoryInfo(filePath).GetFiles();
- foreach (FileInfo s in arrfile)
- {
- ListBox1.Items.Add(s.Name);
- }
- }
- InitFolderInfo(str);
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- string filepath = StrFilePath + "/" + DropDownList1.Text;
- string filename = ListBox1.SelectedValue;
- string fullfilename = Server.MapPath(filepath + "/") + filename;
- FileInfo DowloadFile = new FileInfo(fullfilename);
- Response.Clear();
- Response.ClearHeaders();
- Response.Buffer = false;
- Response.ContentType = "application/octet-stream";
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DowloadFile.FullName, System.Text.Encoding.UTF8));
- Response.AppendHeader("Content-Length", DowloadFile.Length.ToString());
- Response.WriteFile(DowloadFile.FullName);
- Response.Flush();
- Response.End();
- }
- protected void Button3_Click(object sender, EventArgs e)
- {
- string filepath = StrFilePath + "/" + DropDownList1.Text;
- string filename = ListBox1.SelectedValue;
- string strFilePhysicalPath = Server.MapPath(filepath + "/") + filename;
- File.Delete(strFilePhysicalPath);
- ListBox1.Items.Remove(ListBox1.Items.FindByText(filename));
- InitFolderInfo(filepath);
- TextBox1.Text = "";
- ShowMessageBox("删除成功!");
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- string filepath = StrFilePath + "/" + DropDownList1.Text;
- string filename = ListBox1.SelectedValue;
- string filenewname = TextBox1.Text;
- string FilePhysicalPath = Server.MapPath(filepath + "/") + filename;
- string FileNewPhysicalPath = Server.MapPath(filepath + "/") + filenewname;
- File.Move(FilePhysicalPath, FileNewPhysicalPath);
- ListItem li = ListBox1.Items.FindByText(filename);
- li.Text = filenewname;
- li.Value = filenewname;
- ShowMessageBox("文件覆盖成功!");
- }
- #region 列表框事件 ListBox1_SelectedIndexChanged()
- protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (!DropDownList1.Text.Equals(""))
- {
- string filepath = StrFilePath + "/" + DropDownList1.Text;
- string filename = ListBox1.SelectedValue;
- string FilePhysicalPath = Server.MapPath(filepath + "/") + filename;
- //根据物理路径实例化文件信息类
- if (!filename.Equals(""))
- {
- FileInfo fi = new FileInfo(FilePhysicalPath);
- //或得文件大小和创建日期赋值给标签
- lbl_FileDescription.Text = string.Format("文件大小:{0}字节<br><br>上传时间:{1}<br>", fi.Length, fi.CreationTime);
- //把文件名赋值给重命名文件框
- TextBox1.Text = filename;
- }
- }
- }
- #endregion
- }