Example #1
0
        public static MsCrmResult SaveAnnotation(Annotation note, string relationName)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                IOrganizationService service = MSCRM.GetOrgService(true);

                int splitLength = note.FileName.Split('.').Length;
                note.FilePath = Guid.NewGuid() + "." + note.FileName.Split('.')[splitLength - 1].ToLower();

                returnValue = AttachmentFileHelper.CreateAttachmentFile(note, service);

                if (returnValue.Success)
                {
                    byte[] data = Convert.FromBase64String(note.File);
                    //File.WriteAllBytes(HostingEnvironment.MapPath("~/attachments") + "/" + note.FilePath, data);
                    File.WriteAllBytes(@Globals.AttachmentFolder + @"\" + note.FilePath, data);

                    note.AttachmentFile = new EntityReference("new_attachment", returnValue.CrmId);
                    returnValue         = AttachmentFileHelper.AssociateAttachmentToEntity(returnValue.CrmId, note.Object, relationName, service);
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }
            return(returnValue);
        }