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

Create custom application page in sharepoint 2007

/*******************Test.aspx*******************************/
<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>


<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
    this.Label1.Text = "Samarendra swain";
}

protected void btnSubmit_onclick(object sender, EventArgs e)
{
   this.Label1.Text = "Hi...";
   this.txtValue.Text = "click submit";
}

</script>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<h1>Testing custom application page</h1>
<asp:Label Text="Hello World" runat="server" ID="Label1"></asp:Label>
<asp:TextBox runat="server" ID="txtValue"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_onclick" />

copy this test.aspx file in this location _layouts/Test.aspx
run with this url like http://testsite/_layouts/Test.aspx
</asp:Content>
/**********************End********************************** /
Try it out and enjoy.............

Create a Custom View for Survey List

In SharePoint, custom views are used to display the items in a list/libraries with custom look and feel.Therefore you have to choose a view format like Standard View, Calendar View, Datasheet View or Gantt View and accordingly you can customize the display style by choosing Filter condition, Sort method, Group By condition etc. SharePoint allows us to create custom views for the list and libraries. But for the Survey type list, SharePoint documentation doesn't mention anything about creating a custom view.
Below mentioned steps are can be adapted to create a custom view for Survey List.

Steps-:
1.Open a SharePoint Site......Open the Survey List.
2.Find the ListID from the URL like
List=%7BF2141E9F%2D8EA2%2D42EE%2DA965%2D52F1D7362066%7D

3.Now change the URL in the browser as
http://SiteName:PortNo/_layouts/ViewType.aspx?List=%7BF2141E9F%2D8EA2%2D42EE%2DA965%2D52F1D7362066%7D

4.Then choose a view format for the survey list.

5.Type a custom View Name.

6.In the same page open the style tab, choose a style for this view e.g Basic Table (Don't set the style as Default).

7.Then press OK to create the view.

Edit the Custom View

1.Open the Survey List
2.Go to Site Action....Click on Edit page....Click on Modify Shared Web Part
3.Now click on Edit the current view
4.It will open the view .Modify the view & save it.

Check it out

Thursday, December 17, 2009

Custom EnsureUser function

The functionality of web.EnsureUser("login name") function is to resolve the user from the sharepoint site. But there might be a case where the login name you are passsing as a parameter, which does not exist in the site, then it will give you a run time error.

But this function will work like a brilliant. It will check the user and if does not exist then add that to "Home Owners" group. You can specify your own group name also.

public SPUser CustomEnsureUser(string fullName,SPWeb web)
{
SPPrincipalInfo objInfo = SPUtility.ResolvePrincipal(web, fullName, SPPrincipalType.SecurityGroup | SPPrincipalType.User, SPPrincipalSource.All, null, false);
if objInfo == null)
{
throw new SPException(SPResource.GetString("User could not be found", new object[]{objInfo.LoginName}));

}
if (objInfo.PrincipalId < 0) { web.Groups["Home Owners"].AddUser(objInfo.LoginName, objInfo.Email, objInfo.DisplayName, string.Empty); } return web.SiteUsers[objInfo.LoginName]; }

Wednesday, December 16, 2009

How to open SharePoint Group easily in Out-Of-Box functionality.

Suppose you are creating a application ,where you are creating sharepoint custom groups day by day. After some days, suppose there are 5000 custom sharepoint groups and you need to Modify settings/update users/delete users in a specific group. Then how can you go to that group easily ?

Step 1.Where ever you will see that group,just right click on that and click properties and get address url like:

http://testserver/testsite/_layouts/editprms.aspx?
obj=%7B9FD2AD57%2DB7E1%2D4C7C%2D9A7C%2DA1BB85B20AEC%7D%2C614%2CLISTITEM
&sel=17637

Step 2: Take the sel value(i.e 17637) and Type the url as the below example:
http://testserver/testsite/_layouts/people.aspx?MembershipGroupId=17637

Then you will reach that Group direcltly.

Try it out and enjoy !

Monday, December 14, 2009

Copy a folder from one list to another list programmatically.

using (SPSite site = new SPSite("http://testserver/spsite"))
{
using (SPWeb web = site.OpenWeb())
{
string sourceListUrl = "CustomList1/";
string destinationListUrl = "CustomList2/";

SPFolder rootFolder = web.GetFolder(sourceListUrl);
foreach (SPFolder objRootSubFolder in rootFolder.SubFolders)
{
if (objRootSubFolder.Name != "Forms")
{
folder = web.GetFolder(objRootSubFolder.ServerRelativeUrl);
foreach (SPFolder objFolder in folder.SubFolders)
{
objFolder.CopyTo(destinationListUrl + objRootSubFolder.Name + "/" + objFolder.Name);
}

foreach (SPFile objFile in folder.Files)
{
objFile.CopyTo(destinationListUrl + objRootSubFolder.Name + "/" + objFile.Name);
}
}
}
}
}

Delete all site groups programmatically.

SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite spSite = new SPSite("http://testserver/spsite"))
{
using (SPWeb spWeb = spSite.OpenWeb())
{
SPGroupCollection objCol = spWeb.SiteGroups;

for (int count = 0; count <= objCol.Count - 1; count++)
{
spWeb.SiteGroups.Remove(0);
}
}
}
});