Class CKApplication
Represents a Word application instance responsible for creating, managing, and closing documents in a controlled environment.
Implements
Inherited Members
Namespace: CoverageKiller2.DOM
Assembly: CoverageKiller2.dll
Syntax
public class CKApplication : IDisposable
Remarks
Version: CK2.00.00.0009
Constructors
CKApplication(Application, int, bool)
Initializes a new instance of the CKApplication class.
Declaration
public CKApplication(Application wordApp, int pid, bool isOwned = true)
Parameters
Type | Name | Description |
---|---|---|
Application | wordApp | The Word application to wrap. |
int | pid | The process ID of the Word instance. |
bool | isOwned | Whether CKOffice is responsible for cleanup. |
Properties
ActiveDocument
Gets the currently active CKDocument in the Word application, if any. Returns null if no document is active or the ActiveDocument call fails.
Declaration
public CKDocument ActiveDocument { get; }
Property Value
Type | Description |
---|---|
CKDocument |
Remarks
Version: CK2.00.01.0001
Documents
Gets all CKDocuments currently tracked by this application.
Declaration
public IReadOnlyList<CKDocument> Documents { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<CKDocument> |
HasKeepOpenDocuments
Declaration
public bool HasKeepOpenDocuments { get; }
Property Value
Type | Description |
---|---|
bool |
IsAddIn
Indicates whether this application is the VSTO ThisAddIn instance.
Declaration
public bool IsAddIn { get; }
Property Value
Type | Description |
---|---|
bool |
IsOwned
Whether this CKApplication instance is responsible for disposing the Word instance.
Declaration
public bool IsOwned { get; }
Property Value
Type | Description |
---|---|
bool |
PID
Gets the process ID of the associated Word instance.
Declaration
public string PID { get; }
Property Value
Type | Description |
---|---|
string |
Visible
Declaration
public bool Visible { get; set; }
Property Value
Type | Description |
---|---|
bool |
WordApp
Gets the raw Word application instance.
Declaration
public Application WordApp { get; }
Property Value
Type | Description |
---|---|
Application |
Methods
CloseDocument(CKDocument, bool)
Closes and removes the specified document.
Declaration
public bool CloseDocument(CKDocument doc, bool force = false)
Parameters
Type | Name | Description |
---|---|---|
CKDocument | doc | The document to close. |
bool | force | If true, attempts a force-close. Ignored if KeepAlive is true. |
Returns
Type | Description |
---|---|
bool | True if the document was closed and removed; otherwise, false. |
Dispose()
Disposes the application and optionally quits Word.
Declaration
public void Dispose()
Dispose(bool)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
GetDocument(string, bool, bool)
Opens a document from disk and wraps it in a CKDocument.
Declaration
public CKDocument GetDocument(string fullPath, bool visible = false, bool createIfNotFound = false)
Parameters
Type | Name | Description |
---|---|---|
string | fullPath | |
bool | visible | |
bool | createIfNotFound |
Returns
Type | Description |
---|---|
CKDocument |
GetShadowWorkspace(bool, bool)
Creates a ShadowWorkspace using a hidden, disposable CKDocument.
Declaration
public ShadowWorkspace GetShadowWorkspace(bool visible = false, bool keepAlive = false)
Parameters
Type | Name | Description |
---|---|---|
bool | visible | |
bool | keepAlive |
Returns
Type | Description |
---|---|
ShadowWorkspace | A new ShadowWorkspace instance. |
GetTempDocument(string, bool, bool)
Creates a temporary CKDocument based on the given file path.
Declaration
public CKDocument GetTempDocument(string fromFile = "", bool visible = false, bool keepAlive = false)
Parameters
Type | Name | Description |
---|---|---|
string | fromFile | The source file to clone. If empty, uses the default template. |
bool | visible | |
bool | keepAlive |
Returns
Type | Description |
---|---|
CKDocument | A new CKDocument instance opened in this application. |
TryGetDocumentFor(Document, out CKDocument)
Attempts to find the CKDocument instance corresponding to the given Word.Document.
Declaration
public bool TryGetDocumentFor(Document doc, out CKDocument ckDoc)
Parameters
Type | Name | Description |
---|---|---|
Document | doc | The Word document to search for. |
CKDocument | ckDoc | The matching CKDocument instance, if found. |
Returns
Type | Description |
---|---|
bool | True if found; otherwise false. |
UntrackDocument(CKDocument)
Stops tracking a disposed document.
Declaration
public bool UntrackDocument(CKDocument doc)
Parameters
Type | Name | Description |
---|---|---|
CKDocument | doc |
Returns
Type | Description |
---|---|
bool |
WithSuppressedAlerts(Action)
Executes the given action with Word alerts and macro security suppressed.
Declaration
public void WithSuppressedAlerts(Action action)
Parameters
Type | Name | Description |
---|---|---|
Action | action | The action to run with suppressed alerts. |
WithSuppressedAlerts<T>(Func<T>)
Executes a function with Word alerts and macro security suppressed, returning a result.
Declaration
public T WithSuppressedAlerts<T>(Func<T> func)
Parameters
Type | Name | Description |
---|---|---|
Func<T> | func | The function to run with suppressed alerts. |
Returns
Type | Description |
---|---|
T | The result of the function. |
Type Parameters
Name | Description |
---|---|
T | The return type. |