Sends the file fileName and buffers of data to a connected System.Net.Sockets.Socket object using the specified System.Net.Sockets.TransmitFileOptions value.
- fileName
- A string that contains the path and name of the file to be sent. This parameter can be null.
- preBuffer
- A byte array that contains data to be sent before the file is sent. This parameter can be null.
- postBuffer
- A byte array that contains data to be sent after the file is sent. This parameter can be null.
- flags
- One or more of System.Net.Sockets.TransmitFileOptions values.
This overload requires the name of the file you want to send and a bitwise combination of System.Net.Sockets.TransmitFileOptions values. The preBuffer parameter contains any data you want to precede the file. postBuffer contains data you want to follow the file. If fileName is in the current working 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.
The flags parameter provides the Window Sockets service provider with additional information about the file transfer. For more information about how to use this parameter, see System.Net.Sockets.TransmitFileOptions.
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.
Socket.SendFile(string) synchronously sends a file to the remote host specified in the Socket.Connect(System.Net.EndPoint) or Socket.Accept method. Socket.SendFile(string) can be used for both connection-oriented and for connectionless protocols.
If you are using a connectionless protocol, you must call Socket.Connect(System.Net.EndPoint) before calling this method; otherwise Socket.SendFile(string) throws a System.Net.Sockets.SocketException. If you are using a connection-oriented protocol, you must either use Socket.Connect(System.Net.EndPoint) to establish a remote host connection, or use Socket.Accept to accept an incoming connection.
If you are using a connection-oriented protocol, Socket.SendFile(string) blocks until the entire file is sent. In nonblocking mode, Socket.SendFile(string) 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 Socket.SendFile(string) method means that the underlying system has had room to buffer your data for a network send.
If you receive a System.Net.Sockets.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 [<topic://conUsingNetworkTracing>].