0% found this document useful (0 votes)
6 views2 pages

SharePointHelper Cs

Uploaded by

devi das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

SharePointHelper Cs

Uploaded by

devi das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

26/11/2024 10:26 SharePointHelper.

cs

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.SharePoint;

namespace SharePointStu.LookupField.Common
{
public static class SharePointHelper
{
#region Public Methods

/// <summary>
/// Get the list of all webs up to and including the web object provided.
/// </summary>
/// <param name="web">The web object to retrieve details of parent webs</param>
/// <returns>Dictionary list of all webs up to and including the passed web object. Key is
web Guid and Value is web title.</returns>
/// <remarks>The order of dictionary will be from the root web (first item) down to the
provided web.</remarks>
public static Dictionary<Guid, string> GetListOfWebsFromWeb(SPWeb web)
{
Dictionary<Guid, string> webs = new Dictionary<Guid, string>();

if (web == null)
return webs;

SPWeb workingWeb = web;


while (!workingWeb.IsRootWeb)
{
webs.Add(workingWeb.ID, workingWeb.Title);
workingWeb = workingWeb.ParentWeb;
}
webs.Add(workingWeb.ID, workingWeb.Title);

return webs;
}

/// <summary>
/// Get a list of all lists that match the given base type within the specified web.
/// </summary>
/// <param name="web">The web object to retrieve the lists from.</param>
/// <param name="listType">The type of lists to retrieve.</param>
/// <returns>A dictionary list of all lists for the given web that are of the specified
list type, ordered by list title.</returns>
public static Dictionary<Guid, string> GetListsForWeb(SPWeb web, SPBaseType listType)
{
Dictionary<Guid, string> lists = new Dictionary<Guid, string>();

if (web == null)
return lists;

lists = (from list in web.Lists.Cast<SPList>()


where list.BaseType == listType
orderby list.Title
select list).ToDictionary(item => item.ID, item => item.Title);

return lists;
}

/// <summary>
/// Get a list of all fields that match the given field type within the specified list.
/// </summary>
/// <param name="list">The list object to retrieve the fields from.</param>
/// <param name="fieldType">The type of fields to retrieve.</param>
/// <returns>A dictionary list of all fields for the given list that are of the specified
field type, ordered by title.</returns>
public static Dictionary<Guid, string> GetFieldsForList(SPList list, SPFieldType
fieldType)
{
file:///C:/Users/amal.bahrini/Desktop/Data cloud/drive-download-20241126T092541Z-001/SharePointHelper.cs 1/2
26/11/2024 10:26 SharePointHelper.cs
Dictionary<Guid, string> columns = new Dictionary<Guid, string>();

if (list == null)
return columns;

columns = (from field in list.Fields.Cast<SPField>()


where field.Type == fieldType
orderby field.Title
select field).ToDictionary(item => item.Id, item => item.Title);

return columns;
}

/// <summary>
/// Get a list of <see
cref="T:SharePointStu.LookupField.Common.SharePointHelper.ExtendedLookupColumnValues"/> objects
populated by the values
/// of the displayColumnId and valueColumnId columns of sourceList.
/// </summary>
/// <param name="sourceList">The list to retrieve values from.</param>
/// <param name="displayColumnId">The id of the display column.</param>
/// <param name="valueColumnId">The id of the value column.</param>
/// <returns>A list of <see
cref="T:SharePointStu.LookupField.Common.SharePointHelper.ExtendedLookupColumnValues"/> objects.
</returns>
public static List<ExtendedLookupColumnValues> GetColumnValues(SPList sourceList, Guid
displayColumnId, Guid valueColumnId)
{
List<ExtendedLookupColumnValues> items = new List<ExtendedLookupColumnValues>();

if (sourceList == null)
return items;
if (!sourceList.Fields.Contains(displayColumnId))
{
return items;
}
if (!sourceList.Fields.Contains(valueColumnId))
{
return items;
}

items = (from item in sourceList.Items.Cast<SPListItem>()


orderby item[displayColumnId]
select new ExtendedLookupColumnValues
{
Display = item[displayColumnId].ToString(),
Value = item[valueColumnId]
}
).ToList();

return items;
}

#endregion Public Methods

#region Inner Class

public class ExtendedLookupColumnValues


{
public string Display { get; set; }
public object Value { get; set; }
}

#endregion Inner Class


}
}

file:///C:/Users/amal.bahrini/Desktop/Data cloud/drive-download-20241126T092541Z-001/SharePointHelper.cs 2/2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy