Aug 28th, 2009 | 1 Comment

I have been getting good response for my post Integrating blog engine into existing site. One of the guy asked me this question on how can we do the opposite? He had a BlogEngine as parent site and needed some other site to be child of BlogEngine. So He posted on that and this is the answer he got for his question.

You need to make this change in your web.config file. If you want to have a website as child of BlogEngine

<location path="." inheritInChildApplications="false">
 <system.web>
 ..... existing content .....
 </system.web>
</location>

<location path="." inheritInChildApplications="false">
 <system.webServer>
 ..... existing content .....
 </system.webServer>
</location>

Written by Ajay Matharu

August 28th, 2009 at 11:48 pm

Jul 25th, 2009 | No Comments

Here is the way we can add item level permission for a user on an item,
SPRoleDefinition oUserRole;
SPRoleAssignment oUserRoleAssignment;
SPListItem itm;
SPSite site = null;
SPWeb web = null;
string siteUrl = Request.Url.ToString();

site = new SPSite(siteUrl);
web = site.OpenWeb();
SPGroup grp = web.Groups[groupname];

itm=web.Lists["Shared Documents"].Items[0];

oUserRole = web.RoleDefinitions.GetByType(SPRoleType.Administrator);

oUserRoleAssignment = new SPRoleAssignment(loginName, emailId, userDisplayName, notes);//for user
or
oUserRoleAssignment = new SPRoleAssignment(grp);//for group

oUserRoleAssignment.RoleDefinitionBindings.Add(oUserRole);
itm.RoleAssignments.Add(oUserRoleAssignment);
web.AllowUnsafeUpdates = true;
itm.Update();
web.Update();
web.AllowUnsafeUpdates = false;

This is useful for setting item level permission via code.

Written by Ajay Matharu

July 25th, 2009 at 12:03 pm