To copy a file attachment in an InfoPath form to a document library, I used this code. The "workfiche" object is an instance of a class generated by the XML Class Generator. For more information about this tool, go to http://www.canerten.com/xml-c-class-generator-for-c-using-xsd-for-deserialization/
byte[] attachFile = workfiche.Vlerick_TP_GeneralInformation.Brochure.AttachDraftText;
//get filename
int namebufferlen = attachFile[20] * 2;
byte[] filenameBuffer = new byte[namebufferlen];
for (int i = 0; i < filenameBuffer.Length; i++)
{
filenameBuffer[i] = attachFile[24 + i];
}
char[] asciiChars = UnicodeEncoding.Unicode.GetChars(filenameBuffer);
string filename = new string(asciiChars);
filename = filename.Substring(0, filename.Length - 1);
//upload to Input Documents doc library
SPFolder inputDocumentsList = web.GetFolder("InputDocuments");
inputDocumentsList.Files.Add(filename, attachFile);
1 comment:
Thanks Koen! This guided me in the right direction! :)
Post a Comment