创建并在客户端 - 服务器系统中下载一个文本文件 [英] Create and download an text file in a client-server system
问题描述
在MS Dynamics CRM中,我将创造超过一个自己的功能区按钮与一些接触属性的文本文件。这个文件我想保存或下载到客户端计算机,使用户可以使用它。
in ms dynamics crm I will create over an own ribbon button an text file with some contact attributes. This file I would like to save or download to the client machine, so the user can work with it.
我怎样才能做到这一点?我要疯了,同时测试许多不同的方式。
How can i do this? I'm going crazy while testing a lot of different ways.
-
包含JavaScript的字符串创建并尝试与数据URI来立即下载它。这么想的工作
create with javascript an string and try to downlaod it with data uri. dosen't work
VAR内容=测试;
window.open(数据:文/八位字节流,+ EN codeURIComponent(内容));
尝试与Silverlight(localY坐标我可以创建一个文件),但远程这么想的工作
try with silverlight (localy I could create a file) but remote dosen't work
接下来的尝试是填补/用JavaScript在服务器上创建一个* .aspx文件,并创建一个文本文件。但我不知道这是工作或我可以做,否则?
next try was to fill/create with javascript an *.aspx file on the server and create a text file. But I don't know if this is working or what can i do otherwise?
请给我一些提示,以解决这个问题。
Please give me some hints to solve this problem.
推荐答案
好吧,我解决了这个问题。
Ok I solved it.
在CRM i集成的JavaScript code打开一个aspx的网站。
In crm i integrated javascript code to open an aspx site.
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 );
}
和有我创建一个电子名片,并给它回下载
and there i create a vcard and give it back to download
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";
}
}
这篇关于创建并在客户端 - 服务器系统中下载一个文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!