如何通过自定义代码在MSCRM 4.0中的salesliterature实体上传文档?

时间:2011-04-27 11:32:44

标签: asp.net-ajax dynamics-crm dynamics-crm-4

如何通过自定义代码在MSCRM 4.0中的salesliterature实体上传文档?

任何人都可以帮我处理代码段吗?

1 个答案:

答案 0 :(得分:1)

嘿......我找到了答案......很简单......

        salesliteratureitem slsLtrItm = new salesliteratureitem();

        Lookup lookUpSalesLiteratureId = new Lookup();
        lookUpSalesLiteratureId.Value = new Guid(salesLiteratuteItem.salesliteratureid.Value.ToString());

        slsLtrItm.salesliteratureid = lookUpSalesLiteratureId;
        slsLtrItm.title = salesLiteratuteItem.title;

        //Read when the file is attached
        FileStream stream = File.OpenRead(salesLiteratuteItem.attacheddocumenturl);
        byte[] byteData = new byte[stream.Length];
        stream.Read(byteData, 0, byteData.Length);
        stream.Close();

        // Encode the data using base64.
        string encodedData = System.Convert.ToBase64String(byteData);

        //provide all required details
        slsLtrItm.documentbody = encodedData;
        slsLtrItm.filename = salesLiteratuteItem.filename;
        slsLtrItm.@abstract = salesLiteratuteItem.@abstract;
        slsLtrItm.authorname = salesLiteratuteItem.authorname;
        slsLtrItm.documentbody = salesLiteratuteItem.documentbody;
        slsLtrItm.iscustomerviewable = new CrmBoolean();
        slsLtrItm.iscustomerviewable.Value = true;
        slsLtrItm.keywords = salesLiteratuteItem.keywords;
        slsLtrItm.mimetype = salesLiteratuteItem.mimetype;

        //create salesLiteratureItem
        Guid salesLiteratureItemid = crmService.Create(slsLtrItm);