public byte[] XmlToMultiPart(string Header, string Xml) { string Boundary = "--" + Header.Split(new string[] { "boundary=" }, StringSplitOptions.None)[1]; List <byte> BodyList = new List <byte>(); XmlDocument XDoc = new XmlDocument(); XDoc.XmlResolver = null; XDoc.LoadXml(Xml); XmlNodeList Sections = XDoc.SelectNodes("/xml/section"); foreach (XmlNode SectionNode in Sections) { BodyList.AddRange(Encoding.UTF8.GetBytes(Boundary + "\r\n")); XmlNodeList FirstHeaderNodes = SectionNode.SelectNodes("./first_header"); string FirstHeaderName = ""; string FirstHeaderFirstValue = ""; string SectionName = ""; StringBuilder HB = new StringBuilder(); if (FirstHeaderNodes != null && FirstHeaderNodes.Count > 0) { FirstHeaderName = FirstHeaderNodes[0].Attributes["header_name"].Value; FirstHeaderFirstValue = FirstHeaderNodes[0].Attributes["oname"].Value; if (FirstHeaderNodes[0].Attributes["name"] != null) { SectionName = FirstHeaderNodes[0].Attributes["name"].Value; } HB.Append(FirstHeaderName); HB.Append(": "); HB.Append(FirstHeaderFirstValue); if (SectionName.Length > 0) { HB.Append("; "); HB.Append("name=\""); HB.Append(Tools.UrlEncode(SectionName)); HB.Append("\""); } XmlNodeList FirstHeaderSectionNodes = FirstHeaderNodes[0].SelectNodes("./first_header_section"); if (FirstHeaderSectionNodes != null) { foreach (XmlNode FirstHeaderSectionNode in FirstHeaderSectionNodes) { HB.Append("; "); HB.Append(Tools.UrlEncode(FirstHeaderSectionNode.Attributes["oname"].Value)); HB.Append("=\""); HB.Append(Tools.UrlEncode(Tools.Base64Decode(FirstHeaderSectionNode.InnerText))); HB.Append("\""); } } HB.AppendLine(); XmlNodeList OtherHeaderNodes = FirstHeaderNodes[0].SelectNodes("./other_headers/header"); if (OtherHeaderNodes != null) { foreach (XmlNode OtherHeadderNode in OtherHeaderNodes) { HB.Append(OtherHeadderNode.Attributes["oname"].Value); HB.Append(": "); XmlNodeList ValueNodes = OtherHeadderNode.SelectNodes("./value"); if (ValueNodes != null && ValueNodes.Count > 0) { HB.Append(Tools.Base64Decode(ValueNodes[0].InnerText)); } XmlNodeList HeaderSections = OtherHeadderNode.SelectNodes("./header_section"); if (HeaderSections != null) { foreach (XmlNode HeaderSection in HeaderSections) { HB.Append("; "); HB.Append(Tools.UrlEncode(HeaderSection.Attributes["oname"].Value)); HB.Append("=\""); HB.Append(Tools.UrlEncode(Tools.Base64Decode(HeaderSection.InnerText))); HB.Append("\""); } } HB.AppendLine(); } } } HB.AppendLine(); BodyList.AddRange(Encoding.UTF8.GetBytes(HB.ToString())); XmlNodeList SectionValueNodes = SectionNode.SelectNodes("./first_header/section_value"); if (SectionValueNodes != null && SectionValueNodes.Count > 0) { bool CrlfAttributeSet = false; if (SectionValueNodes[0].Attributes["crlf"] != null && SectionValueNodes[0].Attributes["crlf"].Value == "1") { CrlfAttributeSet = true; } string InnerText = Tools.Base64Decode(SectionValueNodes[0].InnerText); if (CrlfAttributeSet) { InnerText = InnerText.Replace("\n", "\r\n"); } //if (SectionValueNodes[0].Attributes["encoded"] != null && SectionValueNodes[0].Attributes["encoded"].Value == "1") //{ BodyList.AddRange(Tools.Base64DecodeToByteArray(InnerText)); //} //else //{ // BodyList.AddRange(Encoding.UTF8.GetBytes(InnerText)); //} } BodyList.AddRange(Encoding.UTF8.GetBytes("\r\n")); } BodyList.AddRange(Encoding.UTF8.GetBytes(Boundary + "--\r\n")); return(BodyList.ToArray()); }