0

每次上传文件时,我都需要在文件末尾添加一个增量数字。我几乎可以正常工作。

请检查以下代码:

Dim intVersion As Integer = 1
   While (System.IO.File.Exists(strDestinationPath))
       Dim temp As Integer = ourFilename.LastIndexOf(".")
       Dim temp2 As String = ourFilename.Substring(temp)
       ourFilename = ourFilename.Replace(temp2, "_" & intVersion & temp2)
       strDestinationPath = System.Configuration.ConfigurationManager.AppSettings("WebLocalContentDir") & "\VisualID\" & ourFilename
       intVersion += 1
   End While

如果我上传文件 3 次,它会保存为,

第一次:VDFGH 第二次:VDFGH_1 第三次:VDFGH_1_2(预期输出为 VDFGH_2)

4

1 回答 1

1
Dim intVersion As Integer = 1
While (System.IO.File.Exists(strDestinationPath))
   Dim temp As Integer = ourFilename.LastIndexOf(".")
   Dim temp2 As String = ourFilename.Substring(temp)
   dim tempFileName as string = ourFilename.Replace(temp2, "_" & intVersion & temp2)
   strDestinationPath = System.Configuration.ConfigurationManager.AppSettings("WebLocalContentDir") & "\VisualID\" & tempFileName
   intVersion += 1
End While

很确定这会奏效。您正在更改原始文件名字符串,然后每次都对其进行修改。

于 2012-09-20T18:18:27.480 回答