I want to add a image using contentservice in umbraco , can it bo done simply using setValue method, what do I need to pass to the setValue Method?
Asked
Active
Viewed 829 times
1 Answers
1
You should use the MediaService instead of the contentservice.
// check ApplicationContext.Current != null
var ms = ApplicationContext.Current.Services.MediaService;
var newMediaItem = ms.CreateMedia(file.FileName, <parentId>, Constants.Conventions.MediaTypes.Image);
newMediaItem.SetValue(Constants.Conventions.Media.File, file);
ms.Save(newMediaItem);

dampee
- 3,392
- 1
- 21
- 37
-
`ms.Save(mimage);` ? I think "mimage" here should be "newMediaItem". – harvzor Mar 14 '16 at 11:30