Hello, I have this code in C# and it works perfect:
protected string GetUniqueName(string filename) {
string temp = filename;
for (int x=1; System.IO.File.Exists(temp); x++){
temp = filename.Substring(0, filename.LastIndexOf(".")) + x + filename.Substring(filename.LastIndexOf("."));
}
return new System.IO.FileInfo(temp).Name;
}
Then I converted it to VB:
Protected Function GetUniqueName(ByVal filename As String) As String
Dim temp As String = filename
Dim x As Integer = 1
While System.IO.File.Exists(temp)
temp = filename.Substring(0, filename.LastIndexOf(".")) + x + filename.Substring(filename.LastIndexOf("."))
System.Math.Min(System.Threading.Interlocked.Incre ment(x), x - 1)
End While
Return (New System.IO.FileInfo(temp)).Name
End Function
Now I am getting an error:
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 303: Dim x As Integer = 1
Line 304: While System.IO.File.Exists(temp)
Line 305: temp = filename.Substring(0, filename.LastIndexOf(".")) + x + filename.Substring(filename.LastIndexOf("."))
Line 306: System.Math.Min(System.Threading.Interlocked.Incre ment(x), x - 1)
Line 307: End While
Source File: D:\wwwroot\www.yourkinetico.com\wwwroot\AdPlanner\ App_Code\Utils\Upload.vb Line: 305
Stack Trace:
[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions .ParseDouble(String Value, NumberFormatInfo NumberFormat) +211
Microsoft.VisualBasic.CompilerServices.Conversions .ToDouble(String Value, NumberFormatInfo NumberFormat) +74
Any help would be greatly appreciated!