10 Replies - 2164 Views - Last Post: 31 January 2012 - 09:30 AM Rate Topic: -----

#1 MBailey24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 12

Browse folder and Save to USB

Posted 28 January 2012 - 03:51 PM

I'm trying to create an application that browses to a certain directory, then the user chooses the specific file to save, then saves the file to a USB drive. So far I am stuck at the OpenFileDialog piece. How do I pass the variable of what the user selects to the savedialog?
Is This A Good Question/Topic? 0
  • +

Replies To: Browse folder and Save to USB

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Browse folder and Save to USB

Posted 28 January 2012 - 05:31 PM

It will be stored in the filename property of the openfiledialog.

        OpenFileDialog1.ShowDialog()
        Dim k As String = OpenFileDialog1.FileName
        MessageBox.Show(k)


Was This Post Helpful? 0
  • +
  • -

#3 MBailey24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 12

Re: Browse folder and Save to USB

Posted 28 January 2012 - 07:41 PM

I knew it was something like that! Wow. Thanks so much.
Was This Post Helpful? 0
  • +
  • -

#4 MBailey24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 12

Re: Browse folder and Save to USB

Posted 30 January 2012 - 10:08 AM

After I choose the file in the opendialogbox and click open, How do I prepopulate the file as the file to be saved when the savedialogbox pops up?
Was This Post Helpful? 0
  • +
  • -

#5 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Browse folder and Save to USB

Posted 30 January 2012 - 10:20 AM

Im afraid I dont understand what you mean, could you rephrase it?
Was This Post Helpful? 0
  • +
  • -

#6 MBailey24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 12

Re: Browse folder and Save to USB

Posted 30 January 2012 - 11:28 AM

Once I have chosen the file in the open dialog box, how do I transfer that to the save dialog box? I have the file being saved to strFile.

I have this below:

OpenFile.InitialDirectory = "c:\_Export"

        OpenFile.Filter = "Report Files (*.pdf)|*.pdf"

        OpenFile.FilterIndex = 1

        OpenFile.RestoreDirectory = True


        If OpenFile.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            Try
                myStream = OpenFile.OpenFile()
                Dim File As String = OpenFile.FileName
                If (myStream IsNot Nothing) Then
                    'insert code to read the stream
                End If


Was This Post Helpful? 0
  • +
  • -

#7 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Browse folder and Save to USB

Posted 30 January 2012 - 03:14 PM

Well assign it's value to a variable and set the savefiledialog.filename property to the variable. It's not to complex, but can I ask what you are trying to do exactly?
Was This Post Helpful? 0
  • +
  • -

#8 MBailey24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 12

Re: Browse folder and Save to USB

Posted 30 January 2012 - 04:57 PM

I am trying to browse to a specific directory, choose a pdf file to save from that directory, and then the next option should be to save that file to a different directory.

Here is the second part where I save:


Finally
                'Check again.
                If (myStream IsNot Nothing) Then
                    myStream.Close()
                End If
                
                SaveFile.InitialDirectory = "C:\"
               
                SaveFile.Filter = "Report Files (*.pdf)|*.pdf"
               
                SaveFile.FilterIndex = 1
               
                SaveFile.RestoreDirectory = True
            End Try
            If SaveFile.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                
                Try
                    
                    myStream = SaveFile.OpenFile()
                    If (myStream IsNot Nothing) Then
                        
                    End If
                Catch ex As Exception
                    MessageBox.Show("Cannot read file from disk. Original error: " & ex.Message)
                Finally
                    'Check again.
                    If (myStream IsNot Nothing) Then
                        myStream.Close()
                    End If

                End Try

            End If


Was This Post Helpful? 0
  • +
  • -

#9 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Browse folder and Save to USB

Posted 30 January 2012 - 07:47 PM

So you are using the openfiledialog to get a files path, and then using the savefiledialog to move that file? Why make it so complex? If that's not what you're really trying to do please explain more, seeing your code helps but I don't understand your problem.
Was This Post Helpful? 0
  • +
  • -

#10 MBailey24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-January 12

Re: Browse folder and Save to USB

Posted 31 January 2012 - 05:43 AM

View Posttrevster344, on 30 January 2012 - 07:47 PM, said:

So you are using the openfiledialog to get a files path, and then using the savefiledialog to move that file? Why make it so complex? If that's not what you're really trying to do please explain more, seeing your code helps but I don't understand your problem.


How would you simplify it?
Was This Post Helpful? 0
  • +
  • -

#11 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Browse folder and Save to USB

Posted 31 January 2012 - 09:30 AM

Declare a wider scope variable if needed, store the openfiledialog.filename value into the variable, and use the System.IO.Directory.Move(variable goes here, path to move it to goes here).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1