From a26bdbe212c3a17628b2d6e5bda32e9d5a2bc24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Rosenthal-Buroh?= <22403655+JuergenRB@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:36:07 +0200 Subject: [PATCH] Add GetUserInformationList by language --- .../Extensions/ListExtensions.cs | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/lib/PnP.Framework/Extensions/ListExtensions.cs b/src/lib/PnP.Framework/Extensions/ListExtensions.cs index 98f54e041..b600ee72e 100644 --- a/src/lib/PnP.Framework/Extensions/ListExtensions.cs +++ b/src/lib/PnP.Framework/Extensions/ListExtensions.cs @@ -1292,32 +1292,62 @@ public static List GetListByUrl(this Web web, string webRelativeUrl, params Expr } /// - /// Gets the publishing pages library of the web based on site language + /// Gets the list of the web based on site language /// /// The web. - /// The publishing pages library. Returns null if library was not found. + /// The source. + /// The defaultResourceFile. + /// The list. Returns null if list was not found. /// - /// Could not load pages library URL name from 'cmscore' resources file. + /// Could not load list URL name from 'defaultResourceFile' resources file. /// - 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); + } + + /// + /// Gets the user information list of the web based on site language + /// + /// The web. + /// The user information list. Returns null if library was not found. + /// + /// Could not load pages library URL name from 'core' resources file. + /// + public static List GetUserInformationList(this Web web) + { + return web.GetListByLanguage("$Resources:userinfo_schema_listtitle", "core"); + } + + /// + /// Gets the publishing pages library of the web based on site language + /// + /// The web. + /// The publishing pages library. Returns null if library was not found. + /// + /// Could not load pages library URL name from 'cmscore' resources file. + /// + public static List GetPagesLibrary(this Web web) + { + return web.GetListByLanguage("$Resources:List_Pages_UrlName", "osrvcore"); } + + /// /// Gets the web relative URL. /// Allow users to get the web relative URL of a list. @@ -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();