Get Project Site URL using CSOM Programmatically

Get Project Site URL using CSOM Programmatically

Get Project Site URL using CSOM Programmatically. In this post, I described you to Get Project Site URL using CSOM Programmatically. Whenever you are developing a custom web part, custom Workflow or something else, You need to get current project site URL dynamically. We also can get the current project site URL using PSI. Below is code to get current project site URL.

 Click Here to like and subscribe my channel

If you don’t know to add references in your solutions then follow the post below

Add  references in Solution

[AdSense-A]

public string GetProjectSiteUrl()
        {
            string ProjectSite = string.Empty;
            try
            {
                Guid Proj_UID = new Guid(System.Web.HttpContext.Current.Request.QueryString["ProjUid"].ToString());               
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    using (ProjectContext projContext = new ProjectContext(SPContext.Current.Web.Url))
                    {

                        projContext.Load(projContext.Projects);
                        projContext.ExecuteQuery();
                        PublishedProject pubProject = projContext.Projects.GetByGuid(Proj_UID);
                        projContext.Load(pubProject, p => p.Id, p => p.Name, p => p.ProjectSiteUrl, p => p.Tasks);
                        projContext.ExecuteQuery();
                        ProjectSite = pubProject.ProjectSiteUrl;

                    }
                });
            }
            catch (Exception ex)
            {
            }
            return ProjectSite;

        }

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!