SaaS CMS has officially launched! Learn more now.

Custom properties not working in EPI 7.5



I had the following custom property in PageTypeBuilder back in episerver 6, and have tried upgrading the solution to 7. These are now no longer showing in the editor. 

[PageTypeProperty(Type = typeof(PropertyFolderBrowser), Order =180, Tab = typeof(Content), EditCaption = "Proposal Images Folder")]

The new syntax is:

        [Display(Name = "Proposal Images Folder", Order = 180, GroupName = GroupNames.Content)]
        public virtual string ProposalImages { get; set; }

I have added the editorHint attributes on both the class and the control for the custom property, but it's not rendering. What am I doing wrong? 

I have followed this article

As this is an upgrade project, I'd rather just get things directly migrated, but because we have moved VPPs into Blobs, I suspect that we will also have issues with how we deal with the result of this selector. 

So the above will return a string folder path: /sitename/folder/path/2015/Proposal/ 

But I can't work with that anymore. The following code does not work, so how would I implement this functionality? 

                List images= new List();

                var rootFolder = HostingEnvironment.VirtualPathProvider.GetDirectory(Data.ProposalImages) as UnifiedDirectory;
                if (rootFolder != null)
                    foreach (var file in rootFolder.Files)
                        images.Add(new ProposalImage()
                            Url = (file as UnifiedFile).VirtualPath,
                            AltText = (string)(file as UnifiedFile).Summary.Dictionary["AlternativeText"] ?? "",
                            Description = (string)(file as UnifiedFile).Summary.Dictionary["Description"] ?? ""

                return images;

Thanks in advance! 


Aug 13, 2015 12:18

As you stated yourself, you have moved from the legacy file system to blobs, the folders are now instead, like everything else, content. The folders in the assets pane where you have media and blocks, are themselves content.

So to mimic this property, you would make a regular ContentReference property, and optionally (depending on what version above 7.5 you have) an AllowedTypes attribute set to 'ContentFolder'.

To ex. retrieve files from this folder you would use ContentLoader.GetChildren.

Aug 13, 2015 12:48
<p>Erik, you have saved me from my torture. The actual code I used was:&nbsp;</p> <p></p> <pre class="brush:html;auto-links:false;toolbar:false" contenteditable="false"> List&lt;ProposalImage&gt; images= new List&lt;ProposalImage&gt;(); var contentLoader = ServiceLocator.Current.GetInstance&lt;IContentLoader&gt;(); var urlResolver = ServiceLocator.Current.GetInstance&lt;UrlResolver&gt;(); var imageRefs = contentLoader.GetChildren&lt;IContent&gt;(Data.ProposalImages); foreach (var file in imageRefs) { images.Add(new ProposalImage() { Url = urlResolver.GetUrl(file.ContentLink), AltText = file.Name, Description = "" }); }</pre> <p>This is working fine now! It does mean we have to re-select the folders for each property for each page, but that's a minor task.&nbsp;</p> <p></p> <p>Thank you!</p>
Aug 13, 2015 17:03
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.