Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8481739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:38:27+00:00 2026-06-10T19:38:27+00:00

I have code that’s pulling some images from a Sharepoint 2010 document library. When

  • 0

I have code that’s pulling some images from a Sharepoint 2010 document library. When I’m logged in and testing everything works just fine but when it’s published it forces a log in screen.

Here’s the kicker: if I reference the images through normal HTML, the published page doesn’t require a login. It’s only when I try to pull the images in and build a list of them into an asp:literal control.

The permissions on the list allow anonymous read, as far as I can tell. Something is fishy somewhere. Please help!

Below is the code I’m using:

public void GetBanners() {

string strCode = "";

using (SPSite oSite = SPContext.Current.Site) {

    SPList oList = oSite.AllWebs[0].Lists["MainPage Banner Library"];
    SPView lv = oList.Views["All Pictures"];
    SPListItemCollection lic = oList.GetItems(lv);

    foreach (SPListItem li in lic) {
        if(li["Enabled"] is bool && (bool)li["Enabled"] == true) {
            if(li["URL"] is string && li["URL"].ToString() != "") {
                strCode = strCode + "<a href=\"" + GetURL(li["URL"].ToString()) + "\" target=\"_blank\"><img src=\"/MainPage Banner Library/" + li["Name"].ToString() + "\" alt=\" \" /></a>";
            } else {
                strCode = strCode + "<img src=\"/MainPage Banner Library/" + li["Name"].ToString() + "\" alt=\" \" />";
            }

        }
    }   
}
ltBanners.Text = strCode;
}

UPDATED:
Aquila’s answer was kind of it. I wound up changing the first line to SPWeb oSite = SPContext.Current.Site.RootWeb; instead of “SPSite oSite = SPContext.Current.Site” and it worked just fine. Below is the new code:

public void GetBanners() {

string strCode = "";

    SPWeb oSite = SPContext.Current.Site.RootWeb;
    SPList oList = oSite.Lists["MainPage Banner Library"];
    SPView lv = oList.Views["All Pictures"];
    SPListItemCollection lic = oList.GetItems(lv);

    foreach (SPListItem li in lic) {
        if(li["Enabled"] is bool && (bool)li["Enabled"] == true) {
            if(li["URL"] is string && li["URL"].ToString() != "") {
                strCode = strCode + "<a href=\"" + GetURL(li["URL"].ToString()) + "\" target=\"_blank\"><img src=\"/MainPage Banner Library/" + li["Name"].ToString() + "\" alt=\" \" /></a>";
            } else {
                strCode = strCode + "<img src=\"/MainPage Banner Library/" + li["Name"].ToString() + "\" alt=\" \" />";
            }

        }
    }   

ltBanners.Text = strCode;

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:38:29+00:00Added an answer on June 10, 2026 at 7:38 pm

    It may be the line SPList oList = oSite.AllWebs[0].Lists["MainPage Banner Library"]; that is causing your problem as this needs to read all lists for the web then do a title comparison to return the list you are after.

    Try using either SPList oList = oSite.AllWebs[0].Lists[ListGUID]; or SPList oList = oSite.AllWebs[0].GetList(ServerRelativeListURL);.

    Quote from MSDN – Handling Large Folders and Lists

    Whenever possible, acquire a reference to a list by using the list’s GUID or URL as a key.

    You can retrieve an SPList object from the SPWeb.Lists property by using the list’s GUID or display name as an indexer. Using SPWeb.Lists[GUID] and SPWeb.GetList(strURL) is always preferable to using SPWeb.Lists[strDisplayName]. Using the GUID is preferable because it is unique, permanent, and requires only a single database lookup. The display name indexer retrieves the names of all the lists in the site and then does a string comparison with them. If you have a list URL instead of a GUID, you can use the GetList method in SPWeb to look up the list’s GUID in the content database before retrieving the list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that reloads images via HTTP from the main thread and displays
I have code that uses the BeautifulSoup library for parsing, but it is very
i have code that reads from a file and streams it through a label.
I have code that pics a random number from 0 to 1. I am
I have code that calculate average number of days from date opened to date
I have code that creates and invokes methods from Microsoft.Jscript objects. I'm registering on
I have code that generates a List<string[]> variable but can't quite figure out how
I have code that looks more or less like the code below but it
I have code that sends web requests through two parallel for each loops. Will
I have code that looks like this: obj.foo(); // obj might, or might not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.