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
Hi,
as the title says I'm trying to add an uploaded image in C# to my IContent object.
So far I have:
IContent articleContent = cs.CreateContent(H1Title, WebConfigManager.GetArtikelContainerId(), ARTICLE_ALIAS, 0);
// Create the media item
IMediaService ms = App.Helper.HelperFunctions.GetMediaService();
int mediaContainerId = WebConfigManager.GetMediaArticlesId();
IMedia mediaItem = ms.CreateMedia(H1Title, mediaContainerId, "Image");
ms.Save(mediaItem);
//Save the file and the directory
Directory.CreateDirectory(mediaRoot + "\\" + mediaContainerId + "\\" + mediaItem.Id);
IntroPictureHttpBasedFile.SaveAs(mediaRoot + "\\" + mediaContainerId + "\\" + mediaItem.Id + "\\" + IntroPictureHttpBasedFile.FileName);
//Update the umbracoFile property
string url = string.Format("/media/" + mediaContainerId + "/{0}/{1}", mediaItem.Id, IntroPictureHttpBasedFile.FileName);
mediaItem.SetValue("umbracoFile", url);
IntroPicture = url;
And now I need to know what exactly to use when I call the SetValue method on the articleContent to add the image to the uploadfield.
Anyone?
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
Programmatically set the value of an Upload Field
Hi,
as the title says I'm trying to add an uploaded image in C# to my IContent object.
So far I have:
IContent articleContent = cs.CreateContent(H1Title, WebConfigManager.GetArtikelContainerId(), ARTICLE_ALIAS, 0);
// Create the media item
IMediaService ms = App.Helper.HelperFunctions.GetMediaService();
int mediaContainerId = WebConfigManager.GetMediaArticlesId();
IMedia mediaItem = ms.CreateMedia(H1Title, mediaContainerId, "Image");
ms.Save(mediaItem);
//Save the file and the directory
Directory.CreateDirectory(mediaRoot + "\\" + mediaContainerId + "\\" + mediaItem.Id);
IntroPictureHttpBasedFile.SaveAs(mediaRoot + "\\" + mediaContainerId + "\\" + mediaItem.Id + "\\" + IntroPictureHttpBasedFile.FileName);
//Update the umbracoFile property
string url = string.Format("/media/" + mediaContainerId + "/{0}/{1}", mediaItem.Id, IntroPictureHttpBasedFile.FileName);
mediaItem.SetValue("umbracoFile", url);
ms.Save(mediaItem);
IntroPicture = url;
And now I need to know what exactly to use when I call the SetValue method on the articleContent to add the image to the uploadfield.
Anyone?
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.