Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am having a huge problem here.

I am executing a query looking for a SPListItem, when I execute this query with user identity it works well, retuning the fields "Author" and "Editor" that I need.

But when I execute the same SPQuery inside a method that is using SPSecurity.RunWithElevatedPrivileges the fields "Author" and "Editor" are not listed.

I have two instances of the same customized application, different content databases, site, but same server.

On the new web site I created a new windows user to Application Pool of this application, used as a managed account inside Sharepoint.

When I use the old user (that is wrong, because this user is computer admin, sharepoint admin, and a lot of other problems to solve talking about best pratices) the SPQuery object returns me perfectly with Author and Editor, but with the new user these fields doesn't get listed.

The Application is the same version, the site was exported and then imported back to the new site.

With the same parameters, different results, depending on RunWithElevatedPrivileges.

The code follows:

    public static SPListItem GetCaixaByID(ref SPWeb web, int idCaixa)
    {
        SPList listCaixa = web.Lists[Config.box_Caixa_ListName];
        SPQuery query = new SPQuery();
        query.Query =
        "<Where>" +
                 "<Eq><FieldRef Name='SequencialID' /><Value Type='Number'>" + idCaixa + "</Value></Eq>" +
        "</Where>";

        SPListItemCollection result = listCaixa.GetItems(query);

        return result[0];
    }

I am using SharePoint 2010.

UPDATE:

I tried using powershell using the both security contexts and the SAME problem, I think that is a security issue but I really don't know how to solve it.

I am putting a print screen of both powershells, same item, different security contexts.

Print Screen showing different security contexts responses

UPDATE 2:

I give my pool user rights on the list directly (even begin site administrator) because the list broken the security inheritance, in powershell it worked, but inside my webpart is still not coming. I think that is a security problem.

In Powershell using pool user context, they show me me this values:

RoleAssignments                    : {Microsoft.SharePoint.SPRoleAssignment, Mi
                                     crosoft.SharePoint.SPRoleAssignment}
AllRolesForCurrentUser             : {}

Using the SharePoint Administrator user, they give me this:

RoleAssignments                    : {Microsoft.SharePoint.SPRoleAssignment, Mi
                                     crosoft.SharePoint.SPRoleAssignment}
AllRolesForCurrentUser             : {Total Control, Colaboration}

-- I translated the values to english.

This item was created programatically, and has no inheritance with the list too.

The 2 roleassingments are:

PS C:\Windows\system32> $cx.RoleAssignments[0]

Member RoleDefinitionBindi Parent ParentSecurableObje ngs ct ------ ------------------- ------ ------------------- Administrators {Total Control} Microsoft.ShareP... Microsoft.ShareP...

PS C:\Windows\system32> $cx.RoleAssignments[1]

Member RoleDefinitionBindi Parent ParentSecurableObje ngs ct ------ ------------------- ------ ------------------- Colaborators CD... {Colaboration} Microsoft.ShareP... Microsoft.ShareP...

-- Translated to english

This pool user is member of Administrators group.

Even with this, I cant receive Author and Editor when querying the list under RunWithElevatedPrivileges (that uses pool user)

Any advice?

share|improve this question
    
Can you check if created and modified fields are part of default view in the target list. If you go to the list settings, at the very bottom of the page, you should see list of views, and one of them should have been marked default. Or SPList.DefaultView should give default view name. –  sssreddy Jan 17 '13 at 15:55
    
This list has no default view, this is what configuration says me. This list is just used by a webpart. No view is marked as default. –  Wagner Bertolini Junior Jan 17 '13 at 19:18
    
Any updates on this, i am facing the exact same issue now? –  Robban1980 Mar 18 at 14:38
add comment

2 Answers 2

Though I cannot explain why this is happening I can suggest using SPQuery.ViewFilelds to pass the fields you want to return? eg:

  SPQuery query = new SPQuery();
  query.Query = "your query";
  query.ViewFields = "<FieldRef Name='Author' />";
share|improve this answer
    
I was thinking about that.. but I am trying to not modify the software since it need to pass QA again.. =/ Its a environment problem, that can be solved with configuration, since it works at another instance. –  Wagner Bertolini Junior Jan 16 '13 at 19:37
    
OK I am wondering if the problem is how you elevating on PowerShell. can you try replacing your line for this one on both scripts? ([xml]$list.GetItems($spQuery)[0].xml).row.ows_Author | Out-Default | Format-Table | Out-Host we you elevating powershell run inside a function and there for it might not output all to the console (just a guess) it wont harm trying :) –  Renzo Jan 16 '13 at 20:27
    
I give my pool user rights on the list directly (even begin site administrator) because the list broken the security inheritance, in powershell it worked, but inside my webpart is still not coming. I think that is a security problem. –  Wagner Bertolini Junior Jan 17 '13 at 12:22
    
Regarding QA, this change would actually be a performance improvement, you know :) –  Alexey Krasheninnikov Jan 23 '13 at 6:15
add comment

Can you check if, Created by and Modified by fields are a part of default view in the target list.

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Muhammad Raja Jan 16 '13 at 22:09
    
This list has no default view, this is what configuration says me. This list is just used by a webpart. –  Wagner Bertolini Junior Jan 17 '13 at 12:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.