How to retrieve list name from guid using .Net managed object model code in SharePoint online?

How to retrieve list name from guid using .Net managed object model code in SharePoint online?

Here we will discuss how we can get the list name from list Guid by using .net managed object model (csom) code in SharePoint online. Here we will do everything using console application and we will connect to SharePoint online site. Here we will pass a Guid of a list and it will return the name of the list in SharePoint online.

To work with .Net client object model we need below dlls:


– Microsoft.SharePoint.Client.dll

– Microsoft.SharePoint.Client.ClientRuntime.dll

We can add these dlls from Nuget package manager which I have explained in the Create console application to work with SharePoint Online Office 365 sites article.

Also you can read:

– How to check if current site is root site using .net managed object model code csom in SharePoint online?

– Step by step create a web api and deploy in Microsoft Azure for SharePoint online using visual studio 2015

Below is the method which will take the site url and Guid of the list. Here GetById method will return the list and then we can retrieve the list title property from the Title property.

 public static string GetListNameFromGUID(string URL, string GUID)

        {

            Guid guid = new Guid(GUID);

            string listName = string.Empty;

            ClientContext context = new ClientContext(URL);

            context.AuthenticationMode = ClientAuthenticationMode.Default;

            context.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());

            var web = context.Web;

            context.Load(web);

            List lst = context.Web.Lists.GetById(guid);

            context.Load(lst,l=>l.Title);

            context.ExecuteQuery();

            return lst.Title;

        }

private static SecureString GetSPOSecureStringPassword()

        {

            try

            {

                var secureString = new SecureString();

                foreach (char c in ConfigurationManager.AppSettings[“SPOPassword”])

                {

                    secureString.AppendChar(c);

                }

                return secureString;

            }

            catch

            {

                throw;

            }

        }

        private static string GetSPOAccountName()

        {

            try

            {

                return ConfigurationManager.AppSettings[“SPOAccount”];

            }

            catch

            {

                throw;

            }

        }

We can call the method like below:

string listName = GetListNameFromGUID(“https://onlysharepoint2013.sharepoint.com/sites/Bhawana/”, “C6D7A7EB-09C0-4E45-B4D8-03C523FEE16D”);

Once you run the above code, you can see the result, it will display the list name based on Guid.

How to retrieve list name from guid using .Net managed object model code in SharePoint online?
How to retrieve list name from guid using .Net managed object model code in SharePoint online?

Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

EnjoySharePoint YouTube Channel

About Bhawana Rathore

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 8+ years of SharePoint experience as well as in .Net technologies . I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools . Now exploring more in SharePoint 2016 :) Hope here I can contribute and share my knowledge to the fullest. As I believe "There is no wealth like knowledge, and no poverty like ignorance"

View all posts by Bhawana Rathore →