Socket.SendFile Method (String)
Assembly: System (in System.dll)
The socket is not connected to a remote host.
The Socket object has been closed.
The Socket object is not in blocking mode and cannot accept this synchronous call.
The file fileName was not found.
An error occurred when attempting to access the socket. See the Remarks section for more information.
This overload sends the file fileName to the connected socket. The flags parameter defaults to UseDefaultWorkerThread (0), and the preBuffer and postBuffer parameters default to null. If fileName is in the local directory, it may be identified with just the name of the file; otherwise, the full path and name of the file must be specified. Wildcards ("..\\myfile.txt") and UNC share names ("\\\\shared directory\\myfile.txt") are supported. If the file is not found, the exception FileNotFoundException is thrown.
This method uses the TransmitFile function found in the Windows Sockets 2 API. For more information about the TransmitFile function and its flags, see the Windows Sockets documentation in the MSDN Library.
If you are using a connectionless protocol, you must call Connect before calling this method, otherwise throws a SocketException exception. If you are using a connection-oriented protocol, you must either use Connect to establish a remote host connection or use Accept to accept an incoming connection.
If you are using a connection-oriented protocol,blocks until the file is sent. In nonblocking mode, may complete successfully before the entire file has been sent. There is no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the method means that the underlying system has had room to buffer your data for a network send.
If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.
Available since 2.0