How can I add a link to a list item column that is of type hyperlink
. The link should be a link to a subfolder in a document library.
What the program does it creates a new subfolder in a document library and after that I need to update a sharepoint list and create a list item with the details of the newly created document library subfolder, including a hyperlink to the subfolder. The list item field/column where the hyperlink is stored is labeled as File
I am using Microsoft.SharepointOnline.CSOM
package with framework
Web web = clientContext.Web;
clientContext.Load(web, a => a.ServerRelativeUrl);
clientContext.ExecuteQuery();
// Create the subfolder in Sharepoint Document Library
Folder parentFolder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/" + parentFolderPath);
clientContext.Load(parentFolder);
clientContext.ExecuteQuery();
parentFolder.AddSubFolder(newSubFolderName, new ListItemUpdateParameters());
parentFolder.Folders.Add(newSubFolderName);
clientContext.Load(parentFolder);
clientContext.ExecuteQuery();
...
// Create a list item, need to add the hyperlink here in the field I have in my list called "File"
clientContext.Load(web.Lists,
lists => lists.Include(list => list.Title,
list => list.Id));
clientContext.ExecuteQuery();
List targetList = clientContext.Web.Lists.GetByTitle(listName);
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = targetList.AddItem(itemCreateInfo);
oListItem["File"] = ???
oListItem.Update();
clientContext.ExecuteQuery();
How can I add a link to a list item column that is of type hyperlink
. The link should be a link to a subfolder in a document library.
What the program does it creates a new subfolder in a document library and after that I need to update a sharepoint list and create a list item with the details of the newly created document library subfolder, including a hyperlink to the subfolder. The list item field/column where the hyperlink is stored is labeled as File
I am using Microsoft.SharepointOnline.CSOM
package with framework
Web web = clientContext.Web;
clientContext.Load(web, a => a.ServerRelativeUrl);
clientContext.ExecuteQuery();
// Create the subfolder in Sharepoint Document Library
Folder parentFolder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/" + parentFolderPath);
clientContext.Load(parentFolder);
clientContext.ExecuteQuery();
parentFolder.AddSubFolder(newSubFolderName, new ListItemUpdateParameters());
parentFolder.Folders.Add(newSubFolderName);
clientContext.Load(parentFolder);
clientContext.ExecuteQuery();
...
// Create a list item, need to add the hyperlink here in the field I have in my list called "File"
clientContext.Load(web.Lists,
lists => lists.Include(list => list.Title,
list => list.Id));
clientContext.ExecuteQuery();
List targetList = clientContext.Web.Lists.GetByTitle(listName);
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = targetList.AddItem(itemCreateInfo);
oListItem["File"] = ???
oListItem.Update();
clientContext.ExecuteQuery();
Share
Improve this question
asked Mar 19 at 18:08
henhenhenhen
1,2075 gold badges20 silver badges42 bronze badges
1 Answer
Reset to default 1Try this
oListItem["File"] = new FieldUrlValue
{
Url = "<your folder link here>"
Description = "My New Folder"
}
Do you face any issues?
-- update: to get the URL to the folder try this:
var newFolder = parentFolder.AddSubFolder(newSubFolderName, new ListItemUpdateParameters());
clientContext.Load(newFolder);
clientContext.ExecuteQuery();
.....
oListItem["File"] = new FieldUrlValue
{
Url = newFolder.ServerRelativeUrl
Description = "My New Folder"
}