Deleting files left behind by the Office Integration

The scenario:

  1. open Excel

  2. create a worksheet

  3. check the worksheet into CM using the Office Integration

  4. close Excel

  5. a temp file is left behind in Documents\Micro Focus CM

  6. the file is deleted the next time you open Excel (or another Office application).

The problem

The scenario described above occurs because Excel retains a handle on the file until it has completed closing, at which point the Office Integration has been unloaded and is unable to delete the file. Other Office applications (e.g. Word) release the file before they close allowing the Office Integration to delete the temp file.

A Workaround

While a future version of CM may contain a solution for this problem a work-around available today is to run a powershell script from the windows task scheduler to delete left over files.

The Script

The script below finds all files scheduled for deletion in the managed docs XML file, deletes them and removes the entry from the XML file.

$filePath = $env:APPDATA + "\Micro Focus\Content Manager\OfficeIntegration\managedDocs"

[xml]$cn = Get-Content $filePath

$cn.ArrayOfManagedDocument.ManagedDocument | ? { $_.DeleteMe -eq $true } | % { 
    Remove-Item $_.Path


The schedule

Not being an admin expert I will not tell you how to configure this script to run for all (or selected) users but I can tell you how I configured it in Windows Task Scheduler. Calling a Powershell script from Windows Task Scheduler is described in this post. In short:

  1. create a task

  2. add an action where program equals powershell.exe and arguments look something like this: -ExecutionPolicy Bypass c:\scripts\file_cleanup.ps1

  3. add a trigger

The Trigger

The trigger could be several of the available options, I chose ‘At log on’ as it was least likely to come into conflict with my use of Office.