-
Sep 24th, 2009, 02:36 AM
#1
Thread Starter
Lively Member
Backgroundworker + Progressbar + Upload To FTP
I have the download progress bar working in my program but I can't find any working code to determine the amount uploaded. here is my upload code
Code:
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create(FTPPath), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("username", "password")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes(FileLocation)
' upload file...
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
MsgBox("File Is Now In Database", MsgBoxStyle.OkOnly, "Upload Complete")
End Sub
-
Sep 24th, 2009, 02:55 AM
#2
Re: Backgroundworker + Progressbar + Upload To FTP
There is no way from that code. You're writing the entire file to the stream with a single synchronous call to Write. That method is simply going to block until the entire file is uploaded. If you want to be able to report progress then you're going to have to break the file up into chunks and then update the progress after writing each chunk.
Given that you're going to be uploading the file in chunks, I would suggest that you read it in chunks too. Open a FileStream and then use a loop to read a chunk and write that chunk. You can choose the size of the chunk yourself, e.g. 1024, 4096 or whatever. You just keep reading and writing until the actual number of bytes you read is less than that size, at which point you know that there's no more data left.
-
Sep 24th, 2009, 03:06 AM
#3
Thread Starter
Lively Member
Re: Backgroundworker + Progressbar + Upload To FTP
could give me an example on how to this?
-
Sep 24th, 2009, 10:31 AM
#4
Thread Starter
Lively Member
Re: Backgroundworker + Progressbar + Upload To FTP
-
Sep 24th, 2009, 02:47 PM
#5
Re: Backgroundworker + Progressbar + Upload To FTP
Originally Posted by Tddupre
Bump can anyone help
JMC gave you a plausible solution.
Now it's up to you to do the research and try it out. I know it can seem daunting at first, but if you break it down, you'll find that's much easier than you first thought.
MSDN has an amazing amount of information that can help. Also, never forget Google
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Sep 24th, 2009, 03:10 PM
#6
Member
Re: Backgroundworker + Progressbar + Upload To FTP
Originally Posted by weirddemon
JMC gave you a plausible solution.
Now it's up to you to do the research and try it out. I know it can seem daunting at first, but if you break it down, you'll find that's much easier than you first thought.
MSDN has an amazing amount of information that can help. Also, never forget Google
kinda off topic and doesn't help the OP much, but i second google and MSDN forums thought.... It's been a REALLY long time since I've touched a language, and back then it was quick basic / visual basic 2.0 or whatever was out then (early 90's)....and even then all i could do was write simple programs that didn't do much.
Recently I've had to get back into it for a side project at work, and in the month that I've been writing my application, I've learned and accomplished FAR more than I'd ever have thought I'd be able to do on my own....namely write an application with a nice GUI that bi-directionally syncs with a server while using local cache's on users machines...what tools have i gained knowledge in?
1.) SQL server (didn't know anything about it before i started)
2.) VB.net
3.) writing to PDF/XLS/XLSX/HTM/Text
4.) writing Triggers
5.) threading
and a host of other things.
I know it's really easy to look for a quick answer by asking other people to do it for you, but if you never learn how to fish, how will you eat?
-
Sep 24th, 2009, 07:16 PM
#7
Re: Backgroundworker + Progressbar + Upload To FTP
Originally Posted by Tddupre
could give me an example on how to this?
I have to concur with the last two posts, which is why I haven't provided an "example". I use the quotes because so many people use the word example when what they actually want is the exact code to solve their problem. There are a ton of examples out there already. The fact that you posted 11 minutes after me shows that you made no effort to find them first. How can you possibly know that you can't do something if you don't try? Make an effort and do what you can for yourself first, then post back here if you have further problems, showing us what you done.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|