大家好,我试图找出如何做的附件,通过WCF为我的CRM 2011的项目的实体。
Hi guys I am trying to figure out how to do attachments for an entity through WCF for my CRM 2011 project.
所以,目前我有MVC格式,允许用户为PDF文件上传到我的服务器。现在,我想有一个WCF服务,着眼于上传的文件,并将它们连接到相关的实体/形式。
So currently I have MVC form that allows users to upload pdf files to my server. Now I want to have a WCF service that looks at the uploaded files and attaches them to the relevant entities/forms.
我可以通过引用CRM的WCF服务上做实体基本的CRUD操作,但不知道到一个文件附加到该实体的方法。可能有人请点我朝着正确的方向?
I am able to do basic CRUD operations on the entity by referencing CRM's WCF service, but not sure on the method to attach a file to that entity. Could someone please point me in the right direction?
您可以用code类似于下面读取相应的文件,EN code中的数据,然后创建一个新的注释是附连到适当的实体。我已经使用后期绑定在这里使用的是早期以任何理由的结合情况。
you can use code similar to that below to read in the appropriate file, encode the data and then create a new annotation which is attached to the appropriate entity. I have used late binding here in case you are using early binding for any reason.
FileStream stream = File.OpenRead("pathToFile");
byte[] byteData = new byte[stream.Length];
stream.Read(byteData, 0, byteData.Length);
stream.Close();
string encodedData = System.Convert.ToBase64String(byteData);
Entity annotation = new Entity("annotation");
annotation.Attributes["subject"] = "My subject";
annotation.Attributes["notetext"] = "My note text";
EntityReference noteRef = new EntityReference();
noteRef.LogicalName = "myEntity";
noteRef.Id = myEntity.Id;
annotation.documentbody = encodedData;
annotation.filename = "myFile.doc";
annotation.mimetype = @"application\ms-word";
annotation.Attributes.Add("objectid", noteRef);
annotation.Attributes.Add("objecttypecode", "myEntity");
service.Create(annotation);
让我知道你的身体情况如何,
Let me know how you get on,
感谢。