title: Send Multiple files to a WebService and Read it into seperate files in the WebService
body: <p>I want to write a web service in c# that receives multiple files from the stream, read them into different files and then perform some ask on these files(say for example, the files that I need to send are XML):</p>
  
  <p><strong>This is what I've done so far:</strong></p>
  
  <p>1)Send the files by the following method, this creates a request and post it to the web service:</p>
  
  <pre><code>public void postMultipleFiles()
      {
          string url = "&lt;the url of the web service&gt;";
          HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
          httpWebRequest.Method = "POST";
          httpWebRequest.KeepAlive = true;
          httpWebRequest.ContentType = "text/xml; encoding='utf-8'";
          Stream memStream = new MemoryStream();
          string[] files = { @"&lt;file1 location&gt;", @"&lt;file2 location&gt;" };
          /*AJ*/
          foreach (string file in files)
          {
              FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
              byte[] buffer = new byte[1024];
              int bytesRead = 0;
              while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
              {
                  memStream.Write(buffer, 0, bytesRead);
              }
              fileStream.Close();
          }
          httpWebRequest.ContentLength = memStream.Length;
          Stream requestStream = httpWebRequest.GetRequestStream();
          memStream.Position = 0;
          byte[] tempBuffer = new byte[memStream.Length];
          memStream.Read(tempBuffer, 0, tempBuffer.Length);
          memStream.Close();
          requestStream.Write(tempBuffer, 0, tempBuffer.Length);
          requestStream.Close();
          try
          {
              WebResponse webResponse = httpWebRequest.GetResponse();
              Stream stream = webResponse.GetResponseStream();
              StreamReader reader = new StreamReader(stream);
              response.InnerHtml = reader.ReadToEnd();
              //Response.Write(reader.ReadToEnd());
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
          httpWebRequest = null;
      }
  </code></pre>
  
  <p>2)Read the stream in the webservice as following:</p>
  
  <pre><code>[WebMethod]
      public string MultiFilePost()
      {
          string xmls = "";
          if (HttpContext.Current.Request.InputStream != null)
          { 
              StreamReader stream = new StreamReader(HttpContext.Current.Request.InputStream);
              xmls = stream.ReadToEnd(); // added to view content of input stream
              xmls = xmls.Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
          }
          return xmls;
      }
  </code></pre>
  
  <p>But this reads the file into a string, appended one after the other.</p>
  
  <p>How do I manage to get this into two different XML files?</p>
  
  <p>Thanks in advance....</p>