SharePoint SPFile.MoveTo Workaround

Last week I wrote an EventHandler for SharePoint Team Services 2003 to route files reaching a particular document workspace into the proper folder (based on a string embedded in the filename). While writing it I found a seemingly intermittent quirk with the SPFile.MoveTo() method where sometimes the source file wouldn't be moved (at least it didn't disappear) and a 0-byte file was created at the target Url with the same name. Rewriting this as a CopyAndDelete() method seems to have solved it:

Public Sub CopyAndDelete(ByVal SharePointEventItem As SPFile, ByVal TargetUrl As String)

SharePointEventItem.CopyTo(TargetUrl, True)

Dim fc As SPFileCollection = SharePointEventItem.ParentFolder.Files

fc.Delete(SharePointEventItem.Url)

End Sub

My end-goal worked out pretty well. A user can walk up to any photopier in a branch, drop in a document, select a particular e-mail address from the list, name the document, hit Start and the document magically appears in a Client's individual folder within a SharePoint team site. The same process could be applied to attachments e-mailed from the outside world. 

These articles contributed to the solution:
- Mail Enabling SharePoint Document Libraries
- Creating Event Log Messages for a Document Library in Microsoft Windows SharePoint Services

 

No Comments