Friday 2 June 2017

SharePoint O365 List – Remove Hyperlink from Title Column

Hi All,
I had a requirement in my project where I had to remove the hyperlink from the Title column and add another hyperlink column with different display name like ‘View Entry’. We will see in this blog on how to achieve this
1. Remove hyperlink from Title column.
2. Add Hyperlink in ‘Multiple lines of Text’ column with different display name in list item while adding.
In this example, I have a SharePoint List with multiple columns like View, Title, Status etc. as shown in image below.
clip_image002
If you click on the any list item Title Column hyperlink, you will be navigated to DispForm page for more details of the list item as shown in image below.
clip_image004
To remove this hyperlink follow below steps:-
1. Go to Ribbon -> List -> Modify View
clip_image006
2. Scroll down the page to the place where Columns and their positions are listed.
3. Uncheck Title (linked to Item with Edit Menu) column and make a note of Position value.
clip_image008
4. Scroll down the list and notice that there are 2 more columns for Title. As we have to select column with no hyperlink, Select Title column
clip_image010
5. Choose position as noticed in step 3 and Save the Changes.
clip_image012
6. Now if you go back to you list, you can notice the hyperlink has been removed. Hurray!!!
clip_image014
Moving to our next objective – having hyperlink in ‘multiple lines of text’ column with different display name in list item.
1. Go to Ribbon -> List -> List Settings
clip_image016
2. Scroll down the page to read column lists. I already have a multiple lines of text column added
clip_image018
clip_image020
3. You may need to add this column by clicking on ‘Create Column’. Please note Type of text is – Enhanced rich text (Rich Text with pictures, tables, and hyperlinks)
clip_image022
After this is done, below is the code in C# to add hyperlink to the ‘View’ Column.
string myUrl = "https://microsoft.sharepoint.com/teams/XXX/Lists/MyListName/DispForm.aspx?ID=X";
oListItem["View"] = "<a href='" + myUrl + "'> View Entry... </a>";
The full code to add a list item in SharePoint List will look like below:-
ClientContext clientContext = new ClientContext("SPO365Url");
 
SecureString securePassword = new SecureString();
foreach (char passwordChar in "SPPassword".ToCharArray())
{
    securePassword.AppendChar(passwordChar);
}
 
clientContext.Credentials = new SharePointOnlineCredentials("SPUserName", securePassword);
Web web = clientContext.Web;
clientContext.Load(web);
List list = clientContext.Web.Lists.GetByTitle("SPListName");
 
ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem oListItem = list.AddItem(listCreationInformation);
string myUrl = "https://microsoft.sharepoint.com/teams/XXX/Lists/MyListName/DispForm.aspx?ID=X";
oListItem["View"] = "<a href='" + myUrl + "'> View Entry... </a>";
oListItem["Title"] = "SP_Issue_Title";
oListItem["Status"] = "SP_Issue_Status";
oListItem["Issue Description"] = "SP_Issue_Description";
oListItem["Action Items"] = "SP_Action_Items";
oListItem["Issue ID"] = "SP_Issue_ID";
clientContext.ExecuteQuery();
All feedback and suggestions are welcome.
Happy Coding!!!

No comments:

Post a Comment