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. C#
  4. Filenames and open file dialog

Filenames and open file dialog

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelp
8 Posts 5 Posters 0 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.
  • S Offline
    S Offline
    SRJ92
    wrote on last edited by
    #1

    hello, i need help with my project for college, i am using visual studio 2008 and c# programming lang. I want to grab the file name or file path to put into a rich text document using an openfiledialog. Users are able to select the file using the openfiledialog, select the file, and then when they double click or press open, the file name is inserted into the richtextbox.... to insert the text i am using InsertText(""); thanks

    L OriginalGriffO 2 Replies Last reply
    0
    • S SRJ92

      hello, i need help with my project for college, i am using visual studio 2008 and c# programming lang. I want to grab the file name or file path to put into a rich text document using an openfiledialog. Users are able to select the file using the openfiledialog, select the file, and then when they double click or press open, the file name is inserted into the richtextbox.... to insert the text i am using InsertText(""); thanks

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

      And what is the problem that you are having?

      Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here

      1 Reply Last reply
      0
      • S SRJ92

        hello, i need help with my project for college, i am using visual studio 2008 and c# programming lang. I want to grab the file name or file path to put into a rich text document using an openfiledialog. Users are able to select the file using the openfiledialog, select the file, and then when they double click or press open, the file name is inserted into the richtextbox.... to insert the text i am using InsertText(""); thanks

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        You can use OpenFileDialog:

                    OpenFileDialog sfd = new OpenFileDialog();
                    sfd.Filter = filterString;
                    if (sfd.ShowDialog() == DialogResult.OK)
                        {
                        string fileName = sfd.FileName;
                        ...
                        }
        

        or FolderBrowserDialog:

                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.SelectedPath = tbInitialDir.Text;
                if (fbd.ShowDialog() == DialogResult.OK)
                    {
                    string filePath = fbd.SelectedPath;
                    ...
                    }
        

        You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        S 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          You can use OpenFileDialog:

                      OpenFileDialog sfd = new OpenFileDialog();
                      sfd.Filter = filterString;
                      if (sfd.ShowDialog() == DialogResult.OK)
                          {
                          string fileName = sfd.FileName;
                          ...
                          }
          

          or FolderBrowserDialog:

                  FolderBrowserDialog fbd = new FolderBrowserDialog();
                  fbd.SelectedPath = tbInitialDir.Text;
                  if (fbd.ShowDialog() == DialogResult.OK)
                      {
                      string filePath = fbd.SelectedPath;
                      ...
                      }
          

          You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

          S Offline
          S Offline
          SRJ92
          wrote on last edited by
          #4

          Thanks for the code example, can u tell me another thing which is how i would put the string / filename into a rich text box ? thanks again ..

          modified on Monday, March 29, 2010 3:52 PM

          N 1 Reply Last reply
          0
          • S SRJ92

            Thanks for the code example, can u tell me another thing which is how i would put the string / filename into a rich text box ? thanks again ..

            modified on Monday, March 29, 2010 3:52 PM

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            Didn't you say you were using InsertText()?


            I know the language. I've read a book. - _Madmatt

            S 1 Reply Last reply
            0
            • N Not Active

              Didn't you say you were using InsertText()?


              I know the language. I've read a book. - _Madmatt

              S Offline
              S Offline
              SRJ92
              wrote on last edited by
              #6

              yeah like inserttext("hello") , but i don't know how to put it for a string .... is it like inserttext("string filename"); or ?

              D 1 Reply Last reply
              0
              • S SRJ92

                yeah like inserttext("hello") , but i don't know how to put it for a string .... is it like inserttext("string filename"); or ?

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

                SRJ92 wrote:

                but i don't know how to put it for a string

                What do you think "hello" is? You get a string for the filepath back from the OpenFileDialog. You just put that string in the InsertText call. What's the problem?

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                S 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  SRJ92 wrote:

                  but i don't know how to put it for a string

                  What do you think "hello" is? You get a string for the filepath back from the OpenFileDialog. You just put that string in the InsertText call. What's the problem?

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008
                  But no longer in 2009...

                  S Offline
                  S Offline
                  SRJ92
                  wrote on last edited by
                  #8

                  sorry i found out now, lol just me being dumb and not thinking right... thanks ...

                  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