Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 200676 - Last Review: August 10, 2004 - Revision: 1.3
How To Use the AsyncRead Method to Download Files
This article was previously published under Q200676
Both
UserDocument objects and
UserControl objects can perform asynchronous file reading from local and remote computers. This article demonstrates how to use the
AsyncRead method of a
UserControl to copy a file.
Step-by-Step Example
The following steps demonstrate how to copy a file from an Internet site.
- Create an ActiveX control project in Visual Basic. UserControl1 is created by default.
- Add two Label controls, a TextBox control, and a CommandButton control to the UserControl designer.
- Position Label1 above Text1, and adjust the size of the TextBox control to handle approximately 100 characters.
- Add the following code to the General Declarations section of UserControl1:
Option Explicit
Private Sub Command1_Click()
' Use the AsyncRead method to copy the file.
UserControl.AsyncRead Text1.Text, vbAsyncTypeFile
End Sub
Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
' Yield execution to ensure that the temporary file is written.
DoEvents
' Display the copied file name, including its path,
' using the value property of the AsyncProp object.
MsgBox Text1.Text & " was copied to: " & AsyncProp.Value
End Sub
Private Sub UserControl_AsyncReadProgress(AsyncProp As AsyncProperty)
' Display the progress of the file copy using the
' BytesRead and BytesMax properties of the AsyncProp object.
Label2.Caption = AsyncProp.BytesRead & " of " & AsyncProp.BytesMax & " bytes copied."
End Sub
Private Sub UserControl_Initialize()
Command1.Caption = "Copy!"
Label1.Caption = "From:"
Label2.Caption = ""
' Assign a file to be copied.
' Use the Visual Basic 6.0 run-time files package as a test.
Text1.Text = "http://download.microsoft.com/download/vb60pro/install/6/Win98Me/EN-US/VBRun60.exe"
End Sub
- Run the project., In the Project Properties dialog box on the Debugging tab, click OK to start the UserControl1 component. Notice that UserControl1 is now running in a Web browser.
- Locate a file that you want to copy from a remote computer through HTTP, and type the URL and file name in the TextBox.
- Click Copy!. A dialog box appears when the copy operation is complete.
For more information about
UserControl objects, refer to Visual Basic Help, and query on
UserControls.
APPLIES TO
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Professional Edition
| kbhowto kbdownload kbcodesnippet kbctrl KB200676 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate