最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Dynamically add hyperlink to sharepoint document library subfolder in list - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

Try 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"
}

发布评论

评论列表(0)

  1. 暂无评论