2013-02-07 63 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"; 
     } 
    } 
相關問題