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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. openFileDialog problem

openFileDialog problem

Scheduled Pinned Locked Moved C#
helptutorial
6 Posts 5 Posters 1 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.
  • C Offline
    C Offline
    CodeItWell
    wrote on last edited by
    #1

    I have one openFileDialog1. How to get the name of the selected file. But not the all path. Exp:"C:\NewFolder\TextFile.txt". Just "TextFile.txt"

    Vasildb

    P G 2 Replies Last reply
    0
    • C CodeItWell

      I have one openFileDialog1. How to get the name of the selected file. But not the all path. Exp:"C:\NewFolder\TextFile.txt". Just "TextFile.txt"

      Vasildb

      P Offline
      P Offline
      Paul Lyons
      wrote on last edited by
      #2

      You can use a Path object from the Sytem.IO namespace.

      string fileName = Path.GetFileName(OpenFileDialog1.FileName);

      Path.GetFileName[^] FileDialog.FileName[^]

      Paul Lyons, CCPL
      Certified Code Project Lurker

      1 Reply Last reply
      0
      • C CodeItWell

        I have one openFileDialog1. How to get the name of the selected file. But not the all path. Exp:"C:\NewFolder\TextFile.txt". Just "TextFile.txt"

        Vasildb

        G Offline
        G Offline
        gnadeem
        wrote on last edited by
        #3

        hi, use Substring and LastIndexOf functions to get the required value; any string supports these methods. regards.

        D E 2 Replies Last reply
        0
        • G gnadeem

          hi, use Substring and LastIndexOf functions to get the required value; any string supports these methods. regards.

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

          That's, most certainly, doing it the hard way and in some cases unreliably.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          G 1 Reply Last reply
          0
          • D Dave Kreskowiak

            That's, most certainly, doing it the hard way and in some cases unreliably.

            Dave Kreskowiak Microsoft MVP - Visual Basic

            G Offline
            G Offline
            gnadeem
            wrote on last edited by
            #5

            Thnx Dave ,for correction.

            1 Reply Last reply
            0
            • G gnadeem

              hi, use Substring and LastIndexOf functions to get the required value; any string supports these methods. regards.

              E Offline
              E Offline
              ednrgc
              wrote on last edited by
              #6

              That should never be done. Prone to too many errors.

              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