Показать сообщение отдельно
Старый 30.07.2008, 12:08   #6  
AlekseyS is offline
AlekseyS
Участник
 
77 / 13 (1) ++
Регистрация: 30.07.2008
Адрес: Киев
Вот у меня работает на account:


//Create a new annotation object, which represents the notes you see in CRM.
annotation newsgroupsNote = new annotation();

//The annotation's body. It is displayed in the notes view.
newsgroupsNote.notetext = "Don't forget send document"; // - \r\n

//The objectid specifies to which business object the annotation belongs.
newsgroupsNote.objectid = new Lookup();
newsgroupsNote.objectid.type = EntityName.account.ToString();
newsgroupsNote.objectid.Value = new Guid(context.OutputParameters.Properties["id"].ToString());

//The objecttypecode specifies the type of the parent entity. Though explicitly specified in
//the objectid property, it must be set.
newsgroupsNote.objecttypecode = new EntityNameReference();
newsgroupsNote.objecttypecode.Value = EntityName.account.ToString();

//The subject. Not displayed in the note view, but when you double click the item,
//the dialog will display it.
newsgroupsNote.subject = "You should look ready document DOZ.\r\n";
///////////////////
//// RETRIEVE ACCOUNT ASSOCIATED WITH CURRENT REQUEST


////////////////////
//
// ent.name
//
// PROCESS DOCUMENT TEMPLATE
////////////////////
//Create the annotation
ICrmService service = context.CreateCrmService(true);
Guid annotID = service.Create(newsgroupsNote);

account ent = (account)service.Retrieve(EntityName.account.ToString(),
new Guid(context.OutputParameters.Properties["id"].ToString()), new AllColumns());

StreamReader reader = new StreamReader(@"c:\upload.doc");
string input = GetBase64StringFromFile(@"c:\upload.doc");
TargetUpdateAnnotation tua = new TargetUpdateAnnotation();
annotation oAnnotation = new annotation();
Key oKey = new Key();
oKey.Value = annotID;
oAnnotation.annotationid = oKey;
oAnnotation.filename =
oAnnotation.filename = ent.name + "_doz.doc";
oAnnotation.mimetype = "application/msword";
oAnnotation.documentbody = input;
CrmNumber oNumber = new CrmNumber();
oNumber.Value = 4;
oAnnotation.filesize = oNumber;
tua.Annotation = oAnnotation;
UpdateRequest req = new UpdateRequest();
req.Target = tua;
UpdateResponse resp = (UpdateResponse) service.Execute(req);