2013-02-07 61 views
1

in ms dynamics crm我将通过自己的功能区按钮创建具有某些联系人属性的文本文件。这个文件我想保存或下载到客户端机器,因此用户可以使用它。在客户端 - 服务器系统中创建并下载文本文件

我该怎么做?我在测试很多不同的方式时发疯。

  • 使用JavaScript创建一个字符串并尝试使用数据URI下拉它。这么想的工作

    window.open("data:text/octet-stream," + encodeURIComponent(content));

  • 尝试使用Silverlight(localy我可以创建一个文件),但远程这么想的工作

  • 下一个尝试是填补/用JavaScript创建服务器上的* .aspx文件并创建一个文本文件。但我不知道这是否有效,或者我可以做些什么?

请给我一些提示,以解决这个问题。

+0

这可能是发送包含与被加工文本的电子邮件的想法。否则,可能会添加一个Web资源并使用IFRAME的内容。文字有多大?它是什么类型的文本(纯文本,CSV,XML)?用户应该如何使用它(阅读,编辑,上传回CRM)? –

+0

用于outlook导入或发送学院等的vcf文件 – GermanSniper

+0

可能是我累了,但我不太清楚实际问题是什么。什么不工作? –

回答

0

好吧,我解决了它。

在crm我集成的JavaScript代码打开一个aspx网站。

function CreateVCF() 
{ 
    var entityName = Xrm.Page.data.entity.getEntityName(); 
    var guid = Xrm.Page.data.entity.getId(); 
    window.open("http://xxxxx/vcfexport.aspx?guid="+guid+ "&name="+entityName); 
} 

,有我创建了一个虚拟卡,并给它回下载

public partial class vcfexport : System.Web.UI.Page { 
    protected void Page_Load(object sender, EventArgs e) { 

     //Authenticate using credentials of iis  
     ClientCredentials Credentials = new ClientCredentials(); 

     Uri OrganizationUri = new Uri("http://server/org/XRMServices/2011/Organization.svc"); 
     Uri HomeRealmUri = null; 

     OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null); 

     IOrganizationService service = (IOrganizationService)serviceProxy; 

     String guidString = Request.QueryString["guid"]; 
     String entityName = Request.QueryString["name"]; 

     if (guidString != null && entityName != null && guidString != "" && entityName != "") { 

      ColumnSet columnSet = new ColumnSet(true); 
      Guid guid = new Guid(guidString); 

      // retrieve the contact dataset 
      Entity contactEntity = service.Retrieve(entityName, guid, columnSet); 

      // create new vcard 
      VCard vcard = new VCard(); 
      vcard.FirstName = contactEntity.GetAttributeValue<String>("firstname"); 
      vcard.LastName = contactEntity.GetAttributeValue<String>("lastname"); 
      //...... 

      String fileName = vcard.LastName + " " + vcard.FirstName + ".vcf"; 

      Response.ContentType = "text/x-vcard"; 
      Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); 
      // give download window 
      Response.Write(vcard.ToString()); 
      Response.End(); 


     } else { 
      lblError.Text = "Es ist ein Fehler aufgetreten. Entityname oder guid sind falsch"; 
     } 
    } 
相关问题