Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get to specific List?

Status
Not open for further replies.

liorlankril

Programmer
Nov 5, 2005
46
IL
I have a web part code (in c#) that try to get to specific List that appear in several Webs (Sub areas) in the portsl. the List name is equal in all instances of the list (called "MyList").

In my code I try to search all instance of this List:

SPSite site = SPControl.GetContextSite(Context);
SPWebCollection allwebs =site.AllWebs;

foreach (SPWeb singalweb in allwebs)
{
SPListCollection lists =singalweb.Lists;
//Search the specific list ("MyList").
}

Or this code:

SPWeb MainWeb=site.AllWebs[""];
SPWebCollection webcoll=MainWeb.GetSubwebsForCurrentUser();

foreach(....){...}

The problem is:
When I arrive to Sub area (Web) with this URL:
I can find the specific list
But when the URL is type of:
(Or C1...and so)

I get a prompt of User and Password to the server.. It's like I dont have permmision to C1,C2 and so....

It's work only if I'm Administrator on the server (but I dont want all the portal's users to be Administrators on the server).

What is the solution?? How to find all instance of the specific list??
 
Try this...
Code:
foreach (SPWeb singalweb in allwebs)
            {
                foreach (SPListCollection lists in singalweb.Lists)
                {
                    foreach (SPList list in lists) 
                    {
                        if (list.Title == "MyList")
                        {
                            // do this
                        }
                    }
                }
               
            }
 
You didnt understand me..... I cant access to webs under C1 or C2... folders
 
I think you have to do 2 things:

1. instantiate the portal NOT from Context, but like
SPSite portal = new SPSite("(you can also use SPControl.Site.HostName and Site.Port etc)

2. impersonate as yourself before you do your action. If that doesnt work, try as admin. There are plenty of articles how to do that...

Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top