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.
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.
To remove this hyperlink follow below steps:-
1. Go to Ribbon -> List -> Modify View
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.
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
5. Choose position as noticed in step 3 and Save the Changes.
6. Now if you go back to you list, you can notice the hyperlink has been removed. Hurray!!!
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
2. Scroll down the page to read column lists. I already have a multiple lines of text column added
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)
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