You need to sign in to do that
Don't have an account?
Pawan Agl
How to add attachment in case entity
Hi Dev
i am using sforce version 3.0 and getting problems to add an attachment file with case entity thru API only. so if u have any samples please let me know.
i badly need solution for that.
regards
pawan
Hi John B,
For your coding pleasure:
private void btnAttachment_Click(object sender, System.EventArgs e)
{
sforce.SforceService binding = new sforce.SforceService();
sforce.LoginResult lr = binding.login("user@domain.com", "password");
binding.SessionHeaderValue = new sforce.SessionHeader();
binding.SessionHeaderValue.sessionId = lr.sessionId;
binding.Url = lr.serverUrl;
//ofd is a OpenFile dialog control
ofd.ShowDialog();
string fname = ofd.FileName;
System.IO.FileInfo fi = new System.IO.FileInfo(fname);
sforce.Attachment attach = new sforce.Attachment();
attach.Name = fi.Name;
System.IO.FileStream fs = fi.OpenRead();
byte[] buf = new byte[fi.Length];
fs.Read(buf, 0, (int)fi.Length);
attach.Body = buf;
attach.ParentId = "contactid";
sforce.SaveResult[] sr = binding.create(new sforce.sObject[] {attach});
for (int i=0;i{
if (sr[i].success)
{
System.Diagnostics.Trace.WriteLine("Attachment added.");
}
else
{
System.Diagnostics.Trace.WriteLine("Error adding attachment: " + sr[i].errors[0].message);
}
}
}
Hi Deve
Thank you very much for that