Reading Infopath File Attachment in C# Causing Corrupted First lin

D

Dan the Man

Hi All,

My Infopath users are going to be uploading csv files to my form and I want
to read the csv files and perform operations on them. Unfortunately, the
first line returned appears to be corrupted. Here is the code I have for
taking a File Attachment Node and converting it into a string array in C#:

IXMLDOMNode oFileAttachment = ...;
string[] arrFileContents;
try
{
byte[] byteBinaryData =
System.Convert.FromBase64String(oFileAttachment.text);

string strFileContents =
System.Text.Encoding.ASCII.GetString(byteBinaryData);

// Split the File Contents up into an array of lines
arrFileContents = strFileContents.Split('\n');
}

When I cycle through the contents of my array, the first line output says
"IFA[]" (where [] represents the square ASCII Character) no matter what the
first line is. The problem occurs before the "strFileContents.Split('\n');"
line.

So, has anyone else seen this problem and know how to fix it?

Thanks in advance.
 
A

Andrew Watt [MVP - InfoPath]

Dan,

If you use a small test attachment and just display it as text do you
get the whole file? Do you see spurious characters?

Andrew Watt
MVP - InfoPath
 
M

Matthew Blain \(Serriform\)

the infopath attachment format is for some reason wrapped in its own binary
format.

more info:
http://tips.serriform.com/CSharpCreateInfoPathAttachment.htm
http://www.developingsolutionswithinfopath.com

--Matthew

Andrew Watt said:
Dan,

If you use a small test attachment and just display it as text do you
get the whole file? Do you see spurious characters?

Andrew Watt
MVP - InfoPath

Hi All,

My Infopath users are going to be uploading csv files to my form and I want
to read the csv files and perform operations on them. Unfortunately, the
first line returned appears to be corrupted. Here is the code I have for
taking a File Attachment Node and converting it into a string array in C#:

IXMLDOMNode oFileAttachment = ...;
string[] arrFileContents;
try
{
byte[] byteBinaryData =
System.Convert.FromBase64String(oFileAttachment.text);

string strFileContents =
System.Text.Encoding.ASCII.GetString(byteBinaryData);

// Split the File Contents up into an array of lines
arrFileContents = strFileContents.Split('\n');
}

When I cycle through the contents of my array, the first line output says
"IFA[]" (where [] represents the square ASCII Character) no matter what the
first line is. The problem occurs before the "strFileContents.Split('\n');"
line.

So, has anyone else seen this problem and know how to fix it?

Thanks in advance.
 
D

Dan the Man

Thanks for the information.. Yes, what it appears to be is a header.. I've
been successful at removing it, however, I was wondering what the best way to
remove it might be.. Any suggestions?

Matthew Blain (Serriform) said:
the infopath attachment format is for some reason wrapped in its own binary
format.

more info:
http://tips.serriform.com/CSharpCreateInfoPathAttachment.htm
http://www.developingsolutionswithinfopath.com

--Matthew

Andrew Watt said:
Dan,

If you use a small test attachment and just display it as text do you
get the whole file? Do you see spurious characters?

Andrew Watt
MVP - InfoPath

Hi All,

My Infopath users are going to be uploading csv files to my form and I want
to read the csv files and perform operations on them. Unfortunately, the
first line returned appears to be corrupted. Here is the code I have for
taking a File Attachment Node and converting it into a string array in C#:

IXMLDOMNode oFileAttachment = ...;
string[] arrFileContents;
try
{
byte[] byteBinaryData =
System.Convert.FromBase64String(oFileAttachment.text);

string strFileContents =
System.Text.Encoding.ASCII.GetString(byteBinaryData);

// Split the File Contents up into an array of lines
arrFileContents = strFileContents.Split('\n');
}

When I cycle through the contents of my array, the first line output says
"IFA[]" (where [] represents the square ASCII Character) no matter what the
first line is. The problem occurs before the "strFileContents.Split('\n');"
line.

So, has anyone else seen this problem and know how to fix it?

Thanks in advance.
 
Top