API
Version 7.x > API > Changing Sites View modes: 
User avatar
Member
Member
JAA - 1/16/2014 4:35:21 PM
   
Changing Sites
I apologize if this question should be obvious, ive been RTFM for at least 30 minutes and Im just missing it. Im also new to the Kentico API ...

When I call CMSContext.Init() it sets my siteID to 0. How can I change sites within my program?

For example, lets say I wanted to insert an EventLogInfo into each sites Event Log. How could I get the list of sites and do this? If fine doing more reading if someone wants to point me to it.

Thanks in advance

User avatar
Kentico Legend
Kentico Legend
Accepted solutionAccepted solution
Brenden Kehren - 1/16/2014 9:45:52 PM
   
RE:Changing Sites
If you look in the database you will see the tables named
CMS_<tablename>
or
COM_<tablename>
The standard practice of the Kentico API is the <tablename> is the Info object. So if we take CMS_Site for example and create a new site object in code you'd write
SiteInfo si = new SiteInfo();
si.SiteName = "Your site name";
If you want to get or update data you use the Provider. Each <tablename>Info object has a provider.
DataSet sites = CMS.SiteProvider.SiteInfoProvider.GetAllSites();
Here is a full code example
// create a new site object
CMS.SiteProvider.SiteInfo si = new CMS.SiteProvider.SiteInfo();
si.SiteName = "MySite";
si.DisplayName = "My Site";
si.DomainName = "localhost";

// insert the site object
CMS.SiteProvider.SiteInfoProvider.SetSiteInfo(si);

//get a list of the sites
DataSet sites = CMS.SiteProvider.SiteInfoProvider.GetAllSites();
So to follow suit, look at the user table, CMS_User. The User object is UserInfo. To get user info you use the static method UserInfoProvider.GetUserInfo(56);

Good luck!
Brenden

User avatar
Member
Member
JAA - 1/17/2014 8:30:41 AM
   
RE:Changing Sites
FroggEye wrote: If you look in the database you will see the tables named
CMS_<tablename>
or
COM_<tablename>
The standard practice of the Kentico API is the <tablename> is the Info object. So if we take CMS_Site for example and create a new site object in code you'd write
SiteInfo si = new SiteInfo();
si.SiteName = "Your site name";
If you want to get or update data you use the Provider. Each <tablename>Info object has a provider.
DataSet sites = CMS.SiteProvider.SiteInfoProvider.GetAllSites();
Here is a full code example
// create a new site object
CMS.SiteProvider.SiteInfo si = new CMS.SiteProvider.SiteInfo();
si.SiteName = "MySite";
si.DisplayName = "My Site";
si.DomainName = "localhost";

// insert the site object
CMS.SiteProvider.SiteInfoProvider.SetSiteInfo(si);

//get a list of the sites
DataSet sites = CMS.SiteProvider.SiteInfoProvider.GetAllSites();
So to follow suit, look at the user table, CMS_User. The User object is UserInfo. To get user info you use the static method UserInfoProvider.GetUserInfo(56);

Good luck!
Brenden

This is great, code worked perfect, thank you.

So site 0 would be something nebulous like 'global'? When I post events to site 0, they come up in site manager Event Log, but nothing site specific. Is there a practical application for site 0?

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/17/2014 8:54:29 AM
   
RE:Changing Sites
Not that I know of. Typically 0 or -1 is the equivalent to nothing within Kentico.