I have a created a custom list named "Hyperlink" in a team site. It has the following fields
1. Title - Single Line of text 2. Hyper - Hyperlink
I will add a new item to the custom list "Hyperlink" and set the value for the 'Hyper" field which is of field type Hyperlink.
Steps Involved:
Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run as administrator.
Go to File tab, click on New and then click on Project.
In the New Projectdialog box, expand the Visual C# node, and then select the Windows node.
In the Templates pane, select Console Application.
Enter the Name as Hyperlink and then click OK.
In the solution explorer, right click on the solution and then click on Properties.
Select the Application tab, check whether “.Net Framework 3.5” is selected for TargetFramework.
Select the Build tab, check whether “Any CPU” is selected for Platform Target.
Add the following references
Microsoft.SharePoint
Add the following namespaces
using Microsoft.SharePoint;
Replace Program.cs with the following code
C#
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.SharePoint;using System.IO; namespaceHyperlink
{ classProgram { staticvoidMain(string[] args) { using (SPSite site = new SPSite("http://serverName:11111/sites/MMS/")) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists.TryGetList("HyperLink"); if (list != null) { SPListItem item = list.Items.Add(); SPFieldUrlValue hyper = new SPFieldUrlValue(); hyper.Description = "Google"; hyper.Url = "http://www.google.com"; item["Title"] = "New item"; item["Hyper"] = hyper; item.Update(); } } } } }}
Alernate Method:
C#
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.SharePoint;using System.IO; namespaceHyperlink{ classProgram { staticvoidMain(string[] args) { using (SPSite site = new SPSite("http://serverName:11111/sites/MMS/")) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists.TryGetList("HyperLink"); if (list != null) { SPListItem item = list.Items.Add(); item["Title"] = "New item"; item["Hyper"] = "http://www.google.com, Google"; item.Update(); } } } } }}
0 comments
Comments
Join the conversation! Your thoughts help the community grow.
Join to leave a comment
Members earn 10 SHARP for a comment, 10 SHARP for a reaction, and 250 SHARP for every blog they publish.
Join the conversation! Your thoughts help the community grow.