Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'll save new content programmatically and I use this code:
private void CreateSubscription(string fullname, string company, string email, int eventId) { ContentService cs = new ContentService(); // <-- on this line var content = cs.CreateContent(_rnd.Next().ToString(), eventId, "subscription"); content.SetValue("fullname", fullname); content.SetValue("email", email); content.SetValue("company", company); cs.Save(content); }
I've taken it from here: Replay on Create new content nodes programmatically.
But this gives me this error on the marked line:
There is no argument given that corresponds to the required formal parameter provider of ContentService.ContentService(IDatabaseUnitOfWorkProvider, RepositoryFactory, ILogger, IEventMessagesFactory, IDataTypeService, IUserService)
provider
ContentService.ContentService(IDatabaseUnitOfWorkProvider, RepositoryFactory, ILogger, IEventMessagesFactory, IDataTypeService, IUserService)
What do I wrong? I'm using Umbraco 7.7.
He Hein,
There should be no need for you to create a new instance of the ContentService. Presumably you are putting this code inside a surface controller?
If you are, you can access the ContentService from the ApplicationContext.
See this documentation link for more details: https://our.umbraco.org/documentation/reference/management/services/contentservice
In the Surface Controller, all services should also be available through the Services property. This saves you having to create your own ones :-)
Hope that helps .
Nik
Access ContentService from ApplicationContent
ApplicationContext.Current.Services.ContentService
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Creation of new ContentService gives me an error
I'll save new content programmatically and I use this code:
I've taken it from here: Replay on Create new content nodes programmatically.
But this gives me this error on the marked line:
What do I wrong? I'm using Umbraco 7.7.
He Hein,
There should be no need for you to create a new instance of the ContentService. Presumably you are putting this code inside a surface controller?
If you are, you can access the ContentService from the ApplicationContext.
See this documentation link for more details: https://our.umbraco.org/documentation/reference/management/services/contentservice
In the Surface Controller, all services should also be available through the Services property. This saves you having to create your own ones :-)
Hope that helps .
Nik
Access ContentService from ApplicationContent
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.