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 840981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:43:00+00:00 2026-05-15T05:43:00+00:00

I’m using the SharePoint 2007 object model API to assign a role to a

  • 0

I’m using the SharePoint 2007 object model API to assign a role to a SharePoint object, however when you do this, you must know the type of SharePoint object beforehand, like this:

// apply the new roleassignment to the folder.  You can do this at the listitem level   if desired (i.e. this could be SPfile.Item…. instead of SPFolder.Item)
folder.Item.RoleAssignments.Add(roleAssignment);

(code snippet from Link)

I’d like the implementation of a method that is able to pass the SharePoint object, determine the type of SharePoint object to look like this:

public static bool AssignRole(string spWebUrl, object spObject, SPUser oUser, string spRoleDefinition);

Example SharePoint object types would be: SPSite, SPWeb, SPList, SPListItem, SPField, SPFolder

Any help on how to tackle the issue of determining the type of the SharePoint object would be much appreciated.

Sidenote:
There is a way to determine the object type (sort of), if you know the full url of where the object lies in the site, although that’s really not a route I’d like to go down.

  • 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-05-15T05:43:01+00:00Added an answer on May 15, 2026 at 5:43 am

    I presume you don’t want to duplicate code?

    Instead of object why not use SPRoleAssignmentCollection ?

    AssignRole(string spWebUrl, SPRoleAssignmentCollection spAssignmentCollection, 
               SPUser oUser, string spRoleDefinition); 
    

    And you call the function as

    AssignRole(spWebUrl, spObject.RoleAssignments, oUser, spRoleDefinition); 
    

    instead of your intended

    AssignRole(spWebUrl, spObject, oUser, spRoleDefinition); 
    

    If you really really want to pass an object you have at least the following options

    • use the is keyword
    • use the GetType and TypeOf methods to compare for type identity.

    For an example of usage of above two and also their difference see: http://bytes.com/topic/c-sharp/answers/641093-difference-between-gettype-typeof-class

    I would not advise having such a method though.

    What prevents users of the method from passing in a List ?
    Now you would need an exception which is thrown (or a return value) when passed in an invalid object.

    Also, what happens if sharepoint adds new objects which can be assigned roles? If you have already shipped this code to many customers, would you now ship an update?

    Hope that helps. Good luck!

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
I know there's a lot of other questions out there that deal with this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

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.