title: how do i send folder with its contents (subfolder/files) to server-client side?
body: <p>I'm making a file transfer (server-client) application. im using TCP. (.net 4.0)</p>
  
  <p>How do I send a Folder with all its contents(folder/files) to the other side ??</p>
  
  <p>I have these methods that works fine:
  <li></p>
  
  <pre><code>Send(string srcPath, string destPath)  //sends a single file
  </code></pre>
  
  <p><li></p>
  
  <pre><code>Recieve(string destPath) //recieves a single file
  </code></pre>
  
  <p>This is the Send method:</p>
  
  <pre><code>public void Send(string srcPath, string destPath)
  {
      using (fs = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
      {
          try
          {
              fileSize = fs.Length;
              while (sum &lt; fileSize)
              {
                  if (fileSize - sum &lt; packetSize)
                  {
                      count = fs.Read(data, 0, (int)(fileSize - sum));
                      network.Write(data, 0, (int)(fileSize - sum));
                  }
                  else
                  {
                      count = fs.Read(data, 0, data.Length);
                      network.Write(data, 0, data.Length);
                  }
                  fs.Seek(sum, SeekOrigin.Begin);
                  sum += count;
              }
              network.Flush();
          }
          finally
          {
              fs.Dispose();
          }
      }
  }
  </code></pre>
  
  <p>and this's the Recieve Method :</p>
  
  <pre><code>    public void Recieve(string destPath)
      {
          using (fs = new FileStream(destPath, FileMode.Create, FileAccess.Write))
          {
              try
              {
                  while (sum &lt; fileSize)
                  {
                      if (fileSize - sum &lt; packetSize)
                      {
                          count = network.Read(data, 0, (int)(fileSize - sum));
                          fs.Write(data, 0, (int)(fileSize - sum));
                      }
                      else
                      {
                          count = network.Read(data, 0, data.Length);
                          fs.Write(data, 0, data.Length);
                      }
                      fs.Seek(sum, SeekOrigin.Begin);
                      sum += count;
                  }
              }
              finally
              {
                  fs.Dispose();
              }
          }
      }
  </code></pre>
  
  <p>This is a common variables :</p>
  
  <pre><code>    const int packetSize = 1024 * 8;    //Packet Size.
      long sum;                           //Sum of sent data.
      long fileSize;                      //File Size.
      int count = 0;                      //data counter.
      static byte[] data = null;          //data buffer.
  
      NetworkStream network; 
      FileStream fs;
  </code></pre>
  
  <p>I also got:</p>
  
  <pre><code>bool IsFolder(string path) //that returns if the path is a folder or a file
  </code></pre>