Friday, August 19, 2005
Recustomize Word Document
Removing the customization from a Word document not only removes the application manifest but also the cached data. Althought it is well documented by Microsoft it still bit me.
http://msdn2.microsoft.com/library/ms185679(en-us,vs.80).aspx
For a solution it was necessary to change the reference to the customization assembly within the document. I did not want to store any data in the original document as it might contain sensitive information. I therefore created a copy of the document in the temporary folder of the current user. As I did not want to copy the customization assembly to the temporary folder and also did not want to hardcode the application path the only option left was to "recustomize" the document to reference the customization assembly in the original application folder.
/// <summary>
/// This function will recustomize the given word document
/// with the given customization assembly
/// </summary>
/// <param name="PstrDocumentFileName">
/// The name of the Word document
/// </param>
/// <param name="PstrCustomizationAssemblyFileName">
/// The customization assembly
/// </param>
private static void RecustomizeDocument(
string PstrDocumentFileName,
string PstrCustomizationAssemblyFileName)
{
// Remove the old customization
if (ServerDocument.IsCustomized(PstrDocumentFileName))
{
ServerDocument.RemoveCustomization(PstrDocumentFileName);
}
// Add the new customization
Assembly LobjCustomizationAssembly =
Assembly.LoadFile(PstrCustomizationAssemblyFileName);
string LstrCustomizationAssemblyVersion =
LobjCustomizationAssembly.GetName().Version.ToString();
bool LcbMakePathsRelative = false;
const string LcstrDeploymentManifestPath = "";
ServerDocument.AddCustomization(
PstrDocumentFileName,
PstrCustomizationAssemblyFileName,
LcstrDeploymentManifestPath,
LstrCustomizationAssemblyVersion,
LcbMakePathsRelative);
}
http://msdn2.microsoft.com/library/ms185679(en-us,vs.80).aspx
For a solution it was necessary to change the reference to the customization assembly within the document. I did not want to store any data in the original document as it might contain sensitive information. I therefore created a copy of the document in the temporary folder of the current user. As I did not want to copy the customization assembly to the temporary folder and also did not want to hardcode the application path the only option left was to "recustomize" the document to reference the customization assembly in the original application folder.
/// <summary>
/// This function will recustomize the given word document
/// with the given customization assembly
/// </summary>
/// <param name="PstrDocumentFileName">
/// The name of the Word document
/// </param>
/// <param name="PstrCustomizationAssemblyFileName">
/// The customization assembly
/// </param>
private static void RecustomizeDocument(
string PstrDocumentFileName,
string PstrCustomizationAssemblyFileName)
{
// Remove the old customization
if (ServerDocument.IsCustomized(PstrDocumentFileName))
{
ServerDocument.RemoveCustomization(PstrDocumentFileName);
}
// Add the new customization
Assembly LobjCustomizationAssembly =
Assembly.LoadFile(PstrCustomizationAssemblyFileName);
string LstrCustomizationAssemblyVersion =
LobjCustomizationAssembly.GetName().Version.ToString();
bool LcbMakePathsRelative = false;
const string LcstrDeploymentManifestPath = "";
ServerDocument.AddCustomization(
PstrDocumentFileName,
PstrCustomizationAssemblyFileName,
LcstrDeploymentManifestPath,
LstrCustomizationAssemblyVersion,
LcbMakePathsRelative);
}