Hi,
Suppose this is our InfoPath form
First we will generate the class for the above InfoPath form
https://nishantrana.me/2014/07/13/generate-a-c-class-from-an-infopath-form/
The sample code
myFields invoice = null; WebClient webclient = new WebClient(); webclient.UseDefaultCredentials = true; using (Stream fileStream = webclient.OpenRead("http://server:5000/formlibrary/FirstForm.xml?NoRedirect=true")) { if (fileStream != null) { XmlTextReader reader = new XmlTextReader(fileStream); reader.Read(); reader.MoveToContent(); XmlSerializer xser = new XmlSerializer(typeof(myFields)); myFields invoiceInfopath = (myFields)xser.Deserialize(reader); byte[] b = invoiceInfopath.field2; // filename int nameBufferLen = b[20] * 2; byte[] fileNameBufffer = new Byte[nameBufferLen]; for (int i = 0; i < nameBufferLen; i++) { fileNameBufffer[i] = b[24 + i]; } char[] charFileName = UnicodeEncoding.Unicode.GetChars(fileNameBufffer); string fileName = new string(charFileName); fileName = fileName.Substring(0, fileName.Length - 1); // attchment byte[] fileContent = new byte[b.Length - (24 + nameBufferLen)]; for (int i = 0; i < fileContent.Length; i++) { fileContent[i] = b[24 + nameBufferLen + i]; } FileStream fs = new FileStream(@"C:\test\" + fileName, FileMode.Create); fs.Write(fileContent, 0, fileContent.Length); fs.Close(); }
Hope it helps.