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 Nothing. 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 SendFile 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, SendFile blocks until the file is sent. In nonblocking mode, SendFile 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 SendFile 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.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.