2012-03-14 4 views
1

안녕하세요 여러분, CRM 2011 프로젝트의 WCF를 통해 엔티티에 첨부 파일을 보내는 방법을 알아 내려고하고 있습니다.WCF를 사용한 Dynamics CRM 2011 첨부 파일

그래서 현재 사용자가 내 서버에 pdf 파일을 업로드 할 수있는 MVC 형식을 가지고 있습니다. 이제 업로드 된 파일을보고 관련 항목/양식에 첨부하는 WCF 서비스를 원합니다.

CRM의 WCF 서비스를 참조하여 엔터티에 대한 기본 CRUD 작업을 수행 할 수 있지만 해당 엔터티에 파일을 첨부하는 방법이 확실하지 않습니다. 누군가가 올바른 방향으로 나를 가리켜 주시겠습니까?

답변

3

아래와 비슷한 코드를 사용하여 해당 파일을 읽고 데이터를 인코딩 한 다음 해당 엔티티에 첨부 된 새로운 주석을 만들 수 있습니다. 어떤 이유로 든 초기 바인딩을 사용하는 경우 늦은 바인딩을 사용했습니다. 나에게 당신이 얼마나 알려

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); 

,

감사합니다.

+0

안녕하세요, 주석 클래스의 documentbody, filename 및 mimetype 속성에 액세스하는 중에 오류가 발생했습니다. – skub

+0

아마 Attributes 컬렉션을 통해 액세스 해보십시오. annotation.Attributes [ "documentbody"]. 그들은 분명 거기에 있어야합니다. 이 기사는 해당 속성의 설정을 확인합니다. http://msdn.microsoft.com/en-us/library/gg328429.aspx. 어떻게 지내는지 알려줘. –

관련 문제