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))
                newItm.SubItems.Add("")
                newItm.SubItems.Add(OpenFile.FileName)
                lstCollection.Items.Add(newItm)

            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))
                        newItm.SubItems.Add("")
                        newItm.SubItems.Add(Str)
                        lstCollection.Items.Add(newItm)
                    End If
                Next
            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

        bWorker.RunWorkerAsync()

    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
            Try
                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
                Loop
                reqfile.Close()
                ftpstream.Close()
                itm.SubItems.Item(2).Text = "File Succesfully uploaded!"
            Catch ex As Exception
                itm.SubItems.Item(2).Text = "File was not uploaded!"
            End Try
        Next

    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
        MsgBox("Finish!")
    End Sub
End Class

Recommended Answers

All 4 Replies

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.

@K

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.