How to move file to folder using vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fanoftvb
    New Member
    • Mar 2007
    • 29

    How to move file to folder using vb.net

    Hi, i would like to move a selected files to a folder using vb.net.

    I currently have this code

    If File.Exists("C: \Documents and Settings\055949 x\transfer\text .txt") And Not File.Exists("C: \Documents and Settings\055949 x\transfer\text .txt") Then

    File.Move("C:\D ocuments and Settings\055949 x\transfer\text .txt", "C:\Documen ts and Settings\055949 x\Desktop\AES file\transfer\t ext.txt")
    Label1.Text = ("File moved!")
    Else
    Label1.Text = ("File does not exist")
    End If

    How to i make it sure that i will be able to move different files without having to write the full directory of the file? I need to move the files that had been display on gridview.

    p.s I'm using vb.net 2005
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    You can use relative directory locations like . and ..

    Comment

    • fanoftvb
      New Member
      • Mar 2007
      • 29

      #3
      thanx for the reply. Can u show me how to do it caz i'm actually quite new to vb.net?

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        Originally posted by fanoftvb
        thanx for the reply. Can u show me how to do it caz i'm actually quite new to vb.net?
        Assuming that your code executable is running in the directory C:\Documents and Settings\055949 x\ directory...

        Code:
        File.Move(".\transfer\text.txt", ".\Desktop\AES file\transfer\text.txt");
        In a shell if you type "cd ." the character '.' is a reference to your current directory. If you type "cd .." the character '..' is a reference to your current directory's parent directory. You can use '.' and '..' anywhere you want. For example say I wanted to move text.txt to the C: root.
        Code:
        Move("C:\Documents and Settings\055949x\transfer\text.txt","..\..\..\text.text")
        Or say I wanted to move it to the My Pictures folder for the "All Users" account:
        Code:
         
        Move("C:\Documents and Settings\055949x\transfer\text.txt","..\..\All Users\Shared Documents\Shared Pictuers\text.text")

        Comment

        • walid
          New Member
          • Mar 2007
          • 7

          #5
          you have to use the move method. use the file system object FSO

          Comment

          • walid
            New Member
            • Mar 2007
            • 7

            #6
            chech the following site.
            http://builder.com.com/5100-6371_14-6089850.html

            Comment

            • RedSon
              Recognized Expert Expert
              • Jan 2007
              • 4980

              #7
              walid, you missed the point of the conversation. The OP asked "without having to write the full directory of the file". If you do not want to type out the full directory of the file you can use relative directory paths (ie '.' and '..')

              Comment

              • fanoftvb
                New Member
                • Mar 2007
                • 29

                #8
                thanx for all the reply..i will try it out..^__^

                Comment

                • fanoftvb
                  New Member
                  • Mar 2007
                  • 29

                  #9
                  hi i currently has this code

                  strfile = Dir("*.txt")

                  If File.Exists(pat h) Then

                  File.Move("C:\D ocuments and Settings\055949 x\Desktop\AES file\" & strfile, "C:\Documen ts and Settings\055949 x\Desktop\AES file\transfer\" & strfile)
                  Label1.Text = ("File moved!")
                  Else
                  Label1.Text = ("File does not exist")
                  End If


                  i am using gridview and evey file has an id and a button next to it, when i click on the different buttons, the file whose button i click will move. But with the code above, i click on the same button and all the different files will move.. Is there any way to move the file according to the file ID...sry if my explaination is not clear..

                  Comment

                  • pcpchandru
                    New Member
                    • Feb 2007
                    • 3

                    #10
                    hi dear ,
                    please help me . am using vb.net windows application . how to open the .net solution file with in this application using vb.net code. if any of them knows please help send the code to me ..

                    Comment

                    • RedSon
                      Recognized Expert Expert
                      • Jan 2007
                      • 4980

                      #11
                      If you have a separate question please post another thread about it. Posting your own question in another persons started thread is considered hijacking the thread, and is against site rules.

                      Please read the FAQ located at the top of the browser window under the FAQ tab. After you have read it only then should you be posting your questions.

                      Please do not post again in this thread unless you have something to add to the original question.

                      Comment

                      • fanoftvb
                        New Member
                        • Mar 2007
                        • 29

                        #12
                        Hi, so did anyone know how to solve my problem, i need it for my project. Thanx in advance...

                        Comment

                        • RedSon
                          Recognized Expert Expert
                          • Jan 2007
                          • 4980

                          #13
                          Originally posted by fanoftvb
                          Hi, so did anyone know how to solve my problem, i need it for my project. Thanx in advance...
                          Instead of asking us if we solved your problem, why don't you try asking yourself if we solved your problem. How are we to know if your problem is solved?

                          Comment

                          Working...