Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Web Part's RenderWebPart() method Code Problem

  Asked By: Quinton    Date: Nov 29    Category: Sharepoint    Views: 2372

Can anyone confirm that this code does/does not work when running from a
working Web Part's RenderWebPart() method:
output.Write("<h1>" + virtualServers[0].Sites.Count.ToString() +
"</h1>");

I consistently receive this error message:
Cannot complete this action. Please try again.

The code I really want to run is this, but it fails for the same reason:
SPSiteCollection sites = virtualServer.Sites;
foreach(SPSite site in sites)
{
output.Write("--" + site.Url + "<br>");
}

I think that this may be a Microsoft Windows SharePoint Services bug,
but I need someone to confirm.

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Kory Brock     Answered On: Nov 29

Your object virtualServers is of what type? SPSite?

 
Answer #2    Answered By: Ernesto Dawson     Answered On: Nov 29

Whoops. Here is the definition for virtualServers:
SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
SPVirtualServerCollection virtualServers =
globalAdmin.VirtualServers;

Trying to keep it short and sweet for the group I left out a crucial
piece of the code, sorry. I only recently became aware that an
SPVirtualServer had an SPSiteCollection object property. I'd like to
iterate thru the entire farm but this code  is preventing me.

As a side note, it also sheds some light on why we all have to use
SPSite for the site  collection and SPWeb for each site in that
collection. But if the virtual server object isn't going to properly
implement the site collection I wish they would not have used the good
object name.

 
Answer #3    Answered By: Santiago Hood     Answered On: Nov 29

When I put it in a try/catch block and send the exception error  to the screen, I
get the following error message:

Request for the permission of type
Microsoft.SharePoint.Security.SharePointPermission,
Microsoft.SharePoint.Security, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c failed.

 
Answer #4    Answered By: Alonzo Richard     Answered On: Nov 29

Raise your trust level to Full for the test.

 
Answer #5    Answered By: Toby Singleton     Answered On: Nov 29

Now I just get the following error  message:

"Cannot complete  this action. Please try again."

 
Answer #6    Answered By: Felipe Osborne     Answered On: Nov 29

That is the same error  message that I get. Aaron said that it is working
for him. I wonder what we are doing different.

 
Didn't find what you were looking for? Find more on Web Part's RenderWebPart() method Code Problem Or get search suggestion and latest updates.




Tagged: