I posted two files to my custom web service. Now I need to read this stream into separate files.
I've sent an XML and a Text file and in the web service I read it as following:
StreamReader stream = new StreamReader(HttpContext.Current.Request.InputStream);
string xmls = stream.ReadToEnd();
I get the stream as string as following (I've also added the boundaries):
"\r\n------------------------------8cfd42d26566ff0\r\nContent-Disposition: form-data; name=\"uplTheFile\"; filename=\"E:\\AJ\\Demo\\EktronSite2\\XMLFiles\\XMLFile.xml\"\r\n Content-Type: application/octet-stream\r\n\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<note xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://tempuri.org/XMLFile.xsd\">\r\n <ID>101</ID>\r\n</note>\r\n------------------------------8cfd42d26566ff0\r\nContent-Disposition: form-data; name=\"uplTheFile\"; filename=\"C:\\TEMP\\log.txt\"\r\n Content-Type: application/octet-stream\r\n\r\nABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n------------------------------8cfd42d26566ff0\r\n"
I need to read the same into different files. For example I need the XML read to XmlDocument type and the text to .docx.
Thanks in advance.
Have you try this :
Stream xmlStream = System.Web.HttpContext.Current.Request.Files[0].InputStream;
Stream txtStream = System.Web.HttpContext.Current.Request.Files[1].InputStream;