0

I have a Picture Library and am trying to use the CQWP to display a list of items in the library. The web part shows the items fine in authenticated mode, but it fails to show the items to anonymous users.

The error log message is: Error while executing web part: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.SetDocumentIconUrlAndOnClickString(SPWeb web, DataRow row, String strDefaultItemOpen, Boolean fSetDocIcon, Boolean fSetOnClick, String fileRefColumnRef, String progIdColumnRef, String fsobjTypeColumnRef, String permMaskColumnRef)
at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.PreProcessForDocumentIconAndOnClickAttribute()
at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.AddContentQueryData()
at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.GetXPathNavigator(String viewPath)
at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform(Boolean bDeferExecuteTransform)

I'm running SP 2010. I've tried various scenarios including: 1. Using the default publishing template. 2. Using the blank site template with publishing and lock down features enabled. 3. Using the default Images lib that comes with the Publishing feature. 4. Using a standard document library with image files uploaded (GIF files). Note: if the doc lib doesn't have any image type files, the CQWP works as expected in anonymous mode. It fails as soon as I put in an image file. 5. Using the Default item style to display the item list. 6. Using my custom item style that outputs only the SafeUrlLink and DisplayTitle.

I've been throwing myself at this for quite some time but still haven't figured it out. Please help! Thanks.

3 Answers 3

1

I ran into this issue a few weeks ago. Theres a bug in the SetDocumentIconUrlAndOnClickString() method. I reflected the web part and found a block of code that generates a script handler. I believe the issue is with the code that attempts to access the SPUser.ID property.

StringBuilder builder = new StringBuilder("DispEx(this, event, 'TRUE', 'FALSE', 'FALSE', ", 400);
builder.Append(StrJScriptParameter(str2, true));
builder.Append(StrJScriptParameter(strDefaultItemOpen, true));
builder.Append(StrJScriptParameter(str2, true));
builder.Append(StrJScriptParameter("", true));
builder.Append(StrServerFileRedirectParam(web, strFileName, strProgID));
builder.Append(StrJScriptParameter("", true));
builder.Append(StrJScriptParameter(Convert.ToString(web.CurrentUser.ID, CultureInfo.InvariantCulture), true));
builder.Append(StrJScriptParameter("0", true));
builder.Append(StrJScriptParameter("0", true));
builder.Append(StrJScriptParameter(strParam, false));
builder.Append("); return false;");

I'm assuming this is the issue as the SPWeb.CurrentUser property is null for annonymous requests.

2
  • Interesting! What did you do to resolve this?
    – Anonymous
    Jul 13, 2010 at 19:22
  • its a bug in the SharePoint code. since our site required anonymous access, I re-worked my solution to use the ECMA client object model instead of a CQWP
    – Anonymous
    Jul 13, 2010 at 20:40
0

Can you check the the images have a published version:

  1. You will need to make sure the version number is at least 1.x.
  2. Make sure that the the images moderation status is approved

An easy way to check if you can view the image as an anonymous user is to copy the image url when you are signed in then when you are looking at site as the anonymous user paste the url into your browser.

1
  • yes, all the content including images are approved and published.
    – Anonymous
    Jul 13, 2010 at 19:21
0

I found a workaround for kill this bug, this consists in inherit the CQWP and add an extra column to the resulting table containing data

public class AnonWorkingContentByQueryWebPart : ContentByQueryWebPart
 {
    protected override void OnInit(EventArgs e)
    {
       this.ProcessDataDelegate = ProcessItems;
    }

    protected virtual DataTable ProcessItems(DataTable data) 
    {
      DataColumn column = new DataColumn("OnClickForWebRendering", typeof(string));
      data.Columns.Add(column);

      return data;
    }
 }

Then you need of course to package, deploy and reference this custom class in your page(s)

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.