Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. File Name with extension

File Name with extension

Scheduled Pinned Locked Moved Visual Studio
help
7 Posts 4 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14575024
    wrote on last edited by
    #1

    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)

    D L Richard DeemingR 3 Replies Last reply
    0
    • M Member_14575024

      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)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • D 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 Kreskowiak

        M Offline
        M Offline
        Member_14575024
        wrote on last edited by
        #3

        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)
        
        L D 2 Replies Last reply
        0
        • M Member_14575024

          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)
          
          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          What is the problem?

          1 Reply Last reply
          0
          • M Member_14575024

            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)

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • M Member_14575024

              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)
              
              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • M Member_14575024

                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)

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                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

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups