Create Project Site Programmatically Using PSI Project Server 2013

Create Project Site Programmatically Using PSI Project Server 2013

Create Project Site Programmatically Using PSI Project Server 2013. During the project creation on PWA, a Project Site is automatically created. But when we need to do some activity during project site creating, we need to Create Project Site Programmatically Using PSI. In the below code you will guide to create Workspace programmatically.

 SvcWorkflow.WorkflowDataSet workflowdataset = new SvcWorkflow.WorkflowDataSet();

SvcWorkflow= workflow service reference.If you don’t know how to add service reference then follow my post. Add PSI Web Reference in Solution file

string EPT_UID = new Guid(System.Web.HttpContext.Current.Request.QueryString["EntProjectTypeUID"]);

“EntProjectTypeUID” is query string parameter, when a project is being created.

[AdSense-A]

 static void Main(string[] args)
        {
            SvcWorkflow.WorkflowDataSet workflowdataset = new SvcWorkflow.WorkflowDataSet();
            string EPT_UID = new Guid(System.Web.HttpContext.Current.Request.QueryString["EntProjectTypeUID"]);
            workflowdataset = workflowclient.ReadEnterpriseProjectType(EPT_UID);
            string ProjectTemaplatename = workflowdataset.EnterpriseProjectType[0].ENTERPRISE_PROJECT_WORKSPACE_TEMPLATE_NAME.ToString();
        }
        public void CreateWorkSpace(Guid projectGuid, string ProjectName, string TemPlateID)
        {

            string WSSINTEROPWEBSERVICE = "/_vti_bin/PSI/WSSInterop.asmx";
            string baseUrl = SPContext.Current.Web.Url;
            WebSvcWssInterop.WssInterop wssInterop =
          new WebSvcWssInterop.WssInterop();
            try
            {
                wssInterop.Url = baseUrl + WSSINTEROPWEBSERVICE;
                wssInterop.Credentials = CredentialCache.DefaultCredentials;
                WebSvcWssInterop.WssServersDataSet dsWssServersDataSet =
                            new WebSvcWssInterop.WssServersDataSet();
                WebSvcWssInterop.WssSettingsDataSet dsWssSettingsDataSet =
                    new WebSvcWssInterop.WssSettingsDataSet();
                WebSvcWssInterop.ProjectWSSInfoDataSet dsProjectWSSInfoDataSet =
                    new WebSvcWssInterop.ProjectWSSInfoDataSet();
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    dsProjectWSSInfoDataSet = wssInterop.ReadWssData(projectGuid);
                    int rowCount = dsProjectWSSInfoDataSet.ProjWssInfo.Rows.Count;
                    if (rowCount == 0)
                    {
                        WebSvcWssInterop.WssServersDataSet dsWssServers =
                        wssInterop.ReadWssServerInfo();
                        string baseCollection = "";
                        dsWssServersDataSet = wssInterop.ReadWssServerInfo();
                        dsWssSettingsDataSet = wssInterop.ReadWssSettings();
                        WebSvcWssInterop.WssSettingsDataSet.WssAdminRow adminRow =
                        dsWssSettingsDataSet.WssAdmin[0];
                        var wssWebAppUid = adminRow.WADMIN_CURRENT_STS_SERVER_UID;
                        var templateName = TemPlateID;
                        var templateLCID = adminRow.WADMIN_STS_TEMPLATE_LCID;
                        foreach (DataRow wssServerRow in dsWssServers.WssServers)
                        {
                            if ((Guid)wssServerRow[dsWssServers.WssServers.WSTS_SERVER_UIDColumn]
                                == wssWebAppUid)
                            {
                                baseCollection = (string)
                                    wssServerRow[dsWssServers.WssServers.WSS_SERVER_URLColumn];
                                break;
                            }
                        }
                        if (!adminRow.IsWADMIN_DEFAULT_SITE_COLLECTIONNull())
                        {
                            var siteCollection = adminRow.WADMIN_DEFAULT_SITE_COLLECTION;
                        }

                        Guid wssServerUid = dsWssSettingsDataSet.WssAdmin[0].WADMIN_CURRENT_STS_SERVER_UID;
                        string wssWebFullUrl = dsWssServersDataSet.WssServers.FindByWSTS_SERVER_UID(wssServerUid).WSS_SERVER_URL
                            + "/" + dsWssSettingsDataSet.WssAdmin[0].WADMIN_DEFAULT_SITE_COLLECTION
                            + "/" + ProjectName;

                        int webTemplateLcid = 1033;
                        // If site exists then we cannot create it for this project...
                        bool SiteExists = wssInterop.WSSWebExists(wssWebFullUrl);
                        //System.Threading.Thread.Sleep(5000);
                        if (!SiteExists)
                        {
                            // This is where we create a site if we need one             
                            wssInterop.CreateWssSite(projectGuid, wssServerUid, wssWebFullUrl, webTemplateLcid, templateName);



                        }
                    }
                });

            }
            catch (Exception ex)
            { }

        }

 


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 !!