Is it possible to use some built in SharePoint API to open a file no matter which web and library it's in?
Example:
Given the file: /subsiteA/PublishingImages/myimage.jpg I want to open it and get the list item, but using this fails:
var url = "/subsiteA/PublishingImages/myimage.jpg";
var file = SPContext.Current.Site.RootWeb.GetFile(url);
SPListItem item = file.GetListItem(); //Fails here with item not in library error
Naturally it will not work as the file is not located in the root web, but is there a generic way to locate the file no matter which web and library it's in and retrieve the SPListItem object related to the file?