Hello Guys,
please i need your help: does OpenFileDialog control have a restriction on the maximum number of files it can upload?
i'm curreently working on an application that uploads files to an FTP Server. the codes work perfectly to upload up to 80 files but if i try to upload more than 80 files,it says "file not found".
i want to modify the codes so it can accept any number and size of files. if OpenFileDialog can't make it happen, kindly show me an alternative. thanks
here is my codes:

Imports System.IO
Imports System.Net
Imports System.Windows.Forms

Public Class FTPServerApp
    Private Sub FTPServerApp_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Control.CheckForIllegalCrossThreadCalls = False
    End Sub

    Private Sub btnAddFile_Click(sender As Object, e As EventArgs) Handles btnAddFile.Click
        Dim OpenFile As New OpenFileDialog() With {.Multiselect = True}
        If OpenFile.ShowDialog() = DialogResult.OK Then
            If OpenFile.FileNames.Count = 1 Then

                Dim newItm As New ListViewItem(Path.GetFileName(OpenFile.FileName))
                newItm.SubItems.Add(txtServer.Text & "/" & Path.GetFileName(OpenFile.FileName))

            ElseIf OpenFile.FileNames.Count > 1 Then
                For Each Str As String In OpenFile.FileNames
                    If My.Computer.FileSystem.FileExists(Str) Then
                        Dim newItm As New ListViewItem(Path.GetFileName(Str))
                        newItm.SubItems.Add(txtServer.Text & "/" & Path.GetFileName(Str))
                    End If
            End If

            lblCount.Text = "0 /" & lstCollection.Items.Count
        End If
    End Sub

    Private Sub btnUploadFile_Click(sender As Object, e As EventArgs) Handles btnUploadFile.Click


    End Sub

    Private Sub bWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bWorker.DoWork
        For Each itm As ListViewItem In lstCollection.Items
                Dim request As FtpWebRequest = DirectCast(WebRequest.Create(New Uri(itm.SubItems.Item(1).Text)), FtpWebRequest)
                request.Method = WebRequestMethods.Ftp.UploadFile
                request.Credentials = New NetworkCredential(txtUser.Text, txtPassword.Text)
                request.UseBinary = True
                request.UsePassive = False

                Dim buffer(1023) As Byte
                Dim bytesIn As Long = 1
                Dim totalBytesIn As Long = 0

                Dim filepath As System.IO.FileInfo = New System.IO.FileInfo(itm.SubItems.Item(3).Text)
                Dim ftpstream As System.IO.FileStream = filepath.OpenRead()
                Dim flLength As Long = ftpstream.Length
                Dim reqfile As System.IO.Stream = request.GetRequestStream

                Do Until bytesIn < 1
                    bytesIn = ftpstream.Read(buffer, 0, 1024)
                    If bytesIn > 0 Then
                        reqfile.Write(buffer, 0, bytesIn)
                        totalBytesIn += bytesIn
                        If flLength > 0 Then
                            Dim perc As Integer = (totalBytesIn / flLength) * 100
                            bWorker.ReportProgress(perc, CInt(itm.Index + 1))
                        End If
                    End If
                itm.SubItems.Item(2).Text = "File Succesfully uploaded!"
            Catch ex As Exception
                itm.SubItems.Item(2).Text = "File was not uploaded!"
            End Try

    End Sub

    Private Sub bWorker_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles bWorker.ProgressChanged
        pBar.Value = e.ProgressPercentage
        lblPercent.Text = e.ProgressPercentage & " %"
        lblCount.Text = CInt(e.UserState) & " / " & lstCollection.Items.Count
    End Sub

    Private Sub bWorker_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bWorker.RunWorkerCompleted
    End Sub
End Class
2 Years
Discussion Span
Last Post by rproffitt

thanks rproffitt for your contribution.. i checked the link you sent but can't make anything out of it


Did you check the rules for uploading files to the server. Most enforce some rules. Just google: "upload fiels restrictions" and you will find heaps of different entries to different servers.



I took has to read it more than once to see what the alternative was about. That said, why not add debug code after the dialog about line 11 and write the strings to a file so you can check it out?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.