PDA

Click to See Complete Forum and Search --> : zip compress remote folders program - problem!


Outofit
Dec 15th, 2009, 12:31 PM
I am writing a windows forms program using VB express 2008, to copy and zip compress certain folders on remote PCs to a destination backup folder on my PC (the one that the program runs on.) It works great if I do the following FIRST:

I open windows explorer and navigate to the folder on the remote PC that I want to back up. Then I am prompted for user name and password. I enter my admin username and password. The "connection" to that folder is now established and NOW my program will work--that is, it will successfully zip compress that folder.

The problem is, if I don't use windows explorer to navigate to the remote folder that I want to back up and enter my user name and password FIRST, that is, before running my program, my program doesn't work--it just creates an empty zip file with nothing in it. :confused:

My question is: how do I programatically 'establish a connection' to a folder on a remote PC? I don't mind if I manually have to enter the User name and password when the program runs. The problem is, my program doesn't even ask, it just fails.

Thanks, I would greatly appreciate any advice!

Outofit
Dec 20th, 2009, 05:53 PM
I have solved my own problem. I can post the code showing how I did it tomorrow, if anyone is curious.

Outofit
Dec 21st, 2009, 06:09 AM
Here it is:

establish_connection(fullsource)



Private Sub establish_connection(ByVal mydir)

'This procedure allows user to browse a network pc. Username and passsword may need to be entered.

Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = mydir
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = openFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
' Insert code to read the stream here.
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
' Check this again, since we need to make sure we didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
End Sub