A: 

The only possible thing I can think of is that the file is currently checked out or locked for editing by another user. Try this...

SPWeb web = SPControl.GetContextWeb(WebPart.WebPartContext);
SPList list = web.GetList(web.Site.Url + "/ListName");
SPFile file = list.GetItemByUniqueId(new Guid(fileId)).File;

if (file.CheckOutStatus != SPFile.SPCheckOutStatus.None)
{
  file.UndoCheckOut();
  file.CheckOut();
}

file.Delete();
Fraser
Thanks for suggestion. I have tried code above and CheckOutStatus is None when I'm getting exception. It works well to delete file in SharePoint web interface, but not with API.
igorti
A: 

Are you deleting a file from a document library?

If so, you need delete whole item, because document library item cannot exist without a file. So you need to change your code this way:

SPWeb web = SPControl.GetContextWeb(WebPart.WebPartContext);
SPList list = web.GetList(web.Site.Url + "/ListName");
// delete whole item
SPListItem itemToDelete = list.GetItemByUniqueId(new Guid(fileId));
itemToDelete.Delete();

Hope it helps!

omlin