My.Computer.Network.UploadFile Method 

Sends the specified file to the specified host address.

' Usage
My.Computer.Network.UploadFile(sourceFileName ,address)
My.Computer.Network.UploadFile(sourceFileName ,address)
My.Computer.Network.UploadFile(sourceFileName ,address ,userName ,password)
My.Computer.Network.UploadFile(sourceFileName ,address ,userName ,password)
My.Computer.Network.UploadFile(sourceFileName ,address ,userName ,password ,showUI ,connectionTimeout)
My.Computer.Network.UploadFile(sourceFileName ,address ,userName ,password ,showUI ,connectionTimeout ,onUserCancel)
My.Computer.Network.UploadFile(sourceFileName ,address ,userName ,password ,showUI ,connectionTimeout)
My.Computer.Network.UploadFile(sourceFileName ,address ,userName ,password ,showUI ,connectionTimeout ,onUserCancel)
My.Computer.Network.UploadFile(sourceFileName ,address ,networkCredentials ,showUI ,connectionTimeout)
My.Computer.Network.UploadFile(sourceFileName ,address ,networkCredentials ,showUI ,connectionTimeout ,onUserCancel)
' Declaration
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As String _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As System.Uri _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As String, _
   ByVal userName As String, _
   ByVal password As String _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As System.Uri, _
   ByVal userName As String, _
   ByVal password As String _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As String, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As String, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal onUserCancel As UICancelOption _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As System.Uri, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As System.Uri, _
   ByVal userName As String, _
   ByVal password As String, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal onUserCancel As UICancelOption _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As System.Uri, _
   ByVal networkCredentials As System.Net.ICredentials, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer _
)
' -or-
Public Sub UploadFile( _
   ByVal sourceFileName As String, _
   ByVal address As System.Uri, _
   ByVal networkCredentials As System.Net.ICredentials, _
   ByVal showUI As Boolean, _
   ByVal connectionTimeout As Integer, _
   ByVal onUserCancel As UICancelOption _
)

Parameters

  • sourceFileName
    String. Path and name of file to upload. Required.
  • address
    String or Uri. URL, IP address, or URI of destination server. Required.
  • userName
    String. User name to authenticate. Default is an empty string: "".
  • password
    String. Password to authenticate. Default is an empty string: "".
  • showUI
    Boolean. Whether to display progress of the operation. Default is False.
  • connectionTimeout
    Int32. Timeout interval in milliseconds. Default is 100 seconds.
  • networkCredentials
    ICredentials. Credentials for authentication.

Exceptions

The following conditions may cause an exception:

Remarks

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.

Security noteSecurity Note

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

Tasks

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

To See

Upload a file

How to: Upload a File in Visual Basic

Example

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

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

This example uploads the file Order.txt to https://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", _
"https://www.cohowinery.com/upload.aspx","","",True,500)

Requirements

Namespace: Microsoft.VisualBasic.Devices

Class: Network

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

Permissions

The following permissions may be necessary:

Permission Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

UIPermission

Controls the permissions related to user interfaces and the clipboard. Associated enumeration: AllWindows.

WebPermission

Controls rights to access HTTP Internet resources. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.

See Also

Tasks

How to: Download a File in Visual Basic
How to: Parse File Paths in Visual Basic

Reference

My.Computer.Network Object
System.Uri
System.Net.ICredentials
Microsoft.VisualBasic.FileIO.UICancelOption
Microsoft.VisualBasic.Devices.Network.UploadFile