Monday, December 04, 2006 7:34 AM
by
bsandeman
Sharepoint ItemDeleting Event
I have recently started work on handling some of the events that can happen on a form library. One of these is the ItemDeleting event. This occurs during the delete process for an item.
As the deletion of an object is part of a business process we had to copy the item to a Deleted library. This I did using properties.ListItem.File.CopyTo which worked fine until Thursday of last week when my VS solution went belly up and vapourised it's links to my ItemHandler project. Once I added my project back in this process never worked again.
I have continued to receive the following error in sharepoint logs and the event viewer -
"Cannot lock file "12.xml". Either the file is in use or the Web server is temporarily busy."
The only way I have managed to work around this is to do the following :
StreamReader r = new StreamReader(properties.ListItem.File.OpenBinaryStream());
String xml= r.ReadToEnd();
r.Dispose();
xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);
namespaceManager.AddNamespace("ns1", appParams.get("xml_namespace"));
SPWeb web = properties.ListItem.Web;
SPFolder folder = web.GetFolder("/treasury/DeletedInvoices/");
SPFileCollection fileColl = folder.Files;
SPFile file = fileColl.Add(properties.ListItem.Name,
Encoding.ASCII.GetBytes(xmlDoc.OuterXml));
This shows all my code which is actually split up nicely into functions, but hopefully this gives you the idea.