Take the community feedback survey now.
AI OnAI Off
Take the community feedback survey now.
Hi,
To create a folder, you can use ContentFolder instead of ImageFile
Regards.
/Q
To create a folder you should use ContentFolder as the type argument to GetDefault<T> as
contentRepository.GetDefault<ContentFolder>(parentLink)
Thanks both, that works perfectly!
To anyone in the same boat I've thrown some rough code which will create a folder in the root if a parent content reference isn't passed and in a sub folder if it is.
//Create a Folder in the root
public ContentReference CreateFolder(string folderName)
{
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentFile = contentRepository.GetDefault<ContentFolder>(SiteDefinition.Current.GlobalAssetsRoot);
contentFile.Name = folderName;
return contentRepository.Save(contentFile, SaveAction.Publish, AccessLevel.NoAccess);
}
//Create a new folder
public ContentReference CreateFolder(string folderName, ContentReference parentReference)
{
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentFile = contentRepository.GetDefault<ContentFolder>(parentReference);
contentFile.Name = folderName;
return contentRepository.Save(contentFile, SaveAction.Publish, AccessLevel.NoAccess);
}
- Jon
Hi - I'm in the process of migrating an image importer from Epi 6R2 to Epi 7.5 and while I can successfully import images, I'm unable to programatically create new folders to put the images in.
I'd like to create a folder stucture similar to the following:
Photos\Events\Event1\photo1.jpg
Photos\Events\Event1\photo2.jpg
Photos\Events\Event2\photo1.jpg
Photos\Events\Event2\photo2.jpg
The code I use to save the images is as follows:
Thanks,
Jon