title: Httplistener and file upload
body: <p>I am trying to retrieve an uploaded file from my webserver. As the client sends its files through a webform (random files), I need to parse the request to get the file out and to process it further on. 
  Basically, the code goes as:</p>
  
  <pre><code>HttpListenerContext context = listener.GetContext();
  HttpListenerRequest request = context.Request;
  StreamReader r = new StreamReader(request.InputStream, System.Text.Encoding.Default);
  // this is the retrieved file from streamreader
  string file = null;
  
  while ((line = r.ReadLine()) != null){
       // i read the stream till i retrieve the filename
       // get the file data out and break the loop 
  }
  // A byststream is created by converting the string,
  Byte[] bytes = request.ContentEncoding.GetBytes(file);
  MemoryStream mstream = new MemoryStream(bytes);
  
  // do the rest
  </code></pre>
  
  <p>As a result, i am able to retrieve textfiles, but for all other files, they are corrupted.
  Could someone tell me how to parse these HttplistnerRequests properly (or providing a lightweighted alternative)?</p>