title: Sending large file consuming a lot of memory in c#
body: <p>I am sending very large file over TCP/IP network which is working as expected.</p>
  
  <p>Just one concern that how to send it efficiently so that memory consumption should be optimized.</p>
  
  <p>Below is the working code </p>
  
  <pre><code>Stream fileStream = File.OpenRead(tbFilename.Text);
  byte[] fileBuffer = new byte[fileStream.Length];
  fileStream.Read(fileBuffer, 0, (int)fileStream.Length);
  
  
  
  // Open a TCP/IP Connection and send the data
     TcpClient clientSocket = new TcpClient(tbServer.Text,8080);
     NetworkStream networkStream = clientSocket.GetStream();
     networkStream.Write(fileBuffer,0,fileBuffer.GetLength(0));
     networkStream.Close();
  </code></pre>