28,409
社区成员




<%@ Page Language="C#" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
string filePath = System.Configuration.ConfigurationSettings.AppSettings["UpLoadPath"] + "/";
string fileName;
//接受保存上传文件
foreach(string f in Request.Files.AllKeys)
{
string fullName;
HttpPostedFile postFile = Request.Files[f];
if (postFile.ContentLength > 10)
{
fileName = postFile.FileName;
GetFileName(fileName, out fullName);
fullName = filePath + fullName;
postFile.SaveAs(Server.MapPath(fullName));
Response.Write(fullName.Trim()); //客户端的返回值。
}
}
}
//根据时间和上传文件名生成新的文件名
void GetFileName(string fileName, out string fullName)
{
int lastDot = fileName.LastIndexOf(".");
string fileExtension = fileName.Substring(lastDot, fileName.Length-lastDot);
DateTime current = DateTime.Now;
int year, month, day, hour, minute, second, millsecond;
year = current.Year;
month = current.Month;
day = current.Day;
hour = current.Hour;
minute = current.Millisecond;
second = current.Second;
millsecond = current.Millisecond;
fullName = year.ToString() + month.ToString() + day.ToString() + hour.ToString() + minute.ToString() + second.ToString() + millsecond.ToString() +
fileExtension;
}
</script>