using (SPSite spSite = new SPSite("http://testsite"))
{
using (SPWeb objWeb = spSite.OpenWeb())
{
SPUser objUser = objWeb.EnsureUser("manuhsolutions\\samarendra");
SPList objLst = objWeb.Lists["ListName"];
SPListItem lstItem = objLst.GetItemById(1);
// break inheriting parent permissions for this List.
lstItem.BreakRoleInheritance(false);
// assign Role to the defined User
SPRoleDefinitionCollection objWebRoleDefn = objWeb.RoleDefinitions;
SPRoleAssignment objRoleAssign = new SPRoleAssignment(objUser);
// change the name of the role definition to [Contribute]
objRoleAssign.RoleDefinitionBindings.Add(objWebRoleDefn["Contribute"]);
lstItem.RoleAssignments.Add(objRoleAssign);
}
}
Monday, February 22, 2010
70-541: Change a user's permissions to edit a list.
using (SPSite spSite = new SPSite("http://testsite/"))
{
using (SPWeb objWeb = spSite.OpenWeb())
{
SPUser objUser = objWeb.EnsureUser("manuhsolutions\\samarendra");
SPList objLst = objWeb.Lists["ListName"];
// break inheriting parent permissions for this List.
objLst.BreakRoleInheritance(false);
// assign Role to the defined User
SPRoleDefinitionCollection objWebRoleDefn = objWeb.RoleDefinitions;
SPRoleAssignment objRoleAssign = new SPRoleAssignment(objUser);
// change the name of the role definition from [Limited Access] to [Full Control]
objRoleAssign.RoleDefinitionBindings.Add(objWebRoleDefn["Full Control"]);
objLst.RoleAssignments.Add(objRoleAssign);
}
}
{
using (SPWeb objWeb = spSite.OpenWeb())
{
SPUser objUser = objWeb.EnsureUser("manuhsolutions\\samarendra");
SPList objLst = objWeb.Lists["ListName"];
// break inheriting parent permissions for this List.
objLst.BreakRoleInheritance(false);
// assign Role to the defined User
SPRoleDefinitionCollection objWebRoleDefn = objWeb.RoleDefinitions;
SPRoleAssignment objRoleAssign = new SPRoleAssignment(objUser);
// change the name of the role definition from [Limited Access] to [Full Control]
objRoleAssign.RoleDefinitionBindings.Add(objWebRoleDefn["Full Control"]);
objLst.RoleAssignments.Add(objRoleAssign);
}
}
70-541: Remove a user from a site group
using (SPSite spSite = new SPSite("http://testsite/"))
{
using (SPWeb objWeb = spSite.OpenWeb())
{
SPUser objUser = objWeb.EnsureUser("manuhsolutions/samarendra");
SPGroup objGroup = objWeb.SiteGroups["Test Group Name"];
objGroup.RemoveUser(objUser);
}
}
{
using (SPWeb objWeb = spSite.OpenWeb())
{
SPUser objUser = objWeb.EnsureUser("manuhsolutions/samarendra");
SPGroup objGroup = objWeb.SiteGroups["Test Group Name"];
objGroup.RemoveUser(objUser);
}
}
70-541: Create a custom SPQuery object.
using (SPSite spSite = new SPSite("http://testsite/"))
{
using (SPWeb objWeb = spSite.OpenWeb())
{
SPList objList = objWeb.GetList(objWeb.Url + "/Lists/" + "ListName");
SPQuery query = new SPQuery();
query.RowLimit = 10;
query.Query = "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + "Samarendra" + "</Value></Eq></Where>";
SPListItemCollection itemColl = objList.GetItems(query);
if (itemColl.Count > 0)
{
SPListItem lstItem = itemColl[0];
}
}
}
{
using (SPWeb objWeb = spSite.OpenWeb())
{
SPList objList = objWeb.GetList(objWeb.Url + "/Lists/" + "ListName");
SPQuery query = new SPQuery();
query.RowLimit = 10;
query.Query = "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + "Samarendra" + "</Value></Eq></Where>";
SPListItemCollection itemColl = objList.GetItems(query);
if (itemColl.Count > 0)
{
SPListItem lstItem = itemColl[0];
}
}
}
70-541: Add a user to a site group
using (SPSite objSite= new SPSite("http://testsite/"))
{
using (SPWeb objWeb = objSite.OpenWeb())
{
SPUser objUser = objWeb.EnsureUser("manuhsolutions\\samarendra");
SPGroup objGroup = objWeb.SiteGroups["Test Group Name"];
objGroup.AddUser(objUser);
}
}
{
using (SPWeb objWeb = objSite.OpenWeb())
{
SPUser objUser = objWeb.EnsureUser("manuhsolutions\\samarendra");
SPGroup objGroup = objWeb.SiteGroups["Test Group Name"];
objGroup.AddUser(objUser);
}
}
Wednesday, February 10, 2010
How to increase the size limitation while you save site as template include content in MOSS 2007
By using the STSADM command , you can maximize the size limitation while you wish to save site as template include the content.
command:
stsadm -o setproperty -pn max-template-document-size -pv 52428800
(52428800 is in byte format which is equal to 50 Mega Byte)
enjoy.......
command:
stsadm -o setproperty -pn max-template-document-size -pv 52428800
(52428800 is in byte format which is equal to 50 Mega Byte)
enjoy.......
Friday, February 5, 2010
Displaying alert message while saving a infopath form.
You might have marked that, in each and every infopath form, there are two buttons 'save and close'. There might be requirement for displaying a alert message on the click event of the save button.
To achive this , open the core.js file from this location \Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\INC and serach Toolbar.ExecuteAction and update the script by looking to the below script.
.
.
.
.
.
Toolbar.ExecuteAction = function(strAction, objEvent)
{if (!BaseControl.CanHandleEvents())
{return;}
switch(strAction)
{case ("refresh"):
{if (document.forms[0] != null)
{View_SubmitForm(false , 24, 0, false );}
break;}
case ("submit"):
{if (View.PreSubmitActions())
{EventLog_Add(
9,
null,
"",
"",
"",
true ,
false ,
false ,
9,
0);}
break;}
case ("view"):
{;
break;}
case ("save"):
{EventLog_Add(
14,
null,
"",
false,
false,
true ,
false ,
false ,
10,
0);alert('Data Saved Successfully');
break;}
case ("saveAs"):
{EventLog_Add(
14,
.
.
.
To achive this , open the core.js file from this location \Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\INC and serach Toolbar.ExecuteAction and update the script by looking to the below script.
.
.
.
.
.
Toolbar.ExecuteAction = function(strAction, objEvent)
{if (!BaseControl.CanHandleEvents())
{return;}
switch(strAction)
{case ("refresh"):
{if (document.forms[0] != null)
{View_SubmitForm(false , 24, 0, false );}
break;}
case ("submit"):
{if (View.PreSubmitActions())
{EventLog_Add(
9,
null,
"",
"",
"",
true ,
false ,
false ,
9,
0);}
break;}
case ("view"):
{;
break;}
case ("save"):
{EventLog_Add(
14,
null,
"",
false,
false,
true ,
false ,
false ,
10,
0);alert('Data Saved Successfully');
break;}
case ("saveAs"):
{EventLog_Add(
14,
.
.
.
Subscribe to:
Posts (Atom)