I develop WebPart in SharePoint 2007, and sometimes when I try to delete a file from a document library with this code:
SPWeb web = SPControl.GetContextWeb(WebPart.WebPartContext);
SPList list = web.GetList(web.Site.Url + "/ListName");
SPFile file = list.GetItemByUniqueId(new Guid(fileId)).File;
file.Delete();
I get the following exception:
Cannot remove file "filename.bmp". Error Code: 3604.
Stack Trace: at Microsoft.SharePoint.Library.SPRequest.AddOrDeleteUrl (String bstrUrl, String bstrDirName, Boolean bAdd, UInt32 dwDeleteOp, Int32 iUserId, Guid & pgDeleteTOfile.polefpletelete.polefpletefpletef.polefpletef.poreleteprefpletef.poreleteprefporefpositlefp .Delete ()
The SPFile object is not zero.
Any ideas why this is happening?
source
share