This topic has not yet been rated - Rate this topic

Network.UploadFile Method (String, String, String, String, Boolean, Int32, UICancelOption)

Sends the specified file to the specified host address.

Namespace:  Microsoft.VisualBasic.Devices
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
public void UploadFile(
	string sourceFileName,
	string address,
	string userName,
	string password,
	bool showUI,
	int connectionTimeout,
	UICancelOption onUserCancel
)

Parameters

sourceFileName
Type: System.String
Path and name of file to upload.
address
Type: System.String
URL, IP address, or URI of destination server.
userName
Type: System.String
User name to authenticate. Default is an empty string: "".
password
Type: System.String
Password to authenticate. Default is an empty string: "".
showUI
Type: System.Boolean
Whether to display progress of the operation. Default is False.
connectionTimeout
Type: System.Int32
Timeout interval in milliseconds. Default is 100 seconds.
onUserCancel
Type: Microsoft.VisualBasic.FileIO.UICancelOption
Action to be taken when the user clicks Cancel. Default is ThrowException.
Exception Condition
ArgumentException

The source file path is not valid.

ArgumentException

connectionTimeout is less than or equal to zero.

InvalidOperationException

address does not include a file name.

SecurityException

Authentication failed.

TimeoutException

The server does not respond within the specified connectionTimeout.

SecurityException

The user authentication fails.

SecurityException

User lacks necessary permissions to perform a network operation.

WebException

The request is denied by the target web server.

If showUI is set to True, a dialog box shows the progress of the operation and includes a Cancel button that the user can click to cancel the operation. Because the dialog box is not modal, it does not block user input to other windows in the program.

If the server does not respond within the interval specified in connectionTimeout, the operation is cancelled and an exception is thrown.

My.Computer.Network.UploadFile outputs trace information when you enable network tracing in your application. For more information, see Enabling Network Tracing.

Note Note

The FTP protocol sends information, including passwords, in plain text and should not be used for transmitting sensitive information.

The following table lists an example of a task involving the My.Computer.Network.UploadFile method.

This example uploads the file Order.txt to http://www.cohowinery.com/uploads.


My.Computer.Network.UploadFile ( "C:\My Documents\Order.txt", 
"http://www.cohowinery.com/upload.aspx")


This example uploads the file Order.txt to http://www.cohowinery.com/uploads without supplying a user name or password, shows the progress of the upload, and has a time-out interval of 500 milliseconds.


My.Computer.Network.UploadFile ("C:\My Documents\Order.txt", 
"http://www.cohowinery.com/upload.aspx","","",True,500)


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ