Umbraco : How to set culture and hostnames of node programmatically .
Hello guys ,
I'm so younger user of Umbraco Cms .
I would be glad if some of you help me to solve my problem .
I have Json file , it includes all information about my content tree. After upload the file to Web API , application create content tree programmatically.
Problems begin later:
After creating any node , I would like to set the culture and hostnames programmatically .
If some of you hit on with this case , please ask me to set it.
You can set the Domain and Hostname using the DomainService
the main thing you need to do once you have a reference to the service, is to create a UmbracoDomain object and then set the domain, languageId and the Id to the content you want it to apply to (e.g your site homepage).
you need to get the language Id from the LocalizationService (see bottom)
// assuming you have worked out the languageId and
// contentNode is the node you want to set this on.
var domain = new UmbracoDomain(domainName);
domain.LanguageId = languageId;
domain.RootContentId = contentNode.Id;
domainService.Save(domain);
the languageId is the Id of the installed language on umbraco (so as they appear in the Developer/Languages - normally this will just be the order they are in (so top one is 1) but if you have added & removed languages that might not be true - so to be certain use the LocalizationServices
you can do this by culture code or Iso Language Code
// by name
var lang = _localizationService.GetLanguageByCultureCode(fName.Value);
// by iso code
var lang = _localizationService.GetLanguageByIsoCode(culture.Value);
with this you can get the id lang.Id for the first snippet of code.
Yeah unless every node is different you will probably only need to set the domain and language a few times, at the highest level for each part of the content tree.
i am not sure but i think setting the domain and language on every single node will result in quite a lot of extra data and config being stored and might impact on the performance of your site.
Umbraco : How to set culture and hostnames of node programmatically .
Hello guys ,
I'm so younger user of Umbraco Cms . I would be glad if some of you help me to solve my problem .
I have Json file , it includes all information about my content tree. After upload the file to Web API , application create content tree programmatically.
Problems begin later:
After creating any node , I would like to set the culture and hostnames programmatically .
If some of you hit on with this case , please ask me to set it.
Thank you very much ,
Best wishes!\ enter image description here
Hi
You can set the Domain and Hostname using the DomainService
the main thing you need to do once you have a reference to the service, is to create a UmbracoDomain object and then set the domain, languageId and the Id to the content you want it to apply to (e.g your site homepage).
you need to get the language Id from the LocalizationService (see bottom)
the languageId is the Id of the installed language on umbraco (so as they appear in the Developer/Languages - normally this will just be the order they are in (so top one is 1) but if you have added & removed languages that might not be true - so to be certain use the LocalizationServices
you can do this by culture code or Iso Language Code
with this you can get the id
lang.Id
for the first snippet of code.Kevin
Oh thank you , bro!
Look at this :
Can you impove this method with you top description? Add set of culture.
Hi I would have a sperate thing for the domain language, you only need set it on at one level and all the content pages below will inherit it.
I have to ask different culture for different nodes.
Hi John,
Yeah unless every node is different you will probably only need to set the domain and language a few times, at the highest level for each part of the content tree.
i am not sure but i think setting the domain and language on every single node will result in quite a lot of extra data and config being stored and might impact on the performance of your site.
is working on a reply...