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 Basic
  4. Newbie here

Newbie here

Scheduled Pinned Locked Moved Visual Basic
csharpquestion
15 Posts 7 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.
  • N Offline
    N Offline
    Nguyen Dinh Quy
    wrote on last edited by
    #1

    What's the code for Vb.Net to open a dialog window, and after choosing a file, you will copy that particular file to a pre-determined location?

    T 1 Reply Last reply
    0
    • N Nguyen Dinh Quy

      What's the code for Vb.Net to open a dialog window, and after choosing a file, you will copy that particular file to a pre-determined location?

      T Offline
      T Offline
      thealca
      wrote on last edited by
      #2

      Dim dlg As New OpenFileDialog() dlg.ShowDialog()

      N 1 Reply Last reply
      0
      • T thealca

        Dim dlg As New OpenFileDialog() dlg.ShowDialog()

        N Offline
        N Offline
        Nguyen Dinh Quy
        wrote on last edited by
        #3

        So how do i code it to copy the chosen file to another destination?

        M D 2 Replies Last reply
        0
        • N Nguyen Dinh Quy

          So how do i code it to copy the chosen file to another destination?

          M Offline
          M Offline
          Marc 0
          wrote on last edited by
          #4

          IO.File.Copy(sourcefile, desinationfile) so i guess i would be something like:

          Dim dlg As New OpenFileDialog()
          If dlg.ShowDialog() = DialogResult.OK
          IO.File.Copy(dlg.FileName, desinationfile)
          End If


          1 Reply Last reply
          0
          • N Nguyen Dinh Quy

            So how do i code it to copy the chosen file to another destination?

            D Offline
            D Offline
            Daniel1324
            wrote on last edited by
            #5

            Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\") EndIf ' Will copy the chosen file to C:\

            N 1 Reply Last reply
            0
            • D Daniel1324

              Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\") EndIf ' Will copy the chosen file to C:\

              N Offline
              N Offline
              Nguyen Dinh Quy
              wrote on last edited by
              #6

              Thanks guys..another question.. Can i change the filename while copying the file to the new location? So that it will be renamed when it is copied to the new location?

              T 1 Reply Last reply
              0
              • N Nguyen Dinh Quy

                Thanks guys..another question.. Can i change the filename while copying the file to the new location? So that it will be renamed when it is copied to the new location?

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                see the MSDN[^]...


                TOXCCT >>> GEII power
                [toxcct][VisualCalc]

                N 1 Reply Last reply
                0
                • T toxcct

                  see the MSDN[^]...


                  TOXCCT >>> GEII power
                  [toxcct][VisualCalc]

                  N Offline
                  N Offline
                  Nguyen Dinh Quy
                  wrote on last edited by
                  #8

                  Hmm..but it doesn't teach us how to rename a file? Sorry but i'm really weak in Vb.Net >.<

                  Y 1 Reply Last reply
                  0
                  • N Nguyen Dinh Quy

                    Hmm..but it doesn't teach us how to rename a file? Sorry but i'm really weak in Vb.Net >.<

                    Y Offline
                    Y Offline
                    Yulianto
                    wrote on last edited by
                    #9

                    Copy the code and run it.


                    Work hard, Work effectively.

                    N 1 Reply Last reply
                    0
                    • Y Yulianto

                      Copy the code and run it.


                      Work hard, Work effectively.

                      N Offline
                      N Offline
                      Nguyen Dinh Quy
                      wrote on last edited by
                      #10

                      Private Sub MenuItem16_Click(ByVal sender as System.Object,ByVal e as EventArgs)Handles MenuItem16.Click Dim FileDialog As OpenFileDialog Dim Test As New Test 'The Test class from MSDN if FileDialog.ShowDialog() = DialogResults.Ok then Test.Main() End If There's no build error, but after I chose a file from the dialog box, no file was copied to the new location :( What's my problem here? Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\") EndIf ' Will copy the chosen file to C:\ I tried this as well, but after clicking OK in the dialog box, it gives an error indicating "Directory Exists", so i couldn't copy my chosen file to C:\ as well...why?

                      Y 1 Reply Last reply
                      0
                      • N Nguyen Dinh Quy

                        Private Sub MenuItem16_Click(ByVal sender as System.Object,ByVal e as EventArgs)Handles MenuItem16.Click Dim FileDialog As OpenFileDialog Dim Test As New Test 'The Test class from MSDN if FileDialog.ShowDialog() = DialogResults.Ok then Test.Main() End If There's no build error, but after I chose a file from the dialog box, no file was copied to the new location :( What's my problem here? Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\") EndIf ' Will copy the chosen file to C:\ I tried this as well, but after clicking OK in the dialog box, it gives an error indicating "Directory Exists", so i couldn't copy my chosen file to C:\ as well...why?

                        Y Offline
                        Y Offline
                        Yulianto
                        wrote on last edited by
                        #11

                        Nguyen Dinh Quy wrote: Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\") EndIf ' Will copy the chosen file to C:\ Try Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\a.txt") EndIf


                        Work hard, Work effectively.

                        N 1 Reply Last reply
                        0
                        • Y Yulianto

                          Nguyen Dinh Quy wrote: Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\") EndIf ' Will copy the chosen file to C:\ Try Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\a.txt") EndIf


                          Work hard, Work effectively.

                          N Offline
                          N Offline
                          Nguyen Dinh Quy
                          wrote on last edited by
                          #12

                          Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\a.txt") EndIf Yah, this will create a text file in C:\...but what if the user chooses other types of files? (.exe, .pdf) I tried choosing an .exe file, but it creates a .txt file, using notepad to read the .exe file. :( Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\" + dlg.FileName) EndIf I tried this, but it gives an error indicating "The given path's format is not supported".

                          Y 1 Reply Last reply
                          0
                          • N Nguyen Dinh Quy

                            Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\a.txt") EndIf Yah, this will create a text file in C:\...but what if the user chooses other types of files? (.exe, .pdf) I tried choosing an .exe file, but it creates a .txt file, using notepad to read the .exe file. :( Dim dlg as New OpenFileDialog if dlg.ShowDialog() = DialogResult.Ok then System.IO.File.Copy(dlg.FileName, "C:\" + dlg.FileName) EndIf I tried this, but it gives an error indicating "The given path's format is not supported".

                            Y Offline
                            Y Offline
                            Yulianto
                            wrote on last edited by
                            #13

                            Nguyen Dinh Quy wrote: Yah, this will create a text file in C:\...but what if the user chooses other types of files? (.exe, .pdf) I tried choosing an .exe file, but it creates a .txt file, using notepad to read the .exe file. Do you mean you want do copy file dynamically, where the user can choose which file to be copied and where? :confused: If the file you want to copy is .exe then the destination file must also .exe so System.IO.File.Copy(dlg.FileName, "C:\a.exe") Nguyen Dinh Quy wrote: ystem.IO.File.Copy(dlg.FileName, "C:\" + dlg.FileName) if dlg.FileName="c:\a.txt" then the destination file you use "C:\" + dlg.FileName, then it means that you're copying file to "C:\c:\a.txt".


                            Work hard, Work effectively.

                            N 1 Reply Last reply
                            0
                            • Y Yulianto

                              Nguyen Dinh Quy wrote: Yah, this will create a text file in C:\...but what if the user chooses other types of files? (.exe, .pdf) I tried choosing an .exe file, but it creates a .txt file, using notepad to read the .exe file. Do you mean you want do copy file dynamically, where the user can choose which file to be copied and where? :confused: If the file you want to copy is .exe then the destination file must also .exe so System.IO.File.Copy(dlg.FileName, "C:\a.exe") Nguyen Dinh Quy wrote: ystem.IO.File.Copy(dlg.FileName, "C:\" + dlg.FileName) if dlg.FileName="c:\a.txt" then the destination file you use "C:\" + dlg.FileName, then it means that you're copying file to "C:\c:\a.txt".


                              Work hard, Work effectively.

                              N Offline
                              N Offline
                              Nguyen Dinh Quy
                              wrote on last edited by
                              #14

                              Ahh i guess my first post was horribly phased ;P Anyway yah, users can choose from the dialog box which files to be copied, but the location where the files are copied to is fixed. With "Files", i mean any types of files.. e.g. User chooses Example.txt from C:\, and it is copied to D:\.So now there's C:\Example.txt and D:\Example.txt. The 1st question here is that i don't know how to do it.

                              A 1 Reply Last reply
                              0
                              • N Nguyen Dinh Quy

                                Ahh i guess my first post was horribly phased ;P Anyway yah, users can choose from the dialog box which files to be copied, but the location where the files are copied to is fixed. With "Files", i mean any types of files.. e.g. User chooses Example.txt from C:\, and it is copied to D:\.So now there's C:\Example.txt and D:\Example.txt. The 1st question here is that i don't know how to do it.

                                A Offline
                                A Offline
                                Anonymous
                                wrote on last edited by
                                #15

                                The following code will handle copying of any file extension. Dim FileDialog As New OpenFileDialog 'FileInfo class has Dim myFile as System.IO.FileInfo With FileDialog if .ShowDialog() = DialogResults.Ok then 'create FileInfo instance where .Filename is the fullpath of source 'file. For example: C:\Example.txt myFile = new System.IO.FileInfo(.Filename) 'FileInfo.Name property indicates the file name 'For example: If the source file is C:\Example.txt than the FileInfo.Name 'property is Example.txt myFile.CopyTo("D:\" & myFile.Name, false) 'syntax: FileInfo.CopyTo(destfilename as String, forceoverwrite as Boolean) End If End With I hope this makes sense :-D A.S.

                                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