TAB
TAB

Reputation: 57

Save a Image using ContentService in Umbraco

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?

Upvotes: 0

Views: 855

Answers (1)

dampee
dampee

Reputation: 3437

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);  

Upvotes: 1

Related Questions