c#实现按日期命名上传文件代码做开发的应该能够用得了吧!
附件说明边的TextBoxId=TextBox
浏览Id=UpLoadFile
上传Id=AddFile
文件目录wwwroot/myWeb/userfiles/upload
private void AddFile_Click(object sender SystemEventArgs e)
{
if(UpLoadFilePostedFileFileNameTrim()!=)
{
String fileName =UpLoadFilePostedFileFileNameSubstring (UpLoadFilePostedFileFileNameLastIndexOf(\\)+ UpLoadFilePostedFileFileNameLength UpLoadFilePostedFileFileNameLastIndexOf(\\))
///取到当前时间的年月日分秒和毫秒的值并使用字符串格式把它们组合成一个字符串
String fileTime = DateTimeNowYearToString() + DateTimeNowMonthToString()
+ DateTimeNowDayToString() + DateTimeNowHourToString()
+ DateTimeNowSecondToString() + DateTimeNowMinuteToString()
+ DateTimeNowMillisecondToString()
///在时间字符串后面添加一个随机数和文件的后缀名
String src=fileNameSubstring(fileNameLastIndexOf()+fileNameLengthfileNameLastIndexOf())ToLower()
if(srcToLower()==rar || srcToLower()==doc || srcToLower()==xls)
{
fileName =fileTime + GetRandomint() + + src
///上载文件到服务器硬盘
UpLoadFilePostedFileSaveAs(ServerMapPath(RequestApplicationPath) + \\userfiles\\upload\\ + fileName)
if(TextBoxTextTrim()==)
{
FCKeditorValue=FCKeditorValue+<a href=userfiles/upload/+fileName+>下载附件</a><br>
}
else
{
FCKeditorValue=FCKeditorValue+<a href=userfiles/upload/+fileName+>+TextBoxTextToString()+< /a><br>
}
}
else
{
ResponseWrite(<script>alert(\文件格式不正确请上传格式为RAR的文件!\)</script>)
}
}
}
private String GetRandomint()
{
Random random = new Random()
return(randomNext()ToString()) //产生一个小于的随机正整数
}