• Anupama Andripalli
  • 5 Points
  • Member since 2014

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 1
Hi, Anyone integrated bold chat with professional edition of salesfore and how was your experience?Thanks

I am trying to do the same to retreive pdf documents using c#.Here is my code and it not working as the body is not the encoded attachment string but something like "/services/data/v28.0/sobjects/Attachment/00Pi0000001UMXa/Body".
            var auth = new AuthenticationClient();
            var url = "https://test.salesforce.com/services/oauth2/token";
            await auth.UsernamePasswordAsync(CustomerKey, CustomerSecret, Username, Password, url);
            var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
                const string fName = "leaseattachment";
                const string qry = "select Name, Body, ContentType from Attachment where ParentId='a0b1100000K0TkKAAV'";
                var fields = await client.QueryAsync<LeaseAttachment>(qry);
                var fileContents = fields.records.FirstOrDefault<LeaseAttachment>();
                byte[] bName = Convert.FromBase64String(fileContents.Body);
               StreamWriter os = new StreamWriter("C:\\Users\\test\\Downloads" + "\\" + fName);
Can someone help me with it?



I am trying to download attachments from Salesforce to upload it to Sharepoint. The issue I am facing is that, the download works fine with attachments like .txt file etc, but for Word or Excel documents gives an error when trying to open the document "the document cannot be opened because there are problems with the contents". 


I am doing this via c# REST api. 


//example of word doc retrieval
string bodyData = HttpGet(token.instance_url + "/services/data/v28.0/sobjects/Attachment/00Pi0000001UMXa/Body", "");
byte[] encData_byte = System.Text.Encoding.UTF8.GetBytes(bodyData);
File.WriteAllBytes(@"c:\yourfile.docx", encData_byte);


From SF documents I understood that the string returned by querying the attachment is Base64Encoded. So in the code you need to ConvertFromBase64. But when I tried to convert the string using Convert.ToBase64String, it always gave an error saying "System.FormatException : Invalid character"


Have anyone faced something similar?