Example #1
0
        public void CreateNewSiteNewSQLOwner(string SiteUrl,
                                             string SiteTitle,
                                             string SiteDescription,
                                             string SiteTemplate,
                                             string OwnerFirstName,
                                             string OwnerLastName,
                                             string OwnerLogin,
                                             string OwnerPassword,
                                             string PwdQuestion,
                                             string PwdAnswer,
                                             string OwnerEmail,
                                             string AppName,
                                             string WebAppUrl,
                                             string ProviderName,
                                             uint nLCID)
        {
            SQLMembershipService SQLService = null;
            SharePointService    SPService  = null;

            try
            {
                SQLService = new SQLMembershipService();
                SPService  = new SharePointService();

                string siteownerLogin = ProviderName + ":" + OwnerLogin;
                string siteownerName  = OwnerFirstName + " " + OwnerLastName;
                string question       = PwdQuestion;
                string answer         = PwdAnswer;

                // create SQL user
                SQLService.CreateUser(AppName, OwnerLogin,
                                      OwnerPassword, OwnerEmail, question, answer, false);

                // create mapping for new site
                SQLService.CreateSiteMapping(AppName, SiteUrl);

                // set application name for sqlmembership provider.
                string oldAppName = SQLService.GetApplicationName();
                SQLService.SetApplicationName(AppName);

                //create site with user as site owner
                SPService.hstCreateSite(WebAppUrl, SiteUrl, SiteTitle, SiteDescription, nLCID, SiteTemplate,
                                        siteownerLogin, siteownerName, OwnerEmail, null, null, null, true);

                // restore application name for sqlmembership provider.
                SQLService.SetApplicationName(oldAppName);
            }
            finally
            {
                if (SQLService != null)
                {
                    SQLService.Dispose();
                }
                if (SPService != null)
                {
                    SPService.Dispose();
                }
            }
        }
Example #2
0
        public void CreateNewSiteExistingSQLOwner(string SiteUrl,
                                                  string SiteTitle,
                                                  string SiteDescription,
                                                  string SiteTemplate,
                                                  string OwnerLogin,
                                                  string AppName,
                                                  string WebAppUrl,
                                                  string ProviderName,
                                                  uint nLCID)
        {
            SQLMembershipService SQLService = null;
            SharePointService    SPService  = null;

            try
            {
                SQLService = new SQLMembershipService();
                SPService  = new SharePointService();
                string siteownerLogin = ProviderName + ":" + OwnerLogin;
                string userEmail      = String.Empty;

                // Validate sql user
                string userXml = SQLService.FindUser(AppName, OwnerLogin, false);
                if (userXml == string.Empty)
                {
                    throw new Exception("User: "******" does not exists");
                }

                XmlDocument xmlDoc = new XmlDocument();
                // Try to load the user xml into an XML document
                xmlDoc.LoadXml(userXml);

                XmlNode userNode = xmlDoc.FirstChild;

                // extract the full name and email address
                for (int i = 0; i < userNode.ChildNodes.Count; i++)
                {
                    if (userNode.ChildNodes[i].Name == "email")
                    {
                        userEmail = userNode.ChildNodes[i].InnerText;
                    }
                }

                // set application name for sqlmembership provider. This needs to be set to create a site
                string oldAppName = SQLService.GetApplicationName();
                SQLService.SetApplicationName(AppName);

                // create site with user as site owner
                SPService.hstCreateSite(WebAppUrl, SiteUrl, SiteTitle, SiteDescription, nLCID, SiteTemplate,
                                        siteownerLogin, userEmail, null, null, null, null, true);

                // create mapping for new site
                SQLService.CreateSiteMapping(AppName, SiteUrl);

                // restore application name for sqlmembership provider.
                SQLService.SetApplicationName(oldAppName);
            }
            finally
            {
                if (SQLService != null)
                {
                    SQLService.Dispose();
                }
                if (SPService != null)
                {
                    SPService.Dispose();
                }
            }
        }