Add an attachment using AttachableRef

Add an attachment using AttachableRef C#.NET Code

Add an attachment using AttachableRef C#.NET Code
                    
string imagePath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "\\", "Services\\Resource\\image.jpg");

System.IO.FileInfo file = new System.IO.FileInfo(imagePath);

Attachable attachable = new Attachable();

attachable.Lat = "25.293112341223";

attachable.Long = "-21.3253249834";

attachable.PlaceName = "Fake Place";

attachable.Note = "Attachable note123 ";

attachable.Tag = "Attachable tag123 ";

//

AttachableRef[] attachments = new AttachableRef[1];

AttachableRef ar = new AttachableRef();

ar.EntityRef = new ReferenceType();

ar.EntityRef.type = objectNameEnumType.Bill.ToString();

ar.EntityRef.name = objectNameEnumType.Bill.ToString();

ar.EntityRef.Value = "3";

attachments[0] = ar;

attachable.AttachableRef = attachments;

//




using (System.IO.FileStream fs = file.OpenRead())

        {

            attachable.ContentType = "image/jpeg";

            attachable.FileName = file.Name;

            Attachable attachableUploaded = commonServiceQBO.Upload(attachable, fs);

            fs.Close();

        }