• edemdev
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi,

Im trying to resolve a problem Im having with Attachments. I have no problem uploading them using the API after a conversionform .txt file to a Base64 byte array but when I try to retrieve them from the SF database using  "Save as..." through the website, the file which is retrieved is still in the base64 format.

This is the conversion code I am using, which I believe may be the cause of the problem

Sample code:

            FileStream fs = new FileStream(@fileName,FileMode.Open,FileAccess.Read);
            byte[] filebytes = new byte[fs.Length];
            fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
            string encodedData = Convert.ToBase64String(filebytes,Base64FormattingOptions.InsertLineBreaks);

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            filebytes = encoding.GetBytes(encodedData);

            //Create an attachment object to send to the license
            sforce.Attachment to_attach = new sforce.Attachment();

            //Set several properties
            to_attach.Name = fileName;
            to_attach.Body = filebytes;


I have also tried adding the MIME dat a to the string for conversion  like so:

string encodedData = si:type=\"xsd:base64Binary\">" +  Convert.ToBase64String(filebytes,Base64FormattingOptions.InsertLineBreaks);

but with no sucess????

Can anyone spot any errors or give som advice???

Thanks
I am trying to query custom fields and custom objects but get the error message:

" Failed to execute wuery successfully, error message was:
  There is an error in XML Document (1,365)"

Is there something I need to do prior to using custom fields and objects?
Hi,

Im trying to resolve a problem Im having with Attachments. I have no problem uploading them using the API after a conversionform .txt file to a Base64 byte array but when I try to retrieve them from the SF database using  "Save as..." through the website, the file which is retrieved is still in the base64 format.

This is the conversion code I am using, which I believe may be the cause of the problem

Sample code:

            FileStream fs = new FileStream(@fileName,FileMode.Open,FileAccess.Read);
            byte[] filebytes = new byte[fs.Length];
            fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
            string encodedData = Convert.ToBase64String(filebytes,Base64FormattingOptions.InsertLineBreaks);

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            filebytes = encoding.GetBytes(encodedData);

            //Create an attachment object to send to the license
            sforce.Attachment to_attach = new sforce.Attachment();

            //Set several properties
            to_attach.Name = fileName;
            to_attach.Body = filebytes;


I have also tried adding the MIME dat a to the string for conversion  like so:

string encodedData = si:type=\"xsd:base64Binary\">" +  Convert.ToBase64String(filebytes,Base64FormattingOptions.InsertLineBreaks);

but with no sucess????

Can anyone spot any errors or give som advice???

Thanks
I am trying to query custom fields and custom objects but get the error message:

" Failed to execute wuery successfully, error message was:
  There is an error in XML Document (1,365)"

Is there something I need to do prior to using custom fields and objects?