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,
I have this requirement that when I create a room type in the content section, it will automatically add the same folder in the media section. With this, how do I create a media folder using the api?
Thanks,
Sherry
Here is a sample:
Media contentFolder = Media.MakeNew("Content", MediaType.GetByAlias("folder"), User.GetUser(0), parentId);
Also have a look at this topic: http://our.umbraco.org/forum/developers/api-questions/6090-add-media-items-programmaticaly-
Jeroen
Hi Jeroen,
Here is my code
void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e){ if (sender.Parent.Text.ToUpper().Equals("FLORA GRAND HOTEL")) { int galleryID = createMediaFolder(sender, 4954); Document d = new Document(sender.Id);d.getProperty( "roomGallery").Value = createMediaFolder(sender, galleryID);}}
void
Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
{
if (sender.Parent.Text.ToUpper().Equals("FLORA GRAND HOTEL"))
int galleryID = createMediaFolder(sender, 4954);
Document d = new Document(sender.Id);
d.getProperty(
"roomGallery").Value = createMediaFolder(sender, galleryID);
}
But I'm getting an error on this before_Publish event.
Can anybody help because i'm getting an error when setting the folder id in the property. I'm getting an error that object is not set to a reference
this is my new code
void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e){ Media parentMediaFolder; Media ImageFolder; int imageFolderID = 0; Media rootFolder = new Media(4954);parentMediaFolder = Media.MakeNew(sender.Text, new MediaType(1031), UmbracoEnsuredPage.CurrentUser, rootFolder.Id);ImageFolder = Media.MakeNew("Images", new MediaType(1031), UmbracoEnsuredPage.CurrentUser, parentMediaFolder.Id);imageFolderID = ImageFolder.Id; Document d = new Document(sender.Id);d.getProperty( "roomGallery").Value = imageFolderID; }
void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
Media parentMediaFolder;
Media ImageFolder;
int imageFolderID = 0;
Media rootFolder = new Media(4954);
parentMediaFolder =
Media.MakeNew(sender.Text, new MediaType(1031), UmbracoEnsuredPage.CurrentUser, rootFolder.Id);
ImageFolder =
Media.MakeNew("Images", new MediaType(1031), UmbracoEnsuredPage.CurrentUser, parentMediaFolder.Id);
imageFolderID = ImageFolder.Id;
"roomGallery").Value = imageFolderID;
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
create media folder using api
Hi,
I have this requirement that when I create a room type in the content section, it will automatically add the same folder in the media section. With this, how do I create a media folder using the api?
Thanks,
Sherry
Here is a sample:
Also have a look at this topic: http://our.umbraco.org/forum/developers/api-questions/6090-add-media-items-programmaticaly-
Jeroen
Hi Jeroen,
Here is my code
But I'm getting an error on this before_Publish event.
Can anybody help because i'm getting an error when setting the folder id in the property. I'm getting an error that object is not set to a reference
this is my new code
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.