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);

}

}

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);

}

}

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];

}

}

}

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);
 
}
 
}

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.......

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,

.
.
.


Thursday, January 21, 2010

Renaming the menu items in SharePoint Site Libraries and Lists for a Specific Site

In SharePoint document Library/List we find menu items like New, Uploads, Actions and Settings etc. At times there might be requirements to rename these menu items for a specific site. The following Javascript function can be used to achieve the objective.




The code snippet shown below can be called from inside the specific SharePoint Page.

e.g AllItems.aspx page inside a Document Library/List.

This javascript function needs to be called on Page load event using _spBodyOnLoadFunctionNames.push method.

<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("renameMenuItem('New', 'My New')");
_spBodyOnLoadFunctionNames.push("renameMenuItem('Settings', 'My Settings')");

function renameMenuItem(oldMenuItemName, newMenuItemName)
{

var vAnchorTag;

var vAllAnchorTags = document.getElementsByTagName('a');
if(oldMenuItemName.length!=0)

{
for (var j = 0; j < vAllAnchorTags.length; j++)

{

vAnchorTag = vAllAnchorTags[j];


if (vAnchorTag.innerText.indexOf(oldMenuItemName)!=-1)

{
vAnchorTag.innerText = newMenuItemName;
try

{

if(newMenuItemName.length != 0)

{

vAnchorTag.parentNode.previousSibling.firstChild.firstChild.alt

= newMenuItemName;


}

else
{

vAnchorTag.parentNode.previousSibling.firstChild.firstChild.alt

= oldMenuItemName;

}

}
catch(err)
{
}
}
} // End For
} // End If
}// End Function
</script>

Check it out from here: http://www.mindfiresolutions.com/Renaming-the-menu-items-in-SharePoint-Site-Libraries-and-Lists-for-a-Specific-Site-209.php
Try it out and enjoy...