Hi,
I'm updating my projects for Umbraco v8 but I have some problems.
I'm trying to update this code that work perfectly in v7:
var contentTypeService = Current.Services.ContentTypeService;
var contentService = Current.Services.ContentService;
if (contentTypeService.GetContentType("falmHKCacheCleanup") == null)
{
// Create Document Type "falmHKCacheCleanup"
var createNewDocumentType = new ContentType(dtFalmContainer.Id)
{
Alias = "falmHKCacheCleanup",
Name = "FALM Housekeeping - Cache Directory Cleanup",
AllowedAsRoot = false,
Icon = "icon-trash color-orange"
};
contentTypeService.Save(createNewDocumentType);
Logger.Info<string>("FALM Housekeeping - Document Type 'FALM Housekeeping - Cache Directory Cleanup' successfully created");
}
else
{
Logger.Info<string>("FALM Housekeeping - Document Type 'FALM Housekeeping - Cache Directory Cleanup' already exist");
}
The problem is that in the VS2019 "Error List" panel I receive this error:
'IContentTypeService' does not contain a definition for 'GetContentType' and no accessible extension method 'GetContentType' accepting a first argument of type 'IContentTypeService' could be found (are you missing a using directive or an assembly reference?)
I tried to search a solution but I didn't find it.
You could use the GetAllContentTypeAliases() method to retrieve all of the existing content type aliases, then check if it contains the alias falmHKCacheCleanup.
Something like the following should work:
var contentTypeService = Current.Services.ContentTypeService;
var contentService = Current.Services.ContentService;
// Get all content types
var contentTypes = contentTypeService.GetAllContentTypeAliases();
// If the alias does not exist, create docType
if (!contentTypes.Contains("falmHKCacheCleanup"))
{
// Create Document Type "falmHKCacheCleanup"
var createNewDocumentType = new ContentType(dtFalmContainer.Id)
{
Alias = "falmHKCacheCleanup",
Name = "FALM Housekeeping - Cache Directory Cleanup",
AllowedAsRoot = false,
Icon = "icon-trash color-orange"
};
contentTypeService.Save(createNewDocumentType);
Logger.Info<string>("FALM Housekeeping - Document Type 'FALM Housekeeping - Cache Directory Cleanup' successfully created");
}
else
{
Logger.Info<string>("FALM Housekeeping - Document Type 'FALM Housekeeping - Cache Directory Cleanup' already exist");
}
How to get specific Content Type in umbraco v8
Hi, I'm updating my projects for Umbraco v8 but I have some problems.
I'm trying to update this code that work perfectly in v7:
The problem is that in the VS2019 "Error List" panel I receive this error:
I tried to search a solution but I didn't find it.
Can anyone help me? Thank you very much
You could use the
GetAllContentTypeAliases()
method to retrieve all of the existing content type aliases, then check if it contains the aliasfalmHKCacheCleanup
.Something like the following should work:
Thank you, it works like a charme!!!
is working on a reply...