0

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?

dampee
  • 3,392
  • 1
  • 21
  • 37
TAB
  • 57
  • 4
  • 16

1 Answers1

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