Home
TeamSite
Deleting documents from worksite
toast
Hi guys,
so i'm trying to write some c# code that will create a new document, however if the user cancels the process prior to completion, then the document will be deleted.
What i'm basically doing is if the user cancels the process, then i'm closing the word document. Before checking the IManDocument back into worksite and I'm grabbing its document number and version and then calling the DeleteDocument method. However, after everything is done, i get an error that says :
"An error occurred in the COM add-in named 'iMan02k' Error #-2147221302
Method '~' of object #~# failed
Location: iMan02K[OnlineOps][MoveDocuementToEcho]"
The code is below (Ive already closed the Document before this). Anyone have any ideas on this? Should I be using another method to delete this document?
public void CheckInAndDeleteFileToWorksite(IManDocument myIManDocument, string fullName)
{
// get the document number and version
int documentNumber;
int documentVersion;
documentNumber = myIManDocument.Number;
documentVersion = myIManDocument.Version;
//Check in the document first
object myErrors = null;
myIManDocument.CheckIn(fullName, imCheckinDisposition.imCheckinReplaceOriginal, imCheckinOptions.imDontKeepCheckedOut, ref myErrors);
//remove the document
myIManDocument.Database.DeleteDocument(documentNumber, documentVersion);
}
Find more posts tagged with
Comments
jny
Are you using a command object, such as ImportCmd, for user to create a new document? If so, you should have to do anything when the user selects to cancel from the dialog.
Would you just explain exactly what you're trying to accomplish? And, if this is an independent application or a customization on top of a WorkSite client?
toast
Hi Jny,
We're basically re-architecting the template customisation software for word and excel integration. However, we're moving away from VBA to c#. We still have to use vba to intercept the file new as .NET does not do this (apparantly not even VSTO).
From word / excel VBA we then reference the .NET com interop and call methods on the application's facade.
So, i've written c# classes that control word. In this case, i'm just working on the create new document process from a template. When a user selects file new, the c# code opens a dialog for the user to select the appropriate template to use. Once a template is selected, I create the document and call the IManFileSaveCmd to front end profile it into Interwoven. If the user hits cancel at this stage, that's fine, no document created. However if the user hits ok, then its checked into interwoven.
I then retrieve the IManDocument from interwoven and pop up an additional display dialog for the user to put template specific information into. for example, a letter will have the details of who its to, the sending information, who its from etc.
However, if at this stage, the user cancels out from this screen (Ie no information in the template at all), we want to delete this document out of worksite straight away. So at this stage, I have the IManDocument and just really need to delete it from Interwoven. Before i can do this, I imagine that i have to close the word document, then either check the document into interwoven or undo the checkout so that there's no exclusive lock on the document. Then i can delete it from Interwoven...
In the example code i gave below, i've called my function CheckInAndDeleteFileToWorksite(IManDocument myIManDocument, string fullName)
, but if there's a better way to delete a document from Interwoven without checking it in, that would be great too.
Any thoughts?
Toast
toast
Just a quick update, i've also tried just ulocking the document and then deleting it:
myIManDocument.UnlockContent();
Instead of the checkin line
But i still get exactly the same error...
jny
I think the problem you are confronted by is that you're attempting to release the WorkSite document object before the associated Word document is closed. Since there isn't an event to catch after the document is closed, it's rather impossible to do this. At which instance are you currently calling your CheckInAndDeleteFileToWorksite function?
Is it possible to reverse the order of the operation to bring up the template input dialog first, then perform front-end profiling?
Or would it work to put the document(s) in a global collection object, then delete them on Application_Quit?