下面是孟老大的多文件上传程序,我想改成上传后自动改名,在代码
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName)
前面加了
Dim FileName111 As String = Path.GetFileName(fileName)
fileName = Now()
fileName = Replace(fileName, "-", "")
fileName = Replace(fileName, ":", "")
fileName = Replace(fileName, " ", "")
fileName = fileName
fileName = fileName & Strx & Right(Path.GetFileName(FileName111), Len(Path.GetFileName(FileName111)) - (InStr(Path.GetFileName(FileName111), ".")) + 1)现在是按时间改名了,可是上传多个文件后,前面的文件就被后面的文件覆盖了,求各位大侠帮忙解决这个问题!谢谢!(问题解决立即送分,在线等)孟老大多文件上传代码:
Private Function SaveImages() As System.Boolean
'遍历File表单元素
Dim files As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files '状态信息
Dim strMsg As New System.Text.StringBuilder("上传的文件分别是:<hr color=red>")
Dim iFile As System.Int32
Try
For iFile = 0 To files.Count - 1
'检查文件扩展名字
Dim postedFile As System.Web.HttpPostedFile = files(iFile)
Dim fileName, fileExtension As System.String
fileName = System.IO.Path.GetFileName(postedFile.FileName)
If Not (fileName = String.Empty) Then
fileExtension = System.IO.Path.GetExtension(fileName)
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br/>")
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br/>")
strMsg.Append("上传文件的文件名:" + fileName + "<br/>")
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br/><hr>")
'可根据扩展名字的不同保存到不同的文件夹
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName)
End If
Next
strStatus.Text = strMsg.ToString()
Return True
Catch Ex As System.Exception
strStatus.Text = Ex.Message
Return False
End Try
End Function
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName)
前面加了
Dim FileName111 As String = Path.GetFileName(fileName)
fileName = Now()
fileName = Replace(fileName, "-", "")
fileName = Replace(fileName, ":", "")
fileName = Replace(fileName, " ", "")
fileName = fileName
fileName = fileName & Strx & Right(Path.GetFileName(FileName111), Len(Path.GetFileName(FileName111)) - (InStr(Path.GetFileName(FileName111), ".")) + 1)现在是按时间改名了,可是上传多个文件后,前面的文件就被后面的文件覆盖了,求各位大侠帮忙解决这个问题!谢谢!(问题解决立即送分,在线等)孟老大多文件上传代码:
Private Function SaveImages() As System.Boolean
'遍历File表单元素
Dim files As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files '状态信息
Dim strMsg As New System.Text.StringBuilder("上传的文件分别是:<hr color=red>")
Dim iFile As System.Int32
Try
For iFile = 0 To files.Count - 1
'检查文件扩展名字
Dim postedFile As System.Web.HttpPostedFile = files(iFile)
Dim fileName, fileExtension As System.String
fileName = System.IO.Path.GetFileName(postedFile.FileName)
If Not (fileName = String.Empty) Then
fileExtension = System.IO.Path.GetExtension(fileName)
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br/>")
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br/>")
strMsg.Append("上传文件的文件名:" + fileName + "<br/>")
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br/><hr>")
'可根据扩展名字的不同保存到不同的文件夹
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName)
End If
Next
strStatus.Text = strMsg.ToString()
Return True
Catch Ex As System.Exception
strStatus.Text = Ex.Message
Return False
End Try
End Function
解决方案 »
- 提交数据时,关于select控件的一个问题
- B/S视频教学中我想做一个视频和图片说明同步的功能,请问怎样实现啊?
- VS2005 的MENU控件问题
- 工作机会--初级ASP.NET 网站程序员 深圳
- 请问如何把一个html文本框控件隐藏
- Response.Write("<a href=#>test</a>")触发服务器端事件的问题
- 急,一个小功能!提交数据后,出现提交成功提示,点击确定关闭数据提交页面!
- 请问怎么做页面打印,doPrint()
- 简单问题,动态插入一个超链接后如何再插入一个换行符<br>
- ******高分求助!! 一个.net数据库访问的问题??谢谢!!
- 如何在asp.net中把页面数据导到excel中!!急!!急!!急!!急!!急!!急!!
- 关于c#继承的问题Page.Session与this.Session
首先上传文件
然后找到文件的位置,
最后File.Move()这个是C#的
这个就可以改名字
然后用MOVE这个方法就可以重新命名了
fileName = Now()
fileName = Replace(fileName, "-", "")
fileName = Replace(fileName, ":", "")
fileName = Replace(fileName, " ", "")
fileName = fileName
fileName = fileName & Strx & Right(Path.GetFileName(FileName111), Len(Path.GetFileName(FileName111)) - (InStr(Path.GetFileName(FileName111), ".")) + 1)我加上上面的代码后文件名按时间改了,但问题是我同时上传多个文件时后面上传的就会覆盖前面上传的文件
Dim FileName111 As String = Path.GetFileName(fileName)
fileName = Now()
fileName = Replace(fileName, "-", "")
fileName = Replace(fileName, ":", "")
fileName = Replace(fileName, " ", "")
fileName = fileName & Right(Path.GetFileName(FileName111), Len(Path.GetFileName(FileName111)) - (InStr(Path.GetFileName(FileName111), ".")) + 1)