0

I am trying to pull data from Content Management Document library , Äpproval Status is not a actual document library column. It was enabled through Content Management Feature....

How to i access Approval Status Value from my Event Receiver (VS2010) using SPMetal?

1

spmetal will not generate the _ModerationStatus field because the field is not belong to the document contenttype.

you can simply write a partial class to add a ModerationStatus property manually

public partial class YOUR_DOCUMENT_CLASS 
{
    private System.Nullable<SPModerationStatus> _ModerationStatus;
    [Microsoft.SharePoint.Linq.ColumnAttribute(Name = "_ModerationStatus", Storage = "_ModerationStatus", FieldType = "Choice")]
    public System.Nullable<SPModerationStatus> ModerationStatus
    {
        get
        {
            return this._ModerationStatus;
        }
        set
        {
            if ((value != this._ModerationStatus))
            {
                this.OnPropertyChanging("ModerationStatus", this._ModerationStatus);
                this._ModerationStatus= value;
                this.OnPropertyChanged("ModerationStatus");
            }
        }
    }
}

public enum SPModerationStatus: int {

    None = 0,

    Invalid = 1,

    [Microsoft.SharePoint.Linq.ChoiceAttribute(Value="0")]
    Approved = 2,

    [Microsoft.SharePoint.Linq.ChoiceAttribute(Value="1")]
    Rejected = 4,

    [Microsoft.SharePoint.Linq.ChoiceAttribute(Value="2")]
    Pending = 8,

    [Microsoft.SharePoint.Linq.ChoiceAttribute(Value="3")]
    Draft = 16,

    [Microsoft.SharePoint.Linq.ChoiceAttribute(Value="4")]
    Scheduled = 32,
}

this code is write just now and then paste here, without any test, but i think it will works :), i have write some similar code in my project to get the author info, and works.

good luck

  • Hi Eric,thanks for the response. I'm always getting Invalid eventhough my Approval Status is Draft. Could you please guide me? – Jaffar Apr 27 '12 at 13:53
  • Sorry Jaffar, there's some mistake, the Value property of Microsoft.SharePoint.Linq.ChoiceAttribute should be set to the _ModerationStatus field value of SPListItem, (file.Item["_ModerationStatus"]), after check the real data, i changed the SPModerationStatus in the answer – Eric Apr 28 '12 at 6:36
0

You should be able to get the value out using a Parameter file for SPMetal like this:

<?xml version="1.0" encoding="utf-8"?>
<Web xmlns="http://schemas.microsoft.com/SharePoint/2009/spmetal">
  <List Name="Images">
     <ContentType Name="Image" Class="ImageWithStatus">
       <Column Name="_ModerationStatus" Member="ModerationStatus" />
     </ContentType>
  </List>
  <ExcludeOtherLists />
</Web>

Run SPMetal like this:

SPMetal /web:http://sp2010 /parameters:param.xml /code:test.cs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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