How to delete a generated web part?

S

SimeonArgus

I have generated (programmatically) a web part for my site. It was
created at user-login when the user had permissions to view the
web-part control, but the control wasn't already a part of their
viewable list.

if (/* User has permission */ ... )
{
// Load the add-on...
Control uc = this.LoadControl(DB.GetValue("AddOnFile"));
uc.ID = DB.GetValue("AddOnName");

GenericWebPart wp = MyWebPartManager.CreateWebPart(uc);
wp.Title = DB.GetValue("AddOnName");
wp.ChromeState = PartChromeState.Normal;

MyWebPartManager.AddWebPart(wp, this.AddOns, 0);
}

Now.... I've removed permissions from the user for that control for
that user. However, because they had permission to it before it is
still a part of their WebPart list for their page.

How do I programmatically remove it???
 
S

SimeonArgus

SimeonArgus said:
I have generated (programmatically) a web part for my site. It was
created at user-login when the user had permissions to view the
web-part control, but the control wasn't already a part of their
viewable list.

if (/* User has permission */ ... )
{
// Load the add-on...
Control uc = this.LoadControl(DB.GetValue("AddOnFile"));
uc.ID = DB.GetValue("AddOnName");

GenericWebPart wp = MyWebPartManager.CreateWebPart(uc);
wp.Title = DB.GetValue("AddOnName");
wp.ChromeState = PartChromeState.Normal;

MyWebPartManager.AddWebPart(wp, this.AddOns, 0);
}

Now.... I've removed permissions from the user for that control for
that user. However, because they had permission to it before it is
still a part of their WebPart list for their page.

How do I programmatically remove it???

Okay... I'm NOT a moron.. I promise. =) I was looking all over for
something under GenericWebPart to say "Delete me". However, I never
looked in WebPartManager. Here's how I pulled it off..

for (int x = 0; x < MyWebPartManager.WebParts.Count; x++)
{
if (MyWebPartManager.WebParts[x].Title ==
DB.GetValue("AddOnName"))
{
// if it is no longer enabled, destroy it.
if (DB.GetValue("Enabled") != "Y")
{

MyWebPartManager.DeleteWebPart(MyWebPartManager.WebParts[x]);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top