30.07.2008, 11:51 | #1 |
Участник
|
Проблема запуска MS WORD
Добрый день!
Подскажите столкнулся с такой проблемой: Делаю plug-ins который по событию создания нового account будет создавать документ MS Word) Code: using System; using Microsoft.Crm.Sdk; using Microsoft.Crm.SdkTypeProxy; using Microsoft.Office.Interop.Word; using Microsoft; namespace Microsoft.Crm.Sdk.Walkthrough { public class AccountCreateHandler: IPlugin { public void Execute(IPluginExecutionContext context) { DynamicEntity entity = null; #region Verify execution context // Check if the input parameters property bag contains a target // of the create operation and that target is of type DynamicEntity. if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity) { // Obtain the target business entity from the input parmameters. entity = (DynamicEntity)context.InputParameters.Properties["Target"]; // Verify that the entity represents an account. if (entity.Name != EntityName.account.ToString()) { return; } } else { return; } #endregion Verify execution context try { //System.Console.WriteLine("Opening a new Word document..."); MSWord.openDocument(); //System.Console.WriteLine("Writing stuff to the document."); MSWord.writeStuff("This is a test."); //System.Console.WriteLine("Saving the document and exiting."); MSWord.closeDocument(@"c:\done_test.doc"); } catch (System.Web.Services.Protocols.SoapException ex) { throw new Exception(ex.Detail.ToString(), ex); } } } class MSWord { public static ApplicationClass word = new ApplicationClass(); public static Document doc = null; public static void openDocument() { word.Visible = true; object file = @"C:\template.dot"; // blank path = new document object newTemplate = false; object docType = 0; object isVisible = false; // add a new document based off of the normal.dot template doc = word.Documents.Add(ref file, ref newTemplate, ref docType, ref isVisible); doc.Activate(); } public static void writeStuff(string what) { System.Console.WriteLine("Total bookmoarks: " + doc.Bookmarks.Count); foreach (Bookmark bk in doc.Bookmarks) { if (bk.Name == "testbook") { bk.Range.Text = "This is a content of bookmark"; } } doc.Tables[1].Rows[1].Cells[1].Range.Text = "Hello word"; //doc.Tables[0].Cell(0, 0).Range.Text = "hello from C#"; word.Selection.TypeText(what); } public static void closeDocument(string path) { object filePath = (object)path; object False = false; object True = true; object blank = ""; object format = WdOpenFormat.wdOpenFormatAuto; //object encoder = Office.MsoEncoding.msoEncodingUSASCII; object unicode = 65001; object missing = System.Reflection.Missing.Value; doc.SaveAs(ref filePath, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); word.Quit(ref missing, ref missing, ref missing); } } } После выполнения лог: # CRM Tracing Version 2.0 # LocalTime: 2008-07-30 00:20:40.4 # Categories: # CallStackOn: No # ComputerName: MOSS # CRMVersion: 4.0.7333.3 # DeploymentType: OnPremise # ScaleGroup: # ServerRole: AppServer, AsyncService, DiscoveryService, WebService, ApiServer, HelpServer, DeploymentService [2008-07-30 00:20:40.4] Process: w3wp |Organization:00000000-0000-0000-0000-000000000000 |Thread: 8(MSCRM:-NotificationManager.NotificationWatcherThreadProc) |Category: Exception |User: 00000000-0000-0000-0000-000000000000 |Level: Error | NotificationManager.NotificationWatcherThreadProc at NotificationManager.NotificationWatcherThreadProc() at ThreadHelper.ThreadStart_Context(Object state) at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at ThreadHelper.ThreadStart() >ThreadAbort Exception in NotificationWatcherThreadProc Thread was being aborted. [2008-07-30 00:20:40.4] Process: w3wp |Organization:00000000-0000-0000-0000-000000000000 |Thread: 8(MSCRM:-NotificationManager.NotificationWatcherThreadProc) |Category: Platform |User: 00000000-0000-0000-0000-000000000000 |Level: Error | NotificationManager.NotificationWatcherThreadProc >NotificationWatcherThreadProc Stopped. Подскажите, в чем может быть проблема. Кучу всего уже пробовал пока 0 решения. Последний раз редактировалось AlekseyS; 31.07.2008 в 13:05. |
|