|
#region 列表框事件 protected void lb_FileList_SelectedIndexChanged(object sender, EventArgs e) { //从config中读取文件上传路径 string strFileUpladPath = ConfigurationManager.AppSettings["FileUplodePath"].ToString(); //从列表框中读取选择的文件名 string strFileName = lb_FileList.SelectedValue; //组合成物理路径 string strFilePhysicalPath = Server.MapPath(strFileUpladPath + "/") + strFileName; //根据物理路径实例化文件信息类 FileInfo fi = new FileInfo(strFilePhysicalPath); //或得文件大小和创建日期赋值给标签 lbl_FileDescription.Text = string.Format("文件大小:{0}字节<br><br>上传时间:{1}<br>", fi.Length, fi.CreationTime); //把文件名赋值给重命名文件框 tb_FileNewName.Text = strFileName; } #endregion #region 下载文件按钮事件 protected void btn_DownLoad_Click(object sender, EventArgs e) { //从web.config读取文件上传路径 string strFileUploadPath = ConfigurationManager.AppSettings["FileUplodePath"].ToLower(); //从列表框中读取选择的文件 string strFileName = lb_FileList.SelectedValue; //组合成物理路径 string FullFileName = Server.MapPath(strFileUploadPath + "/") + strFileName;
FileInfo DownloadFile = new FileInfo(FullFileName); Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.ContentType = "application/octet-stream "; Response.AppendHeader("Content-Disposition ", "attachment;filename= " + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8)); Response.AppendHeader("Content-Length ", DownloadFile.Length.ToString()); Response.WriteFile(DownloadFile.FullName); Response.Flush(); Response.End(); } #endregion #region 删除文件 protected void btn_Delete_Click(object sender, EventArgs e) { //从config中读取文件上传路径 string strFileUpladPath = ConfigurationManager.AppSettings["FileUplodePath"].ToString(); //从列表框中读取选择的文件名 string strFileName = lb_FileList.SelectedValue; //组合成物理路径 string strFilePhysicalPath = Server.MapPath(strFileUpladPath + "/") + strFileName; //删除文件 System.IO.File.Delete(strFilePhysicalPath); //更新文件列表框控件 lb_FileList.Items.Remove(lb_FileList.Items.FindByText(strFileName)); //更新文件夹信息 InitFolderInfo(); //更新文件描述信息 tb_FileNewName.Text = ""; //更新重命名文本框 lbl_FileDescription.Text = ""; //调用自定义消息提示 ShowMessageBox("删除成功!"); } #endregion #region 重命名文件 protected void btn_Rename_Click(object sender, EventArgs e) { //从web.config中读取文件上传路径 string strFileUpladPath = ConfigurationManager.AppSettings["FileUplodePath"].ToString(); //从列表框中控件中读取选择的文件名 string strFileName = lb_FileList.SelectedValue; //重命名文本框或得选择的文件名 string strFileNewName = tb_FileNewName.Text; //组合成物理路径 string strFilePhysicalPath = Server.MapPath(strFileUpladPath + "/") + strFileName; //组合成新物理路径 string strFileNewPhysicalPath = Server.MapPath(strFileUpladPath + "/") + strFileNewName; //文件重命名,即获取新地址覆盖旧地址的过程 System.IO.File.Move(strFilePhysicalPath, strFileNewPhysicalPath); //找到文件列表的匹配项 ListItem li = lb_FileList.Items.FindByText(strFileName); //修改文字 li.Text = strFileNewName; //修改值 li.Value = strFileNewName; //调用自定义方法现实 ShowMessageBox("文件覆盖成功!"); } #endregion #region 下拉列表事件 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { MultiView1.ActiveViewIndex = Convert.ToInt32(DropDownList1.SelectedValue); } #endregion }
共2页: 上一页 [1] 2 下一页
|