File Name with extension
-
Hi I have a folder that contain image file with different extension like 1.jpg,2.jpeg,3.pdf,4.png etc.. in my project i type 1 or 3 in text box as input and want to return as 1.jpg or 3.pdf i trieda lot but fail plz help Dim ImagePath As String = "E:\Net Project\Voting\FJCCI\FJCCI\" & Val(TxtReceiptNo.Text) & ".jpg" Dim FileInfo As New FileInfo(ImagePath) MessageBox.Show(FileInfo.Extension) Dim extension As String = Path.GetExtension(ImagePath) Console.WriteLine("GetExtension('{0}') returns '{1}'", ImagePath, extension) Console.WriteLine(extension) ' Console.WriteLine(".txt" = extension)
-
Hi I have a folder that contain image file with different extension like 1.jpg,2.jpeg,3.pdf,4.png etc.. in my project i type 1 or 3 in text box as input and want to return as 1.jpg or 3.pdf i trieda lot but fail plz help Dim ImagePath As String = "E:\Net Project\Voting\FJCCI\FJCCI\" & Val(TxtReceiptNo.Text) & ".jpg" Dim FileInfo As New FileInfo(ImagePath) MessageBox.Show(FileInfo.Extension) Dim extension As String = Path.GetExtension(ImagePath) Console.WriteLine("GetExtension('{0}') returns '{1}'", ImagePath, extension) Console.WriteLine(extension) ' Console.WriteLine(".txt" = extension)
You haven't shown the code you're using so it's impossible to tell you what you're doing wrong.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
You haven't shown the code you're using so it's impossible to tell you what you're doing wrong.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakDim ImagePath As String = "E:\Net Project\Voting\FJCCI\FJCCI\" & Val(TxtReceiptNo.Text) & ".jpg"
Dim FileInfo As New FileInfo(ImagePath) MessageBox.Show(FileInfo.Extension) Dim extension As String = Path.GetExtension(ImagePath) Console.WriteLine("GetExtension('{0}') returns '{1}'", ImagePath, extension) Console.WriteLine(extension) ' Console.WriteLine(".txt" = extension)
-
Dim ImagePath As String = "E:\Net Project\Voting\FJCCI\FJCCI\" & Val(TxtReceiptNo.Text) & ".jpg"
Dim FileInfo As New FileInfo(ImagePath) MessageBox.Show(FileInfo.Extension) Dim extension As String = Path.GetExtension(ImagePath) Console.WriteLine("GetExtension('{0}') returns '{1}'", ImagePath, extension) Console.WriteLine(extension) ' Console.WriteLine(".txt" = extension)
-
Hi I have a folder that contain image file with different extension like 1.jpg,2.jpeg,3.pdf,4.png etc.. in my project i type 1 or 3 in text box as input and want to return as 1.jpg or 3.pdf i trieda lot but fail plz help Dim ImagePath As String = "E:\Net Project\Voting\FJCCI\FJCCI\" & Val(TxtReceiptNo.Text) & ".jpg" Dim FileInfo As New FileInfo(ImagePath) MessageBox.Show(FileInfo.Extension) Dim extension As String = Path.GetExtension(ImagePath) Console.WriteLine("GetExtension('{0}') returns '{1}'", ImagePath, extension) Console.WriteLine(extension) ' Console.WriteLine(".txt" = extension)
See Path.Combine. [https://www.dotnetperls.com/path-vbnet\](https://www.dotnetperls.com/path-vbnet)
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.' ― Confucian Analects
-
Dim ImagePath As String = "E:\Net Project\Voting\FJCCI\FJCCI\" & Val(TxtReceiptNo.Text) & ".jpg"
Dim FileInfo As New FileInfo(ImagePath) MessageBox.Show(FileInfo.Extension) Dim extension As String = Path.GetExtension(ImagePath) Console.WriteLine("GetExtension('{0}') returns '{1}'", ImagePath, extension) Console.WriteLine(extension) ' Console.WriteLine(".txt" = extension)
Path.GetFileNameWithoutExtension Method (System.IO) | Microsoft Docs[^] And then you compare your input to the string returned by the above method for each file you're searching against.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Hi I have a folder that contain image file with different extension like 1.jpg,2.jpeg,3.pdf,4.png etc.. in my project i type 1 or 3 in text box as input and want to return as 1.jpg or 3.pdf i trieda lot but fail plz help Dim ImagePath As String = "E:\Net Project\Voting\FJCCI\FJCCI\" & Val(TxtReceiptNo.Text) & ".jpg" Dim FileInfo As New FileInfo(ImagePath) MessageBox.Show(FileInfo.Extension) Dim extension As String = Path.GetExtension(ImagePath) Console.WriteLine("GetExtension('{0}') returns '{1}'", ImagePath, extension) Console.WriteLine(extension) ' Console.WriteLine(".txt" = extension)
Try:
Dim folder As New DirectoryInfo("E:\Net Project\Voting\FJCCI\FJCCI\")
Dim file As FileInfo = folder.EnumerateFiles(TxtReceiptNo.Text + ".*").FirstOrDefault()
If file Is Nothing Then
MessageBox.Show("The specified file does not exist.")
Else
MessageBox.Show(file.Extension)
End If
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer