Q:

How to remove System.Web.UI.WebControls.WebParts.Part

I am trying to remove some WebParts from a page in my site collection. Normally I can do this with SPLimitedWebPartManager.DeleteWebPart(webPart) however, that will not delete System.Web.UI.WebControls.WebParts.Part nor can I cast it to a WebPart object (it returns null).
Currently I am just setting visible attribute to false, but ideally I would like to delete it.
Any suggestions?

A:

You should be able to get the WebPart object by indexer of the WebParts collection, and then pass it to DeleteWebPart method without any additional casting.
For example:
manager.DeleteWebPart(manager.WebParts[7]);

The indexer returns strongly-typed System.Web.UI.WebControls.WebParts.WebPart object, at least as it goes from the MSDN documentation, so this should work (however, didn't test it myself).

