在web.config里配置,文件的限制信息
BrowseFiles.aspx:
BrowseFiles.aspx.cs
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<!--日志权重处理级别
0 Off 不输出跟踪和调试消息。
1 Error 输出错误处理消息。
2 Warning 输出警告和错误处理消息。
3 Info 输出信息性消息、警告和错误处理消息。
4 Verbose 输出所有调试和跟踪消息。
-->
<switches>
<add name="dSwitch" value="4"/>
<!-- 默认权重处理级别 -->
<add name="sdfs" value="2"/>
</switches>
<trace autoflush="true" indentsize="2"/>
</system.diagnostics>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=RJB-ZYB;Initial Catalog=RenheOA2;User ID=sa"/>
</connectionStrings>
<appSettings>
<!-- 日至文件路径 -->
<add key="LogPath" value="logdir"/>
<!-- 日至是否写入事件查看器 -->
<add key="EventLog" value="true"/>
<!-- 共享文件夹默认目录-->
<add key="folderPath" value="Upload"/>
<!--上传文件类型-->
<add key="FileTypeLimit" value=".zip,.rar,.jpg,.gif,.bmp,.doc,.txt,.swf,.xls,.doc,.ppt"/>
<!--限制文件夹的总大小,单位为KB,102400KB=100M-->
<add key="FolderSizeLimit" value="40960"/>
</appSettings>
<system.web>
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20"/>
<!-- 上传大文件设置-->
<httpRuntime executionTimeout="90" maxRequestLength="102400" useFullyQualifiedRedirectUrl="false"
minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>
<authentication mode="Windows"/>
<!--
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<compilation debug="true" />
</system.web>
</configuration>
BrowseFiles.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BrowseFiles.aspx.cs" enableEventValidation="false"
Inherits="CommonPage_FileManager_BrowseFiles" %>
<!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 runat="server">
<title>无标题页</title>
<link href="../FileManager/StyleBrowseFile.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function CreateDir()
{
dirName = prompt('输入要创建的目录名称:','新文件夹');
if ((dirName) && (dirName!=""))
{
document.forms['BrowseFiles'].elements['funcParam'].value = dirName;
__doPostBack('CreateDir', '');
}
}
function Download(path)
{
document.forms['BrowseFiles'].elements['funcParam'].value = path;
__doPostBack('Download', '');
}
function Delete()
{
return confirm('确认要删除所选的文件/文件夹吗?')
// __doPostBack('Delete','');
}
function Rename(path)
{
newName = prompt('输入文件夹/文件的新名称:','');
if ((newName) && (newName!=""))
{
document.forms['BrowseFiles'].elements['funcParam'].value = path;
document.forms['BrowseFiles'].elements['funcExtraParam'].value = newName;
__doPostBack('Rename', '');
}
}
</script>
</head>
<body>
<form id="BrowseFiles" method="post" runat="server" enctype="multipart/form-data">
<input type="hidden" id="funcParam" runat="server" name="funcParam">
<input type="hidden" id="funcExtraParam" runat="server" name="funcExtraParam">
<asp:Table runat="server" CssClass="TableHeader" Width="100%" ID="Table1">
<asp:TableRow>
<asp:TableCell Width="36">
<asp:Image runat="server" Height="25" Width="25" ImageUrl="./Images/OpenFolder.gif"
ID="Image1" NAME="Image1"></asp:Image>
</asp:TableCell>
<asp:TableCell>
<asp:Label runat="server" ID="FolderDescription"></asp:Label>
</asp:TableCell>
<asp:TableCell Width="140px">
操作:<a href="javascript:CreateDir();"><img border="0" src="./Images/NewFolder.gif"
alt="创建一个新目录" height="20" width="20"></a>
<asp:LinkButton ID="CreateDir" runat="server" OnClick="CreateDir_Click" />
<%--<a href="javascript:Delete();"><img border="0" src="./Images/Delete.gif" Alt="删除选择的文件/文件夹" height="20" width="20"></a>
--%>
<asp:ImageButton ImageUrl="./Images/Delete.gif" ToolTip="删除选择的文件/文件夹" Height="20"
Width="20" ID="ImageButton1" runat="server" OnClientClick="Delete();" OnClick="Delete_Click" /><asp:LinkButton
ID="Delete" runat="server" OnClick="Delete_Click" Visible="False" />
<asp:LinkButton ID="Rename" runat="server" OnClick="Rename_Click" Visible="False" />
<asp:LinkButton ID="Download" runat="server" OnClick="Download_Click" Visible="False" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Table ID="FoldersAndFiles" runat="server" CssClass="Grid_General" Width="100%">
<asp:TableRow CssClass="Grid_Header">
<asp:TableCell Width="36px" Font-Bold="True" />
<asp:TableCell Text="名称" Font-Bold="True" />
<asp:TableCell Width="30px" Font-Bold="True" />
<asp:TableCell Width="40px" Font-Bold="True" />
<asp:TableCell Text="大小" Width="80px" Font-Bold="True" HorizontalAlign="Right" />
<asp:TableCell Text="创建时间" Width="140px" Font-Bold="True" />
<asp:TableCell Text="修改时间" Width="140px" Font-Bold="True" />
</asp:TableRow>
</asp:Table>
<br>
<asp:Table runat="server" ID="Table2">
<asp:TableRow>
<asp:TableCell Width="80px" Font-Bold="True" Text="上传文件:" />
<asp:TableCell>
<input id="UploadedFile" runat="server" class="LongButton" name="UploadedFile" size="35"
type="file">
</asp:TableCell>
<asp:TableCell>
<asp:Button ID="Upload" OnClick="Upload_Click" runat="server" CssClass="Button" Text="上 传">
</asp:Button>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br>
<asp:Label ID="StatusMessage" runat="server" CssClass="StatusMessage" Visible="False"
Width="100%" />
<asp:Label ID="FolderStyle" runat="Server" Text="Grid_Item" Visible="false" />
<asp:Label ID="FileStyle" runat="Server" Text="Grid_AlternatingItem" Visible="false" />
</form>
</body>
</html>
BrowseFiles.aspx.cs
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 LEO.Common;
using System.IO;
public partial class CommonPage_FileManager_BrowseFiles : BasePage
{
private string folderPath;
private string folderPathDefault;
private string[] extensions = new string[]{".arj", ".asa",".asax", ".ascx", ".asmx", ".asp", ".aspx", ".au", ".avi", ".bat", ".bmp",
".cab", ".chm", ".com", ".config", ".cs", ".css", ".disco", ".dll", ".doc",
".exe", ".gif", ".hlp", ".htm", ".html", ".jpg",".png", ".inc", ".ini",
".log", ".mdb", ".mid", ".midi", ".mov", ".mp3", ".mpg", ".mpeg",
".pdf", ".ppt", ".sys", ".txt", ".tif", ".vb", ".vbs", ".vsdisco",
".wav", ".wri", ".swf", ".xls", ".xml", ".zip",".rar"};
protected void Page_Load(object sender, EventArgs e)
{
//初始化文件夹路径
folderPathDefault = String.Format("{0}/{1}", Request.ApplicationPath.ToString(), ConfigurationManager.AppSettings["folderPath"].ToString());
if (!Directory.Exists(folderPathDefault))
Directory.CreateDirectory(Server.MapPath(folderPathDefault));
folderPath = Server.UrlDecode(Request.Params["Folder"]);
if (folderPath == null || folderPath == "/")
folderPath = folderPathDefault;
// 去除文件夹末尾的"/".
else if (folderPath.EndsWith("/"))
folderPath = folderPath.Substring(0, folderPath.Length - 1);
// 显示文件路径
FolderDescription.Text = "文件路径: " + folderPath.Substring(folderPathDefault.Length);
// 实际文件夹路径 "<br>Physical folder: " + Server.MapPath(folderPath);
FillFoldersAndFilesTable();
}
/****************************************************************************
/扫描当前文件夹,添加所有子目录和文件
/添加文件链接、图标、文件夹结构, 和其他资料,如创建日期,大小等。
/****************************************************************************/
private void FillFoldersAndFilesTable()
{
string location;
DirectoryInfo parentDir;
DirectoryInfo[] childDirs;
FileInfo[] childFiles;
try
{
parentDir = new DirectoryInfo(Server.MapPath(folderPath));
//得到所有的文件夹、子目录
childDirs = parentDir.GetDirectories();
childFiles = parentDir.GetFiles();
}
catch (Exception exc)
{
StatusMessage.Text = exc.Message;
StatusMessage.Visible = true;
Logger.Log(Logger.ERROR, "初始化共享文件夹 :" + exc.Message);
return;
}
TableRow rowItem;
TableCell cellItemIcon;
TableCell cellItemLink;
TableCell cellSize;
TableCell cellDownload;
TableCell cellOperations;
TableCell cellCreated;
TableCell cellLastModified;
HyperLink linkRename;
HyperLink linkItem;
HyperLink linkDownload;
CheckBox checkItem;
// HyperLink linkSetAttribs;
// Label labelAttributes;
System.Web.UI.WebControls.Image imgItemIcon;
Style styleFolderRow = new Style();
styleFolderRow.CssClass = FolderStyle.Text;
Style styleFileRow = new Style();
styleFileRow.CssClass = FileStyle.Text;
Style styleLink = new Style();
styleLink.CssClass = "GridLink";
// 如果目录不是共享文件的根目录增加向上一级的链接
if (folderPath != folderPathDefault)
{
rowItem = new TableRow();
cellItemIcon = new TableCell();
cellItemLink = new TableCell();
linkItem = new HyperLink();
imgItemIcon = new System.Web.UI.WebControls.Image();
// 增加向上的图片链接
imgItemIcon.ImageUrl = "./Images/ParentFolder.gif";
cellItemIcon.Controls.Add(imgItemIcon);
cellItemIcon.HorizontalAlign = HorizontalAlign.Right;
// 增加到父级目录的链接
linkItem.Text = " ...";
int lastSlashIndex = folderPath.LastIndexOf("/");
location = folderPath.Substring(0, lastSlashIndex);
if (location.Length == 0)
location = Request.ApplicationPath.ToString();
linkItem.NavigateUrl = "BrowseFiles.aspx?Folder=" + Server.UrlEncode(location);
linkItem.ApplyStyle(styleLink);
cellItemLink.Controls.Add(linkItem);
// 添加单元格到行
rowItem.Cells.Add(cellItemIcon);
rowItem.Cells.Add(cellItemLink);
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());
// 将行添加到表
rowItem.ApplyStyle(styleFolderRow);
FoldersAndFiles.Rows.Add(rowItem);
}
// 添加所有的子文件夹
foreach (DirectoryInfo childDir in childDirs)
{
rowItem = new TableRow();
cellItemLink = new TableCell();//内容单元格
linkItem = new HyperLink();
cellItemIcon = new TableCell();//图标单元格
checkItem = new CheckBox();
imgItemIcon = new System.Web.UI.WebControls.Image();
cellSize = new TableCell();
cellOperations = new TableCell();
linkRename = new HyperLink();
cellCreated = new TableCell();
cellLastModified = new TableCell();
//cellAttributes = new TableCell();
//labelAttributes = new Label();
//linkSetAttribs = new HyperLink();
//创建到到子文件夹的链接
linkItem.Text = childDir.Name;
location = folderPath;
if (location.EndsWith("/"))
location += childDir.Name;
else
location += "/" + childDir.Name;
linkItem.NavigateUrl = "BrowseFiles.aspx?Folder=" + Server.UrlEncode(location);
linkItem.ApplyStyle(styleLink);
cellItemLink.Controls.Add(linkItem);
// 子文件夹大小
cellSize.Text = FormatSize(GetDirectorySize(childDir.FullName)) + " ";
cellSize.HorizontalAlign = HorizontalAlign.Right;
// 创建及修改时间
cellCreated.Text = String.Format("{0:MM/dd/yy HH:mm}", childDir.CreationTime);
cellLastModified.Text = String.Format("{0:MM/dd/yy HH:mm}", childDir.LastWriteTime);
//设置一个属性用于记录文件夹路径
checkItem.Attributes["Path"] = location;
checkItem.Attributes["IsFile"] = "false";
cellItemIcon.Controls.Add(checkItem);
// 增加一个文件夹图标
imgItemIcon.ImageUrl = "./Images/ClosedFolder.gif";
cellItemIcon.Controls.Add(imgItemIcon);
cellItemIcon.HorizontalAlign = HorizontalAlign.Right;
// 添加重命名链接。"D",表明是一个文件夹
linkRename.Text = "<img src=\"./Images/Rename.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"重命名文件夹\">";
linkRename.NavigateUrl = "javascript:Rename('D" + location + "');";
cellOperations.Controls.Add(linkRename);
修改文件夹属性
//labelAttributes.Text = GetAttributesDescription(childDir.Attributes);
//labelAttributes.Font.Name = "Courier";
//linkSetAttribs.Text = "<img src=\"./Images/Edit.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"Edit attributes\">";
//linkSetAttribs.NavigateUrl = "javascript:SetAttributes('" + location + "');";
//cellAttributes.Controls.Add(labelAttributes);
//cellAttributes.Controls.Add(linkSetAttribs);
//增加格
rowItem.Cells.Add(cellItemIcon);
rowItem.Cells.Add(cellItemLink);
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(cellOperations);
rowItem.Cells.Add(cellSize);
rowItem.Cells.Add(cellCreated);
rowItem.Cells.Add(cellLastModified);
// 增加行
rowItem.ApplyStyle(styleFolderRow);
FoldersAndFiles.Rows.Add(rowItem);
}
// 添加所有的子文件
foreach (FileInfo childFile in childFiles)
{
rowItem = new TableRow();
cellItemLink = new TableCell();
linkItem = new HyperLink();
cellItemIcon = new TableCell();
checkItem = new CheckBox();
imgItemIcon = new System.Web.UI.WebControls.Image();
cellDownload = new TableCell();
linkDownload = new HyperLink();
cellSize = new TableCell();
cellOperations = new TableCell();
linkRename = new HyperLink();
cellCreated = new TableCell();
cellLastModified = new TableCell();
//cellAttributes = new TableCell();
//labelAttributes = new Label();
//linkSetAttribs = new HyperLink();
int extIndex;
// 在新窗口打开文件 (此功能屏蔽)
linkItem.Text = childFile.Name;
location = folderPath;
if (location.EndsWith("/"))
location += childFile.Name;
else
location += "/" + childFile.Name;
//linkItem.NavigateUrl = location;
//linkItem.Target = "_blank";
linkItem.ApplyStyle(styleLink);
cellItemLink.Controls.Add(linkItem);
// 下载链接
linkDownload.Text = "<img src=\"./Images/Download.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"文件下载\">";
linkDownload.NavigateUrl = "javascript:Download('" + location + "');";
cellDownload.Controls.Add(linkDownload);
// 文件大小
cellSize.Text = FormatSize(childFile.Length) + " ";
cellSize.HorizontalAlign = HorizontalAlign.Right;
// 创建时间
cellCreated.Text = String.Format("{0:MM/dd/yy HH:mm}", childFile.CreationTime);
cellLastModified.Text = String.Format("{0:MM/dd/yy HH:mm}", childFile.LastWriteTime);
//重命名文件链接
linkRename.Text = "<img src=\"./Images/Rename.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"文件重命名\">";
linkRename.NavigateUrl = "javascript:Rename('F" + location + "');";
cellOperations.Controls.Add(linkRename);
// //编辑文件,此功能屏蔽
//extIndex = Array.IndexOf(textExtensions, childFile.Extension.ToLower());
//if (extIndex > -1 &&
// (childFile.Attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly &&
// (childFile.Attributes & FileAttributes.System) != FileAttributes.System)
//{
// HyperLink linkEditFile = new HyperLink();
// linkEditFile.Text = "<img src=\"./Images/Write.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"Edit this file\">";
// linkEditFile.NavigateUrl = "EditFile.aspx?File=" + location;
// cellOperations.Controls.Add(linkEditFile);
//}
//添加文件图标
extIndex = Array.IndexOf(extensions, childFile.Extension.ToLower());
if (extIndex > -1)
imgItemIcon.ImageUrl = "./Images/" + childFile.Extension.Substring(1) + ".gif";
else
imgItemIcon.ImageUrl = "./Images/unknown.gif";
// set the checkbox and add the item's path and type (file) as
// it's done above for child directories
checkItem.Attributes["Path"] = location;
checkItem.Attributes["IsFile"] = "true";
cellItemIcon.Controls.Add(checkItem);
cellItemIcon.Controls.Add(imgItemIcon);
cellItemIcon.HorizontalAlign = HorizontalAlign.Right;
// 编辑属性
//labelAttributes.Text = GetAttributesDescription(childFile.Attributes);
//labelAttributes.Font.Name = "Courier";
//linkSetAttribs.Text = "<img src=\"./Images/Edit.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"Edit attributes\">";
//linkSetAttribs.NavigateUrl = "javascript:SetAttributes('" + location + "');";
//cellAttributes.Controls.Add(labelAttributes);
//cellAttributes.Controls.Add(linkSetAttribs);
rowItem.Cells.Add(cellItemIcon);
rowItem.Cells.Add(cellItemLink);
rowItem.Cells.Add(cellDownload);
rowItem.Cells.Add(cellOperations);
rowItem.Cells.Add(cellSize);
rowItem.Cells.Add(cellCreated);
rowItem.Cells.Add(cellLastModified);
rowItem.ApplyStyle(styleFileRow);
FoldersAndFiles.Rows.Add(rowItem);
}
}
/****************************************************************************
/ 计算文件夹的大小
/****************************************************************************/
protected long GetDirectorySize(string path)
{
long dirSize = 0;
DirectoryInfo dir = new DirectoryInfo(path);
// add the size of each file
foreach (FileInfo file in dir.GetFiles())
dirSize += file.Length;
// add the size of each sub-directory, that is retrieved by recursively
// calling this same routine
foreach (DirectoryInfo subdir in dir.GetDirectories())
dirSize += GetDirectorySize(subdir.FullName);
return dirSize;
}
/****************************************************************************
/ 格式化文件大小返回,B\KB\MB
/***************************************************************************/
protected string FormatSize(double fileSize)
{
if (fileSize < 1024)
return String.Format("{0:N0} B", fileSize);
else if (fileSize < 1024 * 1024)
return String.Format("{0:N2} KB", fileSize / 1024);
else
return String.Format("{0:N2} MB", fileSize / (1024 * 1024));
}
//上传文件
protected void Upload_Click(object sender, EventArgs e)
{
int fileLength=int.Parse(ConfigurationManager.AppSettings["FolderSizeLimit"].ToString());
//文件是否被指定
if (UploadedFile.PostedFile != null && UploadedFile.PostedFile.FileName.Length > 0)
{
if (IsAllowableFileType(UploadedFile.PostedFile.FileName) && UploadedFile.PostedFile.ContentLength/1024 < fileLength)
{
string destDir = Server.MapPath(folderPath);
try
{
// 保存到当前目录
string fileName = Path.GetFileName(UploadedFile.PostedFile.FileName);
UploadedFile.PostedFile.SaveAs(Path.Combine(destDir, fileName));
// 刷新页面
Response.Redirect("BrowseFiles.aspx?Folder=" + Server.UrlEncode(folderPath));
}
catch (Exception exc)
{
StatusMessage.Text = exc.Message;
StatusMessage.Visible = true;
Logger.Log(Logger.ERROR, "上传文件 :" + exc.Message);
}
}
else
MessageShow("不允许上传此格式或文件大于" + fileLength/1024+ "M!");
}
else
{
MessageShow("请选择文件!");
}
}
// 判断文件类型限制
protected bool IsAllowableFileType(string FileName)
{
//从web.config读取判断文件类型限制
string strFileTypeLimit = ConfigurationManager.AppSettings["FileTypeLimit"].ToString();
//当前文件扩展名是否包含在这个字符串中
if (strFileTypeLimit.IndexOf(Path.GetExtension(FileName).ToLower()) > 0)
return true;
else
return false;
}
//创建文件夹
protected void CreateDir_Click(object sender, EventArgs e)
{
string path = folderPath;
if (path.EndsWith("/"))
path += funcParam.Value;
else
path += "/" + funcParam.Value;
try
{
Directory.CreateDirectory(Server.MapPath(path));
Response.Redirect("BrowseFiles.aspx?Folder=" + Server.UrlEncode(folderPath));
}
catch (Exception exc)
{
StatusMessage.Text = exc.Message;
StatusMessage.Visible = true;
Logger.Log(Logger.ERROR, "创建文件夹 :" + exc.Message);
}
}
//删除文件或目录
protected void Delete_Click(object sender, EventArgs e)
{
bool redir = true;
foreach (TableRow tr in FoldersAndFiles.Rows)
{
if (tr.Cells[0].Controls.Count == 2)
{
CheckBox checkItem = (CheckBox)tr.Cells[0].Controls[0];
if (checkItem.Checked)
{
try
{
string path = Server.MapPath(checkItem.Attributes["Path"].ToString());
if (Convert.ToBoolean(checkItem.Attributes["IsFile"]) == true)
File.Delete(path);
else
Directory.Delete(path, true);
}
catch (Exception exc)
{
StatusMessage.Text = exc.Message;
StatusMessage.Visible = true;
redir = false;
Logger.Log(Logger.ERROR, "删除文件或目录 :" + exc.Message);
}
}
}
}
if (redir) Response.Redirect("BrowseFiles.aspx?Folder=" + Server.UrlEncode(folderPath));
}
//重命名文件夹或文件
protected void Rename_Click(object sender, EventArgs e)
{
bool isFile = funcParam.Value.StartsWith("F");
//提取源路径
string sourcePath = Server.MapPath(funcParam.Value.Substring(1));
string destPath;
try
{
if (isFile)
{
FileInfo sourceFile = new FileInfo(sourcePath);
// 合并新路径
destPath = Path.Combine(sourceFile.Directory.FullName, funcExtraParam.Value);
//移动文件 = 重命名
sourceFile.MoveTo(destPath);
}
else
{
DirectoryInfo sourceDir = new DirectoryInfo(sourcePath);
// 合并新路径
destPath = Path.Combine(sourceDir.Parent.FullName, funcExtraParam.Value);
移动文件夹 = 重命名
sourceDir.MoveTo(destPath);
}
//
Response.Redirect("BrowseFiles.aspx?Folder=" + Server.UrlEncode(folderPath));
}
catch (Exception exc)
{
StatusMessage.Text = exc.Message;
StatusMessage.Visible = true;
Logger.Log(Logger.ERROR, "重命名文件夹或文件 :" + exc.Message);
}
}
//下载文件
protected void Download_Click(object sender, EventArgs e)
{
//提取源路径
string sourcePath = Server.MapPath(funcParam.Value);
try
{
System.IO.FileInfo file = new System.IO.FileInfo(sourcePath);
// UrlDecode
Response.Clear();
Page.Response.ClearHeaders();
Page.Response.Buffer = false;
this.EnableViewState = false;
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", file.Length.ToString());
// Response.ContentType = "application/octet-stream";
Page.Response.ContentType = "application/unknown";
Response.WriteFile(file.FullName);
Page.Response.Flush();
Page.Response.Close();
Response.End();
Page.Response.Clear();
}
catch (Exception exc)
{
StatusMessage.Text = exc.Message;
StatusMessage.Visible = true;
Logger.Log(Logger.ERROR, "重命名文件夹或文件 :" + exc.Message);
}
}
}