Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-1062 Add GetUserInformationList by language #1063

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions src/lib/PnP.Framework/Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,32 +1292,62 @@ public static List GetListByUrl(this Web web, string webRelativeUrl, params Expr
}

/// <summary>
/// Gets the publishing pages library of the web based on site language
/// Gets the list of the web based on site language
/// </summary>
/// <param name="web">The web.</param>
/// <returns>The publishing pages library. Returns null if library was not found.</returns>
/// <param name="source">The source.</param>
/// <param name="defaultResourceFile">The defaultResourceFile.</param>
/// <returns>The list. Returns null if list was not found.</returns>
/// <exception cref="System.InvalidOperationException">
/// Could not load pages library URL name from 'cmscore' resources file.
/// Could not load list URL name from 'defaultResourceFile' resources file.
/// </exception>
public static List GetPagesLibrary(this Web web)
private static List GetListByLanguage(this Web web, string source, string defaultResourceFile)
{
if (web == null) throw new ArgumentNullException(nameof(web));

var context = web.Context;
int language = (int)web.EnsureProperty(w => w.Language);

var result = Utilities.Utility.GetLocalizedString(context, "$Resources:List_Pages_UrlName", "osrvcore", language);
var result = Utilities.Utility.GetLocalizedString(context, source, defaultResourceFile, language);
context.ExecuteQueryRetry();
string pagesLibraryName = new Regex(@"['´`]").Replace(result.Value, "");
string listName = new Regex(@"['´`]").Replace(result.Value, "");

if (string.IsNullOrEmpty(pagesLibraryName))
if (string.IsNullOrEmpty(listName))
{
throw new InvalidOperationException("Could not load pages library URL name from 'cmscore' resources file.");
throw new InvalidOperationException($"Could not load list URL name from '{defaultResourceFile}' resources file.");
}

return web.GetListByUrl(pagesLibraryName) ?? web.GetListByTitle(pagesLibraryName);
return web.GetListByUrl(listName) ?? web.GetListByTitle(listName);
}

/// <summary>
/// Gets the user information list of the web based on site language
/// </summary>
/// <param name="web">The web.</param>
/// <returns>The user information list. Returns null if library was not found.</returns>
/// <exception cref="System.InvalidOperationException">
/// Could not load pages library URL name from 'core' resources file.
/// </exception>
public static List GetUserInformationList(this Web web)
{
return web.GetListByLanguage("$Resources:userinfo_schema_listtitle", "core");
}

/// <summary>
/// Gets the publishing pages library of the web based on site language
/// </summary>
/// <param name="web">The web.</param>
/// <returns>The publishing pages library. Returns null if library was not found.</returns>
/// <exception cref="System.InvalidOperationException">
/// Could not load pages library URL name from 'cmscore' resources file.
/// </exception>
public static List GetPagesLibrary(this Web web)
{
return web.GetListByLanguage("$Resources:List_Pages_UrlName", "osrvcore");
}



/// <summary>
/// Gets the web relative URL.
/// Allow users to get the web relative URL of a list.
Expand Down Expand Up @@ -2332,7 +2362,7 @@ public static void EnableModernAudienceTargeting(this List list)
Field firstField = list.Fields.AddFieldAsXml(firstModernTargetingFieldXml, false, addOptions);
list.Context.Load(firstField);

var userInformationList = web.Lists.GetByTitle("User Information List");
var userInformationList = web.GetUserInformationList();
list.Context.Load(userInformationList, l => l.Id);
list.Context.ExecuteQueryRetry();

Expand Down