Dim dr As DialogResult = Me.OpenFileDialog1.ShowDialog()
If (dr = System.Windows.Forms.DialogResult.OK) Then
'Selecting multiple files here
Dim N As Integer = 0
For Each myFileName In OpenFileDialog1.FileNames
Try
Dim MyAdvancedWebClient As New MyAdvancedWebClient
MyAdvancedWebClient.FileName = OpenFileDialog1.SafeFileNames(N)
Dim myUri As New Uri("ftp://testing.com/" & OpenFileDialog1.SafeFileNames(N))
MyAdvancedWebClient.Credentials = New System.Net.NetworkCredential("username", "password")
'Uploading of main file
MyAdvancedWebClient.UploadFileAsync(myUri, OpenFileDialog1.FileNames(N))
'Uploading the HTML file here
Dim b As New UriBuilder()
b.Host = "testing.com"
b.UserName = "username"
b.Password = "password"
b.Port = 21
b.Path = "/" & OpenFileDialog1.SafeFileNames(N) & ".html"
b.Scheme = Uri.UriSchemeFtp
Dim g As Uri = b.Uri
Dim c As System.Net.FtpWebRequest = DirectCast(System.Net.FtpWebRequest.Create(g), System.Net.FtpWebRequest)
c.Method = System.Net.WebRequestMethods.Ftp.AppendFile
Dim h As System.IO.Stream = (c.GetRequestStream)
Dim SW As New System.IO.StreamWriter(h)
Dim contents = "<html><head></head><body></body></html>"
SW.WriteLine(contents)
SW.Close()
h.Close()
Catch SecEx As SecurityException
' The user lacks appropriate permissions to read files, discover paths, etc.
MessageBox.Show("Security error. Please contact your administrator for details.\n\n" & _
"Error message: " & SecEx.Message & "\n\n" & _
"Details (send to Support):\n\n" & SecEx.StackTrace)
Catch ex As Exception
' Could not load the File - probably permissions-related.
MessageBox.Show(("Cannot Select File: " & myFileName.Substring(myFileName.LastIndexOf("\"c)) & _
". You may not have permission to read the file, or " + "it may be corrupt." _
& ControlChars.Lf & ControlChars.Lf & "Reported error: " & ex.Message))
End Try
N = N + 1
Next myFileName
End If
Everything works fine, but if the user selects more than 2 files the program stops responding.
What do you think the problem here is?
(no error recorded during debug, the program just stops responding.)

New Topic/Question
Reply




MultiQuote





|