我很清楚微软的支持基础文章说它不支持自动化办公产品UI.似乎Windows Server 2008 x64和Excel 2007强制执行给定的语句.
我在NT服务(本地系统帐户)OnStart方法中运行以下代码.当它在控制台应用程序中运行相同的代码时,它所做的只是Excel自动化.
提供的代码有两部分.第一部分启动Excel,创建一个新的工作簿并将其保存到给定的文件名.第二部分启动Excel的新实例并打开给定文件.打开操作以此异常结束:
服务无法启动.System.Runtime.InteropServices.COMException(0x800A03EC):Microsoft Office Excel无法访问文件'c:\ temp\test.xls'.有几个可能的原因:
•文件名或路径不存在.•该文件正由另一个程序使用.?您尝试保存的工作簿与当前打开的工作簿具有相同的名称.
为什么自动excel能够启动并将文件写入磁盘但是当它被要求"只是"打开现有文件时失败?
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
// launch excel and create/save a new work book
Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.UserLibraryPath, excel.Interactive));
//
string filename = "c:\\temp\\test.xls";
if(System.IO.File.Exists(filename)) System.IO.File.Delete(filename);
//
excel.Workbooks.Add(System.Reflection.Missing.Value);
excel.Save(filename);
excel.Quit();
excel = null;
// lauch new instance of excel and open saved file
excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
try
{
Microsoft.Office.Interop.Excel.Workbook book = excel.Workbooks.Open(filename,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
true,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
false,
false,
System.Reflection.Missing.Value, …Run Code Online (Sandbox Code Playgroud) 我正在使用crmsvcutil生成早期绑定类型.在crm 4.0天中,只需点击entity.ChildEntities属性即可加载相关的entites.
//Winvs.Next.Entities.CrmDataContext dc = new Entities.CrmDataContext(new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(
var cred = new System.ServiceModel.Description.ClientCredentials();
cred.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
//
using (var organizationServiceProxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(new Uri(System.Configuration.ConfigurationManager.ConnectionStrings["CrmConnection"].ConnectionString), null, cred, null))
using (Winvs.Next.Entities.CrmDataContext dc = new Entities.CrmDataContext(organizationServiceProxy))
{
// This statement is required to enable early-bound type support.
organizationServiceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new Microsoft.Xrm.Sdk.Client.ProxyTypesBehavior());
//
foreach (var a in dc.AccountSet)
{
foreach (var c in a.contact_customer_accounts)
{
c.FullName.ToString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用最新的CRM 2011 SDK版本执行此操作而不是加载已实现的实体时,我得到一个NullReferenceException,它没有提供有关该问题的进一步信息.
foreach (var c in a.contact_customer_accounts)
Run Code Online (Sandbox Code Playgroud)
我想念什么?如何使用CRM2011 Linq加载相关实体?