Blog posts by Anders Hattestad
2016-04-12T07:33:55.0000000Z
/blogs/Anders-Hattestad/
Optimizely World
Light logging of time used in Controller and View
/blogs/Anders-Hattestad/Dates/2016/4/light-logging-of-time-used-in-controller-and-view/
2016-04-12T07:33:55.0000000Z
<p>There are great tool available for logging user actions on your site like google analytic, but sometimes you want to know more about how much time a controller used, and how much time the view rendering took. If one creates a ActionFilterAttribute and tag your controller with it it’s possible to get that kind of information easy.</p> <p> <p>You tag your controller like this</p> <pre class="language-csharp"><code> [TrackTimeActionFilter]
<span class="kwrd">public</span> <span class="kwrd">class</span> SearchPageController : PageController<SearchPage>
{</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
<p>The you create a TrackTimeActionFilter</p>
<pre class="language-csharp"><code> <span class="kwrd">public</span> <span class="kwrd">class</span> TrackTimeActionFilter : ActionFilterAttribute
{
Stopwatch stopWatch0;
Stopwatch stopWatch1;
Stopwatch stopWatch2;
<span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnActionExecuting(ActionExecutingContext filterContext)
{
stopWatch0 = <span class="kwrd">new</span> Stopwatch();
stopWatch1 = <span class="kwrd">new</span> Stopwatch();
stopWatch0.Start();
stopWatch1.Start();
}
<span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnActionExecuted(ActionExecutedContext filterContext)
{
stopWatch1.Stop();
<span class="rem">// Log("OnActionExecuted", filterContext.RouteData);</span>
}
<span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnResultExecuting(ResultExecutingContext filterContext)
{
stopWatch2 = <span class="kwrd">new</span> Stopwatch();
stopWatch2.Start();
}
<span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnResultExecuted(ResultExecutedContext filterContext)
{
stopWatch0.Stop();
stopWatch2.Stop();
Log(filterContext.RouteData, stopWatch0.ElapsedMilliseconds, stopWatch1.ElapsedMilliseconds, stopWatch2.ElapsedMilliseconds, filterContext.HttpContext);
}
<span class="kwrd">private</span> <span class="kwrd">void</span> Log(RouteData routeData, <span class="kwrd">long</span> timeTotal, <span class="kwrd">long</span> timeController, <span class="kwrd">long</span> timeRenderView, HttpContextBase context)
{
var service = ServiceLocator.Current.GetInstance<ContentActionStoreService>();
<span class="kwrd">if</span> (service.IsEnabled && !EPiServer.Editor.PageEditing.PageIsInEditMode)
{
<span class="kwrd">try</span> {
var add = CreateEntity(routeData);
<span class="kwrd">if</span> (add != <span class="kwrd">null</span>)
{
var userNameOrSessionId = context.Session.SessionID;
<span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(context.User.Identity.Name))
userNameOrSessionId = context.User.Identity.Name;
var ip = GetUsersIp(context.Request);
IGeolocationResult geo = <span class="kwrd">null</span>;
<span class="kwrd">if</span> (ip != IPAddress.None)
geo = GetCurrentUsersLocation(ip);
add.SiteReference = ContentReference.StartPage.ToReferenceWithoutVersion().ToString();
add.MachineName = System.Environment.MachineName;
add.TotalMilliSeconds = timeTotal;
add.ControllerMilliSeconds = timeController;
add.ViewMilliSeconds = timeRenderView;
add.Viewed = DateTime.Now;
add.IpAdress = <span class="str">""</span> + ip;
add.RawUrl = context.Request.RawUrl;
<span class="kwrd">if</span> (context.Request.UrlReferrer!=<span class="kwrd">null</span>)
{
add.UrlReferrer = <span class="str">""</span> + context.Request.UrlReferrer;
var url = <span class="kwrd">new</span> EPiServer.UrlBuilder(context.Request.UrlReferrer);
var fromContent = UrlResolver.Current.Route(<span class="kwrd">new</span> EPiServer.UrlBuilder(context.Request.UrlReferrer));
<span class="kwrd">if</span> (fromContent==<span class="kwrd">null</span>)
fromContent = UrlResolver.Current.Route(<span class="kwrd">new</span> EPiServer.UrlBuilder(context.Request.UrlReferrer.PathAndQuery));
<span class="kwrd">if</span> (fromContent!=<span class="kwrd">null</span>)
{
add.ReferrerReferenceWithoutVersion = fromContent.ContentLink.ToReferenceWithoutVersion().ToString();
<span class="kwrd">if</span> (fromContent <span class="kwrd">is</span> ILocale && (fromContent <span class="kwrd">as</span> ILocale).Language!=<span class="kwrd">null</span>)
add.ReferrerLanguageID = (fromContent <span class="kwrd">as</span> ILocale).Language.Name.ToLower();
}
}
add.QueryString = context.Request.Url.Query;
add.IsEditMode = EPiServer.Editor.PageEditing.PageIsInEditMode;
add.UserNameOrSessionId = userNameOrSessionId;
<span class="kwrd">if</span> (geo != <span class="kwrd">null</span>)
{
add.Region = geo.Region;
add.ContinentCode = geo.ContinentCode;
add.CountryCode = geo.CountryCode;
<span class="kwrd">if</span> (geo.Location != <span class="kwrd">null</span>)
{
add.Latitude = geo.Location.Latitude;
add.Longitude = geo.Location.Longitude;
add.HorizontalAccuracy = geo.Location.HorizontalAccuracy;
}
}
service.AddAndLazySave(add);
}
}
<span class="kwrd">catch</span> (System.Exception error)
{
service.AddError(error);
}
}
}
<span class="kwrd">protected</span> <span class="kwrd">static</span> ContentActionEntity CreateEntity(RouteData routeData)
{
var nodeRef = <span class="str">""</span> + routeData.DataTokens[<span class="str">"node"</span>];
ContentReference parsed;
<span class="kwrd">if</span> (!ContentReference.TryParse(nodeRef, <span class="kwrd">out</span> parsed))
{
<span class="kwrd">return</span> <span class="kwrd">null</span>;
}
var result = <span class="kwrd">new</span> ContentActionEntity();
result.ReferenceWithoutVersion = parsed.ToReferenceWithoutVersion().ToString();
result.WorkdId = parsed.WorkID;
result.ControllerName = <span class="str">""</span> + routeData.Values[<span class="str">"controller"</span>];
result.ActionName = <span class="str">""</span> + routeData.Values[<span class="str">"action"</span>];
result.LanguageID = <span class="str">""</span> + (routeData.Values[<span class="str">"language"</span>] ?? routeData.DataTokens[<span class="str">"defaultLanguage"</span>]);
<span class="kwrd">if</span> (<span class="kwrd">string</span>.IsNullOrEmpty(result.LanguageID))
result.LanguageID = ContentLanguage.PreferredCulture.Name;
var currentNode = routeData.Values[<span class="str">"currentContent"</span>];
<span class="kwrd">if</span> (currentNode <span class="kwrd">is</span> IContent)
{
result.ReferenceWithoutVersion += (currentNode <span class="kwrd">as</span> IContent).ContentLink.ToReferenceWithoutVersion().ToString();
result.WorkdId += (currentNode <span class="kwrd">as</span> IContent).ContentLink.WorkID;
}
<span class="kwrd">if</span> (currentNode <span class="kwrd">is</span> ILocale)
{
result.LanguageID = (currentNode <span class="kwrd">as</span> ILocale).Language.Name;
}
<span class="kwrd">return</span> result;
}
<span class="kwrd">protected</span> IGeolocationResult GetCurrentUsersLocation(IPAddress ipAddress)
{
var geoLocationProvider = Geolocation.Provider <span class="kwrd">as</span> GeolocationProvider;
<span class="kwrd">return</span> geoLocationProvider.Lookup(ipAddress);
}
<span class="kwrd">protected</span> IPAddress GetUsersIp(HttpRequestBase request)
{
<span class="kwrd">if</span> (request.ServerVariables[<span class="str">"HTTP_X_FORWARDED_FOR"</span>] != <span class="kwrd">null</span>)
<span class="kwrd">return</span> IPAddress.Parse(request.ServerVariables[<span class="str">"HTTP_X_FORWARDED_FOR"</span>].ToString());
<span class="kwrd">if</span> (request.UserHostAddress.Length != 0)
<span class="kwrd">return</span> IPAddress.Parse(request.UserHostAddress);
<span class="kwrd">return</span> IPAddress.None;
}
}</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
width:100%;
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>
<p>This code will create an object of type ContentActionEntity and save it to a store if we are not in edit modus. The object have different kind of attributes specified bellow. </p>
<pre class="language-csharp"><code>[EPiServerDataStore(AutomaticallyRemapStore = <span class="kwrd">true</span>, AutomaticallyCreateStore = <span class="kwrd">true</span>)]
<span class="kwrd">public</span> <span class="kwrd">class</span> ContentActionEntity : IDynamicData
{
<span class="kwrd">public</span> EPiServer.Data.Identity Id { get; set; }
[EPiServerIgnoreDataMember]
<span class="kwrd">public</span> <span class="kwrd">bool</span> IsSaved { get
{
<span class="kwrd">if</span> (Id == <span class="kwrd">null</span>)
<span class="kwrd">return</span> <span class="kwrd">false</span>;
<span class="kwrd">return</span> <span class="kwrd">true</span>;
}
}
[EPiServerDataIndex]
<span class="kwrd">public</span> <span class="kwrd">string</span> SiteReference { get; set; }
[EPiServerDataIndex]
<span class="kwrd">public</span> <span class="kwrd">string</span> MachineName { get; set; }
[EPiServerDataIndex]
<span class="kwrd">public</span> <span class="kwrd">string</span> ReferenceWithoutVersion { get; set; }
<span class="kwrd">public</span> <span class="kwrd">int</span> WorkdId { get; set; }
[EPiServerDataIndex]
<span class="kwrd">public</span> <span class="kwrd">string</span> LanguageID { get; set; }
[EPiServerDataIndex]
<span class="kwrd">public</span> <span class="kwrd">bool</span> IsEditMode { get; set; }
[EPiServerDataIndex]
<span class="kwrd">public</span> DateTime Viewed { get; set; }
<span class="kwrd">public</span> <span class="kwrd">long</span> TotalMilliSeconds { get; set; }
<span class="kwrd">public</span> <span class="kwrd">long</span> ControllerMilliSeconds { get; set; }
<span class="kwrd">public</span> <span class="kwrd">long</span> ViewMilliSeconds { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> UserNameOrSessionId { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> QueryString { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> ControllerName { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> ActionName { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> ContinentCode { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> CountryCode { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> Region { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> IpAdress { get; set; }
<span class="kwrd">public</span> <span class="kwrd">double</span> HorizontalAccuracy { get; set; }
<span class="kwrd">public</span> <span class="kwrd">double</span> Latitude { get; set; }
<span class="kwrd">public</span> <span class="kwrd">double</span> Longitude { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> RawUrl { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> UrlReferrer { get; set; }
[EPiServerDataIndex]
<span class="kwrd">public</span> <span class="kwrd">string</span> ReferrerReferenceWithoutVersion { get; set; }
[EPiServerDataIndex]
<span class="kwrd">public</span> <span class="kwrd">string</span> ReferrerLanguageID { get; set; }
<span class="kwrd">public</span> GeoCoordinate GetLocation()
{
<span class="kwrd">return</span> <span class="kwrd">new</span> GeoCoordinate(Latitude, Longitude);
}
<span class="kwrd">public</span> <span class="kwrd">string</span> GetContinentName()
{
<span class="kwrd">if</span> (<span class="kwrd">string</span>.IsNullOrEmpty(ContinentCode))
<span class="kwrd">return</span> <span class="str">""</span>;
var localizationService = ServiceLocator.Current.GetInstance<LocalizationService>();
<span class="kwrd">return</span> localizationService.GetString(<span class="str">"/shell/cms/visitorgroups/criteria/geographiclocation/continents/"</span> + ContinentCode);
}
<span class="kwrd">public</span> <span class="kwrd">string</span> GetCountryName()
{
<span class="kwrd">if</span> (<span class="kwrd">string</span>.IsNullOrEmpty(CountryCode))
<span class="kwrd">return</span> <span class="str">""</span>;
var localizationService = ServiceLocator.Current.GetInstance<LocalizationService>();
<span class="kwrd">return</span> localizationService.GetString(<span class="str">"/shell/cms/visitorgroups/criteria/geographiclocation/countries/"</span> + CountryCode);
}
<span class="kwrd">public</span> IContent GetContent()
{
<span class="kwrd">try</span> {
var pageRef = ContentReference.Parse(ReferenceWithoutVersion);
var lang = <span class="kwrd">new</span> LanguageSelector(<span class="kwrd">this</span>.LanguageID);
<span class="kwrd">return</span> EPiServer.DataFactory.Instance.Get<IContent>(pageRef, lang);
}
<span class="kwrd">catch</span>
{
<span class="kwrd">return</span> <span class="kwrd">null</span>;
}
}
<span class="kwrd">public</span> MvcHtmlString GetPageName(<span class="kwrd">string</span> format)
{
<span class="kwrd">try</span>
{
var pageRef = ContentReference.Parse(ReferenceWithoutVersion);
var lang = <span class="kwrd">new</span> LanguageSelector(<span class="kwrd">this</span>.LanguageID);
var pathList = EPiServer.DataFactory.Instance.GetAncestors(pageRef).Where(p => p <span class="kwrd">is</span> SitePageData).Reverse().Select(p => p.Name);
var paths =<span class="kwrd">string</span>.Join(<span class="str">"/"</span>, pathList);
var name = EPiServer.DataFactory.Instance.Get<IContent>(pageRef, lang).Name;
<span class="kwrd">return</span> MvcHtmlString.Create(<span class="kwrd">string</span>.Format(format, paths, name));
}
<span class="kwrd">catch</span>
{
<span class="kwrd">return</span> MvcHtmlString.Create(<span class="kwrd">string</span>.Format(format, <span class="str">"Error "</span> + ReferenceWithoutVersion + <span class="str">" ["</span> + LanguageID + <span class="str">"]"</span>, <span class="str">""</span>));
}
}
}</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>
<p>The servcie looks like this</p>
<pre class="language-csharp"><code> [ServiceConfiguration(ServiceType = <span class="kwrd">typeof</span>(ContentActionStoreService), Lifecycle = ServiceInstanceScope.Singleton)]
<span class="kwrd">public</span> <span class="kwrd">class</span> ContentActionStoreService
{
<span class="kwrd">public</span> ContentActionStoreService()
{
var key = ConfigurationManager.AppSettings[<span class="str">"ServereTimeInfo"</span>];
<span class="kwrd">if</span> (<span class="kwrd">string</span>.IsNullOrEmpty(key) || key.ToLower() == <span class="str">"true"</span>)
{
IsEnabled = <span class="kwrd">true</span>;
}
}
DynamicDataStore ContentActionStore
{
get
{
<span class="kwrd">return</span> DynamicDataStoreFactory.Instance.GetStore(<span class="kwrd">typeof</span>(ContentActionEntity));
}
}
List<ContentActionEntity> spool = <span class="kwrd">new</span> List<ContentActionEntity>();
<span class="kwrd">object</span> lockObject = <span class="kwrd">new</span> <span class="kwrd">object</span>();
<span class="kwrd">public</span> <span class="kwrd">void</span> AddAndLazySave(ContentActionEntity add)
{
Add(add);
SaveTempItems(<span class="kwrd">false</span>);
}
<span class="kwrd">public</span> <span class="kwrd">void</span> SaveTempItems(<span class="kwrd">bool</span> always)
{
List<ContentActionEntity> saveItems = <span class="kwrd">null</span>;
<span class="kwrd">lock</span> (lockObject)
{
<span class="kwrd">if</span> (spool.Count > 10 || always)
{
saveItems = spool;
spool = <span class="kwrd">new</span> List<ContentActionEntity>();
}
}
<span class="kwrd">if</span> (saveItems != <span class="kwrd">null</span>)
{
<span class="kwrd">foreach</span> (var item <span class="kwrd">in</span> saveItems)
ContentActionStore.Save(item);
}
}
<span class="kwrd">void</span> Add(ContentActionEntity add)
{
<span class="kwrd">lock</span> (lockObject)
{
spool.Add(add);
}
}
}</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
</p>
<p>
<p>Then you can either create a view based on thees rows, or just to some SQL queries on the view. Either way it’s a easy and simple solution to find what controller actions or views that takes long time to execute.</p></p>
When EPiServer.Search's Score is zero
/blogs/Anders-Hattestad/Dates/2016/2/when-episerver.searchs-score-is-zero/
2016-02-18T11:32:31.0000000Z
<p>I got a problem with the search result using EPiServer.Search. The site is in Norwegian and is set to default langauge in site settings in admin. </p> <p>But the result from the search always gave me 0 for result on the IndexResponseItem Score. <br />After some digging around I found this code </p> <pre class="language-csharp"><code>indexResponseItem.Score = (<span class="kwrd">float</span>.TryParse(RequestHandler.GetAttributeValue(current, SearchSettings.Config.SyndicationItemAttributeNameScore), <span class="kwrd">out</span> num2) ? num2 : 0f);</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<br />Beeing executed in RequestHandler.PopulateSearchResultsFromFeed
<br />And since my current Culture will be set to "no" since the host sets it to that, the result from IndexService/IndexingService.svc will return results in "en" then I got problems
<p>The quick solution is to change the current culture before one search and set it back after. </p>
<pre class="language-csharp"><code>var section = ConfigurationManager.GetSection(<span class="str">"system.web/globalization"</span>) <span class="kwrd">as</span> GlobalizationSection;
var oldCulture = Thread.CurrentThread.CurrentCulture;
<span class="kwrd">if</span> (section!=<span class="kwrd">null</span> )
{
Thread.CurrentThread.CurrentCulture=CultureInfo.GetCultureInfo(section.UICulture);
}
var res= SearchHandler.Instance.GetSearchResults(groupQuery, 1, maxSize);
Thread.CurrentThread.CurrentCulture = oldCulture;
<span class="kwrd">return</span> res;</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
width:100%;
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>I Guess there are more correct ways of doing this, but a solution is better than none :)</p>
Continent-Country-Region drop down list as dojo property
/blogs/Anders-Hattestad/Dates/2016/2/continent-country-region-drop-down-list-as-dojo-property/
2016-02-11T15:05:53.0000000Z
<p>I have looked at different ways of implementing a dropdown list with dependencies. Have looke at <a href="/link/e37532397357404f855e7c21105956c2.aspx">Doong Nguyen’s solution</a> but had problems making it also work with continent.</p> <p>First of all I made a ContinentCountryRegionSelectionFactory to get all items needed.</p> <a href="http://11011.net/software/vspaste"></a> <pre class="language-csharp"><code><span class="kwrd">class</span> DependedItem : ISelectItem
{
<span class="kwrd">public</span> <span class="kwrd">string</span> Parent { get; set; }
<span class="kwrd">public</span> <span class="kwrd">object</span> Value { get; set; }
<span class="kwrd">public</span> <span class="kwrd">int</span> Level { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> Text { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> Name { get { <span class="kwrd">return</span> Text; } }
}</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Then I populated it as follows using the GeoLoation store in episerver to get the different kind of options and created first a class to store the values</p>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
width:100%;
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
<pre class="language-csharp"><code><span class="kwrd">public</span> <span class="kwrd">class</span> ContinentCountryRegionSelectionFactory : ISelectionFactory
{
<span class="kwrd">public</span> IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
var _geolocationProviderBase = ServiceLocator.Current.GetInstance<GeolocationProviderBase>();
var _localizationService = ServiceLocator.Current.GetInstance<LocalizationService>();
var list = <span class="kwrd">new</span> List<ISelectItem>();
<span class="kwrd">foreach</span> (var continentKey <span class="kwrd">in</span> _geolocationProviderBase.GetContinentCodes())
{
var continent = <span class="kwrd">new</span> DependedItem()
{
Value = continentKey,
Parent = <span class="str">""</span>,
Level=0,
Text = _localizationService.GetString(<span class="str">"/shell/cms/visitorgroups/criteria/geographiclocation/continents/"</span> + continentKey)
};
list.Add(continent);
<span class="kwrd">foreach</span> (var countryKey <span class="kwrd">in</span> _geolocationProviderBase.GetCountryCodes(continentKey))
{
var country = <span class="kwrd">new</span> DependedItem()
{
Value = continentKey+<span class="str">"-"</span>+ countryKey,
Parent= continentKey,
Level=1,
Text = _localizationService.GetString(<span class="str">"/shell/cms/visitorgroups/criteria/geographiclocation/countries/"</span> + countryKey)
};
list.Add(country);
<span class="kwrd">foreach</span> (var regionKey <span class="kwrd">in</span> _geolocationProviderBase.GetRegions(countryKey))
{
var region = <span class="kwrd">new</span> DependedItem()
{
Value = continentKey + <span class="str">"-"</span> + countryKey+<span class="str">"-"</span>+ regionKey,
Parent= continentKey + <span class="str">"-"</span> + countryKey,
Level=2,
Text = regionKey
};
list.Add(region);
}
}
}
<span class="kwrd">return</span> list;
}
}</code></pre>
<p><a href="http://paste.ofcode.org/83pXPiBSemJdn4J7TbMaPf">Full code of this is here</a></p>
<p>After I have done this the scary part remains. First I add a file ClientResources/scripts/editors/SelectAreaEditor.js Then made a dojo property where one text box is the value of the property. And 3 other FilteringSelect dropdowns are Continent/Country/Region</p>
<p>After one select for instance a continent I update the store for country and updates the value and display the country area.</p>
<pre class="language-csharp"><code><span class="rem">/*</span>
<span class="rem">Dojo widget for editing a list of strings. Also see property type PropertyStringList in /Models/Properties.</span>
<span class="rem">*/</span>
define([
<span class="str">"dojo/_base/array"</span>,
<span class="str">"dojo/_base/connect"</span>,
<span class="str">"dojo/_base/declare"</span>,
<span class="str">"dojo/_base/lang"</span>,
<span class="str">"dijit/_CssStateMixin"</span>,
<span class="str">"dijit/_Widget"</span>,
<span class="str">"dijit/_TemplatedMixin"</span>,
<span class="str">"dijit/_WidgetsInTemplateMixin"</span>,
<span class="str">"dijit/form/TextBox"</span>,
<span class="str">"epi/epi"</span>,
<span class="str">"epi/shell/widget/_ValueRequiredMixin"</span>,
<span class="str">"dojo/store/Memory"</span>,
<span class="str">"dijit/form/FilteringSelect"</span>
],
<span class="kwrd">function</span> (
array,
connect,
declare,
lang,
_CssStateMixin,
_Widget,
_TemplatedMixin,
_WidgetsInTemplateMixin,
Textarea,
epi,
_ValueRequiredMixin,
Memory,
FilteringSelect
) {
<span class="kwrd">return</span> declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin, _CssStateMixin, _ValueRequiredMixin], {
templateString: <span class="str">"<div class=\"dijitInline\">\
<div data-dojo-attach-point=\"stateNode, tooltipNode\" >\
<div data-dojo-attach-point=\"textBox\" type=\"hidden\" data-dojo-type=\"dijit.form.TextBox\"></div>\
</div>\
<div data-dojo-attach-point=\"inputLevel1\" data-dojo-type=\"dijit.form.FilteringSelect\" style=\"min-width: 300px;\">\
</div>\
<div data-dojo-attach-point=\"area2\" style=\"display:block;padding-left:30px;display:none;\">\
<div data-dojo-attach-point=\"inputLevel2\" data-dojo-type=\"dijit.form.FilteringSelect\" style=\"min-width: 300px;\">\
</div>\
<div data-dojo-attach-point=\"area3\" style=\"display:block;padding-left:30px;display:none;\">\
<div data-dojo-attach-point=\"inputLevel3\" data-dojo-type=\"dijit.form.FilteringSelect\" style=\"min-width: 300px\">\
</div>\
</div>\
</div>\
</div>"</span>,
intermediateChanges: <span class="kwrd">false</span>,
value: <span class="kwrd">null</span>,
allItemsStore: <span class="kwrd">null</span>,
selected: <span class="kwrd">null</span>,
onChange: <span class="kwrd">function</span> (value) {
<span class="rem">// Event</span>
},
postCreate: <span class="kwrd">function</span> () {
<span class="rem">// call base implementation</span>
<span class="kwrd">this</span>.inherited(arguments);
<span class="rem">// Init textarea and bind event</span>
<span class="kwrd">this</span>.textBox.set(<span class="str">"intermediateChanges"</span>, <span class="kwrd">this</span>.intermediateChanges);
<span class="kwrd">this</span>.connect(<span class="kwrd">this</span>.textBox, <span class="str">"onChange"</span>, <span class="kwrd">this</span>._onTextBoxChanged);
<span class="kwrd">this</span>._setUpStores(1);
<span class="kwrd">this</span>.selected = <span class="kwrd">this</span>._findSelected(<span class="str">""</span>);
<span class="kwrd">this</span>.connect(<span class="kwrd">this</span>.inputLevel1, <span class="str">"onChange"</span>, <span class="kwrd">this</span>._onLevelBoxChanged1);
<span class="kwrd">this</span>.connect(<span class="kwrd">this</span>.inputLevel2, <span class="str">"onChange"</span>, <span class="kwrd">this</span>._onLevelBoxChanged2);
<span class="kwrd">this</span>.connect(<span class="kwrd">this</span>.inputLevel3, <span class="str">"onChange"</span>, <span class="kwrd">this</span>._onLevelBoxChanged3);
},
postMixInProperties: <span class="kwrd">function</span> () {
<span class="kwrd">this</span>.inherited(arguments);
<span class="kwrd">var</span> test = <span class="kwrd">this</span>.selections;
<span class="kwrd">this</span>.allItemsStore = <span class="kwrd">new</span> Memory({ idProperty: <span class="str">"value"</span>, IsType: <span class="str">"Continent"</span>, data: <span class="kwrd">this</span>.selections });
},
isValid: <span class="kwrd">function</span> () {
<span class="kwrd">return</span> !<span class="kwrd">this</span>.required || (<span class="kwrd">this</span>.value.length > 0 && <span class="kwrd">this</span>.value!= <span class="str">""</span>);
},
<span class="rem">// Setter for value property</span>
_setValueAttr: <span class="kwrd">function</span> (value) {
<span class="kwrd">this</span>._setValue(value, <span class="kwrd">true</span>,<span class="kwrd">true</span>);
},
_setReadOnlyAttr: <span class="kwrd">function</span> (value) {
<span class="kwrd">this</span>._set(<span class="str">"readOnly"</span>, value);
<span class="kwrd">this</span>.textBox.set(<span class="str">"readOnly"</span>, value);
},
_setIntermediateChangesAttr: <span class="kwrd">function</span> (value) {
<span class="kwrd">this</span>.textBox.set(<span class="str">"intermediateChanges"</span>, value);
<span class="kwrd">this</span>._set(<span class="str">"intermediateChanges"</span>, value);
},
_onTextBoxChanged: <span class="kwrd">function</span> (value) {
<span class="kwrd">this</span>._setValue(value, <span class="kwrd">false</span>,<span class="kwrd">false</span>);
},
_onLevelBoxChanged1: <span class="kwrd">function</span> (value) {
<span class="kwrd">var</span> me = <span class="kwrd">this</span>._findSelected(value);
<span class="rem">//this.selected = this._findSelected(value);</span>
<span class="kwrd">if</span> (<span class="kwrd">this</span>.selected.level1 != me.level1) {
<span class="kwrd">this</span>.selected = me;
<span class="kwrd">this</span>._setUpStores(2);
<span class="kwrd">this</span>._setValuesInDropDowns();
<span class="kwrd">this</span>._setValue(value, <span class="kwrd">true</span>, <span class="kwrd">false</span>);
} <span class="kwrd">else</span> {
<span class="rem">//this._setValue(value, true, false);</span>
}
},
_onLevelBoxChanged2: <span class="kwrd">function</span> (value) {
<span class="kwrd">var</span> me = <span class="kwrd">this</span>._findSelected(value);
<span class="kwrd">if</span> (<span class="kwrd">this</span>.selected.level2!=me.level2)
{
<span class="kwrd">this</span>.selected = me;
<span class="kwrd">this</span>._setUpStores(3);
<span class="kwrd">this</span>._setValuesInDropDowns();
<span class="kwrd">this</span>._setValue(value, <span class="kwrd">true</span>, <span class="kwrd">false</span>);
}
<span class="rem">//this._setUpStores();</span>
<span class="rem">//this._setValue(value, true,false);</span>
},
_onLevelBoxChanged3: <span class="kwrd">function</span> (value) {
<span class="kwrd">var</span> me = <span class="kwrd">this</span>._findSelected(value);
<span class="kwrd">if</span> (<span class="kwrd">this</span>.selected.level3 != me.level3) {
<span class="kwrd">this</span>.selected = me;
<span class="rem">//this._setUpStores(3);</span>
<span class="kwrd">this</span>._setValuesInDropDowns();
<span class="kwrd">this</span>._setValue(value, <span class="kwrd">true</span>, <span class="kwrd">false</span>);
}
},
_findSelected: <span class="kwrd">function</span> (value) {
<span class="kwrd">var</span> result = { level1: <span class="str">""</span>, level2: <span class="str">""</span>, level3: <span class="str">""</span> };
<span class="kwrd">var</span> item = <span class="kwrd">this</span>.allItemsStore.query({ value: value });
<span class="kwrd">if</span> (item.length != 0) {
<span class="kwrd">if</span> (item[0].level == 2) {
result.level3 = item[0].value;
item = <span class="kwrd">this</span>.allItemsStore.query({ value: item[0].parent });
}
<span class="kwrd">if</span> (item[0].level == 1) {
result.level2 = item[0].value;
item = <span class="kwrd">this</span>.allItemsStore.query({ value: item[0].parent });
}
<span class="kwrd">if</span> (item[0].level == 0) {
result.level1 = item[0].value;
}
}
<span class="kwrd">return</span> result;
},
_setValuesInDropDowns: <span class="kwrd">function</span> () {
<span class="kwrd">this</span>.inputLevel1.set(<span class="str">"value"</span>, <span class="kwrd">this</span>.selected.level1);
<span class="kwrd">this</span>.inputLevel2.set(<span class="str">"value"</span>, <span class="kwrd">this</span>.selected.level2);
<span class="kwrd">this</span>.inputLevel3.set(<span class="str">"value"</span>, <span class="kwrd">this</span>.selected.level3);
<span class="kwrd">this</span>.area2.style.display=(<span class="kwrd">this</span>.selected.level1!=<span class="str">""</span>)?<span class="str">"block"</span>:<span class="str">"none"</span>;
<span class="kwrd">this</span>.area3.style.display=(<span class="kwrd">this</span>.selected.level2!=<span class="str">""</span>)?<span class="str">"block"</span>:<span class="str">"none"</span>;
},
_setUpStores: <span class="kwrd">function</span> (level) {
<span class="kwrd">if</span> (level == 1 || level == 0) {
<span class="kwrd">var</span> level1 = <span class="kwrd">this</span>.allItemsStore.query({ level: 0 });
<span class="kwrd">var</span> level1Store = <span class="kwrd">new</span> Memory({ idProperty: <span class="str">"value"</span>, data: level1 });
<span class="kwrd">this</span>.inputLevel1.set(<span class="str">"store"</span>, level1Store);
}
<span class="kwrd">if</span> ((level == 2 || level == 0) && <span class="kwrd">this</span>.selected.level1 != <span class="str">""</span>) {
<span class="kwrd">var</span> level2 = <span class="kwrd">this</span>.allItemsStore.query({ level: 1, parent: <span class="kwrd">this</span>.selected.level1});
<span class="kwrd">var</span> level2Store = <span class="kwrd">new</span> Memory({ idProperty: <span class="str">"value"</span>, data: level2 });
<span class="kwrd">this</span>.inputLevel2.set(<span class="str">"store"</span>, level2Store);
}
<span class="kwrd">if</span> ((level == 3 || level == 0) && <span class="kwrd">this</span>.selected.level2 != <span class="str">""</span>) {
<span class="kwrd">var</span> level3 = <span class="kwrd">this</span>.allItemsStore.query({ level: 2, parent: <span class="kwrd">this</span>.selected.level2 });
<span class="kwrd">var</span> level3Store = <span class="kwrd">new</span> Memory({ idProperty: <span class="str">"value"</span>, data: level3 });
<span class="kwrd">this</span>.inputLevel3.set(<span class="str">"store"</span>, level3Store);
}
},
_setValue: <span class="kwrd">function</span> (value, updateTextbox,updateDropDown) {
<span class="kwrd">if</span> (updateDropDown) {
<span class="kwrd">this</span>.selected = <span class="kwrd">this</span>._findSelected(value);
<span class="kwrd">this</span>._setUpStores(0);
<span class="kwrd">this</span>._setValuesInDropDowns();
}
<span class="kwrd">if</span> (<span class="kwrd">this</span>._started && epi.areEqual(<span class="kwrd">this</span>.value, value)) {
<span class="kwrd">return</span>;
}
<span class="rem">// set value to this widget (and notify observers)</span>
<span class="kwrd">this</span>._set(<span class="str">"value"</span>, value);
<span class="rem">// set value to textarea</span>
<span class="kwrd">if</span> (updateTextbox) {
<span class="kwrd">this</span>.textBox.set(<span class="str">"value"</span>, value);
}
<span class="kwrd">if</span> (<span class="kwrd">this</span>._started && <span class="kwrd">this</span>.validate()) {
<span class="rem">// Trigger change event</span>
<span class="kwrd">this</span>.onChange(value);
}
}
});
});</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><a href="http://paste.ofcode.org/ukJ8uZyFwhZvsxUpxetdpg">Full dojo code is here</a></p>
<p>The I needed to add the descriptor the the string property </p>
<pre class="language-csharp"><code>[ClientEditor(ClientEditingClass = <span class="str">"iterasite/editors/SelectAreaEditor"</span>, SelectionFactoryType = <span class="kwrd">typeof</span>(ContinentCountryRegionSelectionFactory))]
<span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">string</span> SelectArea { get; set; }</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>And after done that the result is </p>
<p><a href="/link/ee1ee67126c441838735ae5f6fa64687.aspx"><img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="/link/11f21bb35488408981352d1429e01787.aspx" width="591" height="115" /></a></p>
<p>This code should work with any data as long as the parent key and level is set. But the value need to be unique accross all values.</p>
<p>Hope this can help someone. It did take some time to figure it out :) </p>
When EPiServer.Search dosen't work
/blogs/Anders-Hattestad/Dates/2016/2/when-episerver.search-dosent-work/
2016-02-09T13:44:32.0000000Z
<p>I work locally and move the site to a test server, and the search didn't work. <br />The first problem was the http://IndexingService/IndexingService.svc gave an 500 error since it didn't find the handler for it. That was easy resolved by adding svg-Itegrated-4.0 handler.</p> <pre class="language-csharp"><code> <span class="kwrd"><</span><span class="html">location</span> <span class="attr">path</span><span class="kwrd">="IndexingService/IndexingService.svc"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">system.web</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">httpRuntime</span> <span class="attr">maxQueryStringLength</span><span class="kwrd">="65536"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">system.web</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">system.webServer</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">handlers</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">clear</span><span class="kwrd">/></span>
<strong>
<span class="kwrd"><</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">="svc-Integrated-4.0"</span> <span class="attr">path</span><span class="kwrd">="*.svc"</span> <span class="attr">verb</span><span class="kwrd">="*"</span> <span class="attr">type</span><span class="kwrd">="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"</span> <span class="attr">preCondition</span><span class="kwrd">="integratedMode,runtimeVersionv4.0"</span> <span class="kwrd">/></span>
</strong>
<span class="kwrd"></</span><span class="html">handlers</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">security</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">requestFiltering</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">requestLimits</span> <span class="attr">maxQueryString</span><span class="kwrd">="65536"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">requestFiltering</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">security</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">system.webServer</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">location</span><span class="kwrd">></span></code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
width:100%;
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>But the problem was there still. I got no hits from the search. I thought it maybe was something that would show in the log, but the log didn't add any lines. That was solved by editing the EPiServerLog.config and set the threshold for the appender to All since it by default is set to Error. </p>
<pre class="language-csharp"><code><span class="kwrd"><</span><span class="html">log4net</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">appender</span> <span class="attr">name</span><span class="kwrd">="errorFileLogAppender"</span> <span class="attr">type</span><span class="kwrd">="log4net.Appender.RollingFileAppender"</span> <span class="kwrd">></span>
<span class="rem"><!-- Consider moving the log files to a location outside the web application --></span>
<span class="kwrd"><</span><span class="html">file</span> <span class="attr">value</span><span class="kwrd">="App_Data\EPiServerErrors2.log"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">encoding</span> <span class="attr">value</span><span class="kwrd">="utf-8"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">staticLogFileName</span> <span class="attr">value</span><span class="kwrd">="true"</span><span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">datePattern</span> <span class="attr">value</span><span class="kwrd">=".yyyyMMdd.'log'"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">rollingStyle</span> <span class="attr">value</span><span class="kwrd">="Date"</span> <span class="kwrd">/></span>
<strong><span class="kwrd"><</span><span class="html">threshold</span> <span class="attr">value</span><span class="kwrd">="All"</span> <span class="kwrd">/></span></strong>
<span class="kwrd"><</span><span class="html">lockingModel</span> <span class="attr">type</span><span class="kwrd">="log4net.Appender.FileAppender+MinimalLock"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">appendToFile</span> <span class="attr">value</span><span class="kwrd">="true"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">layout</span> <span class="attr">type</span><span class="kwrd">="log4net.Layout.PatternLayout"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">conversionPattern</span> <span class="attr">value</span><span class="kwrd">="%date [%thread] %level %logger: %message%n"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">layout</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">appender</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">appender</span> <span class="attr">name</span><span class="kwrd">="outputDebugStringAppender"</span> <span class="attr">type</span><span class="kwrd">="log4net.Appender.OutputDebugStringAppender"</span> <span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">layout</span> <span class="attr">type</span><span class="kwrd">="log4net.Layout.PatternLayout"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">conversionPattern</span> <span class="attr">value</span><span class="kwrd">="[%thread] %level %logger: %message%n"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">layout</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">appender</span><span class="kwrd">></span>
<span class="rem"><!-- Log page publish to find editor related errors. --></span>
<span class="kwrd"><</span><span class="html">logger</span> <span class="attr">name</span><span class="kwrd">="EPiServer.Search.IndexingService"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">level</span> <span class="attr">value</span><span class="kwrd">="All"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">logger</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">root</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">level</span> <span class="attr">value</span><span class="kwrd">="Error"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">appender-ref</span> <span class="attr">ref</span><span class="kwrd">="errorFileLogAppender"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">root</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">log4net</span><span class="kwrd">></span></code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>But my zero hits didn't show in the log, or it showed that the index was responding, but gave 0 hits. Then it struck me that to get the index to work I need to copy the AppData/Index files to the new server. And it worked. So mental not to self, when deploying a local site to a test server copy the AppData/Index files also, or reindex the site again </p>
Get owner content of document in “for this page”
/blogs/Anders-Hattestad/Dates/2016/2/get-owner-content-of-document-in-for-this-page/
2016-02-08T14:55:40.0000000Z
<p>A quick tip for finding owner page.</p> <p>var contentAssetHelper = ServiceLocator.Current.GetInstance<ContentAssetHelper>();</p> <p>var ownerNode = contentAssetHelper.GetAssetOwner(media.ContentLink);</p> <p>It is also worth to mention that the standard EPiServer Search will index local files bellow contentlink 4, or if you drag the current page "for this page" folder inside a contentarea it will give you the same value.</p> <p> VirtualPathQuery pathQuery = new VirtualPathQuery();<br /> pathQuery.AddContentNodes(bellow, serviceLocationHelper.ContentLoader()); </p>
Extending the HyperLink with custom field
/blogs/Anders-Hattestad/Dates/2015/2/extending-the-hyperlink-with-custom-field/
2015-02-20T13:48:50.0000000Z
I needed to extend the popup with a new field where the editors could add a phone number. In EPiServer 7.5 this can be done by extending the EditorDescriptorRegistration <pre class="language-csharp"><code> [EditorDescriptorRegistration(TargetType = <span class="kwrd">typeof</span> (<span class="kwrd">string</span>), UIHint = <span class="str">"HyperLink"</span>,
EditorDescriptorBehavior = EditorDescriptorBehavior.OverrideDefault)]
<span class="kwrd">public</span> <span class="kwrd">class</span> LinkEditorDescriptor : EditorDescriptor
{
<span class="kwrd">private</span> <span class="kwrd">readonly</span> LocalizationService _localizationService;
<span class="kwrd">public</span> LinkEditorDescriptor() : <span class="kwrd">this</span>(LocalizationService.Current)
{
}
<span class="kwrd">public</span> LinkEditorDescriptor(LocalizationService localizationService)
{
_localizationService = localizationService;
}
<span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
{
<span class="kwrd">base</span>.ModifyMetadata(metadata, attributes);
IEnumerable<IContentRepositoryDescriptor> allInstances =
ServiceLocator.Current.GetAllInstances<IContentRepositoryDescriptor>();
List<HyperLinkModel> list = (
from r <span class="kwrd">in</span> allInstances
orderby r.SortOrder
<span class="kwrd">where</span> r.LinkableTypes != <span class="kwrd">null</span> && r.LinkableTypes.Count() > 0
select <span class="kwrd">new</span> HyperLinkModel
{
Name = r.CustomSelectTitle ?? r.Name,
Roots = r.Roots,
WidgetType = <span class="str">"epi-cms/widget/ContentSelector"</span>,
LinkableTypes = r.LinkableTypes,
SearchArea = r.SearchArea
}).ToList<HyperLinkModel>();
list.InsertRange(list.Count, <span class="kwrd">new</span>[]
{
<span class="kwrd">new</span> HyperLinkModel
{
Name = <span class="str">"Email"</span>,
Title = _localizationService.GetString(<span class="str">"/episerver/cms/widget/editlink/emailtooltip"</span>),
DisplayName = _localizationService.GetString(<span class="str">"/episerver/cms/widget/editlink/email"</span>),
WidgetType = <span class="str">"epi-cms/form/EmailValidationTextBox"</span>
},
<span class="kwrd">new</span> HyperLinkModel
{
Name = <span class="str">"ExternalLink"</span>,
Title = _localizationService.GetString(<span class="str">"/episerver/cms/widget/editlink/externallinktooltip"</span>),
DisplayName = _localizationService.GetString(<span class="str">"/episerver/cms/widget/editlink/externallink"</span>),
WidgetType = <span class="str">"epi-cms/form/UrlValidationTextBox"</span>
},
<span class="kwrd">new</span> HyperLinkModel
{
Name = <span class="str">"FreeTextLink"</span>,
Title = <span class="str">"Other links"</span>,
DisplayName = <span class="str">"Other"</span>,
WidgetType = <span class="str">"alloy/TextBoxMustHaveValue"</span>
},
<span class="kwrd">new</span> HyperLinkModel
{
Name = <span class="str">"Anchor"</span>,
Title = _localizationService.GetString(<span class="str">"/episerver/cms/widget/editlink/anchortooltip"</span>),
DisplayName = _localizationService.GetString(<span class="str">"/episerver/cms/widget/editlink/anchor"</span>),
WidgetType = <span class="str">"epi-cms/form/AnchorSelectionEditor"</span>,
Invisible = <span class="kwrd">true</span>
}
});
metadata.EditorConfiguration[<span class="str">"providers"</span>] = list;
metadata.GroupName = <span class="str">"Href"</span>;
metadata.GroupSettings = <span class="kwrd">new</span> GroupSettings
{
Name = metadata.GroupName,
ClientLayoutClass = <span class="str">"epi.shell.layout.LayoutContainer"</span>,
DisplayUI = <span class="kwrd">true</span>
};
metadata.ClientEditingClass = <span class="str">"epi-cms/widget/HyperLinkSelector"</span>;
}
}
<span class="kwrd">internal</span> <span class="kwrd">class</span> HyperLinkModel
{
<span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> DisplayName { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> Title { get; set; }
<span class="kwrd">public</span> IEnumerable<ContentReference> Roots { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> WidgetType { get; set; }
<span class="kwrd">public</span> IEnumerable<Type> LinkableTypes { get; set; }
<span class="kwrd">public</span> <span class="kwrd">bool</span> Invisible { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> SearchArea { get; set; }
}
}</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>I needed to create my own HyperLinkModel since its internal </p>
<p>Then I needed to create a dojo class like this </p>
<div>
<pre class="language-csharp"><code>define(<span class="str">"alloy/TextBoxMustHaveValue"</span>, [
<span class="str">"dojo/_base/declare"</span>,
<span class="str">"dojo/_base/lang"</span>,
<span class="str">"dojox/validate/web"</span>,
<span class="str">"dijit/form/ValidationTextBox"</span>,
<span class="rem">// Resources</span>
<span class="str">"epi/i18n!epi/cms/nls/episerver.cms.form.emailvalidation"</span>
], <span class="kwrd">function</span> (
declare,
lang,
validator,
ValidationTextBox,
<span class="rem">// Resources</span>
resources
) {
<span class="kwrd">return</span> declare([ValidationTextBox], {
<span class="rem">// summary:</span>
<span class="rem">// Represents the email input textbox.</span>
<span class="rem">// tags:</span>
<span class="rem">// internal</span>
validator: <span class="kwrd">function</span> (value, constraints) {
<span class="rem">// summary:</span>
<span class="rem">// Validate the text input with email address validation.</span>
<span class="rem">// tags:</span>
<span class="rem">// overrided</span>
<span class="kwrd">return</span> (!<span class="kwrd">this</span>.required && <span class="kwrd">this</span>._isEmpty(value)) || (!<span class="kwrd">this</span>._isEmpty(value));
},
invalidMessage: resources.invalidmessage
});
});</code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></div>
<p>And then register the path in modules.config</p>
<div>
<pre class="language-csharp"><code><span class="kwrd"><</span><span class="html">dojo</span><span class="kwrd">></span>
<span class="rem"><!-- Add a mapping from alloy to ~/ClientResources/Scripts to the dojo loader configuration --></span>
<span class="kwrd"><</span><span class="html">paths</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">="alloy"</span> <span class="attr">path</span><span class="kwrd">="Scripts"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">paths</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">dojo</span><span class="kwrd">></span></code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></div>
<p><a href="/link/a486ca7495ef403f828453764f977073.aspx"><img title="clip_image002" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="clip_image002" src="/link/a8bc80b276624b7fb839ea652acb8fbe.aspx" width="792" height="772" /></a>
<p>And then the result</p></p>
Quick tip when Search is not working
/blogs/Anders-Hattestad/2015/1/quick-tips-when-search-is-not-working/
2015-01-07T18:56:32.0000000Z
<p>I had a search page that worked locally but not on my test server. The strange thing was that the when I access this path locally I got the result </p> <p><a href="http://host/IndexingService/IndexingService.svc/search/?q=(EPISERVER_SEARCH_DEFAULT%3a(test))+AND+((EPISERVER_SEARCH_TYPE%3a(EPiServer.Core.PageData%2cEPiServer))+OR+(EPISERVER_SEARCH_TYPE%3a(EPiServer.Core.PageData%2cEPiServer)))&namedindexes=&offset=0&limit=30&format=xml&accesskey=local">http://host/IndexingService/IndexingService.svc/search/?q=(EPISERVER_SEARCH_DEFAULT%3a(test))+AND+((EPISERVER_SEARCH_TYPE%3a(EPiServer.Core.PageData%2cEPiServer))+OR+(EPISERVER_SEARCH_TYPE%3a(EPiServer.Core.PageData%2cEPiServer)))&namedindexes=&offset=0&limit=30&format=xml&accesskey=local</a> </p> <p>but on the test server I got the 404 page. So after some checking I found out that the default handlers for webserver was different, and the solution was to change the web.config to something like this: </p> <p><location path="IndexingService/IndexingService.svc"> <br />  <system.web> <br />    <httpRuntime maxQueryStringLength="65536" /> <br />  </system.web> <br />  <system.webServer> <br />    <handlers> <br />      <clear/> <br />      <add name="svc-Integrated-4.0" path="*.svc" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv4.0" /> <br />    </handlers> <br />    <security> <br />      <requestFiltering> <br />        <requestLimits maxQueryString="65536" /> <br />      </requestFiltering> <br />    </security> <br />  </system.webServer> <br /></location></p>
Extending ContentArea to use custom CSS class on child elements
/blogs/Anders-Hattestad/Dates/2014/8/Extending-ContentArea-to-use-custom-CSS-class-on-child-elements/
2014-08-25T08:18:46.0000000Z
<div>In EPiServer 7.5 there is support for selection DisplayOption for items in a ContentArea. The build in support will change the tag the item is rendered with. But if you want to render it with the default tag and just add some CSS to the item this is a way of doing it.</div> <div><a href="/link/d9d0e8186eb1495f964442977644f218.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="/link/909dc88acefa426abe6018cfefc128ce.png" width="388" height="402" /></a> </div> <div><strong>First, I made myself a DisplayOptionWithCss class</strong></div> <pre class="language-csharp"><code><span style="background: white; color: blue">public class </span><span style="background: white; color: #2b91af">DisplayOptionWithCss </span><span style="background: white; color: black">: </span><span style="background: white; color: #2b91af">DisplayOption
</span><span style="background: white; color: black">{
</span><span style="background: white; color: blue">public </span><span style="background: white; color: black">DisplayOptionWithCss() { }
</span><span style="background: white; color: blue">public </span><span style="background: white; color: black">DisplayOptionWithCss(</span><span style="background: white; color: blue">string </span><span style="background: white; color: black">id, </span><span style="background: white; color: blue">string </span><span style="background: white; color: black">name,</span><span style="background: white; color: blue">string </span><span style="background: white; color: black">tag,</span><span style="background: white; color: blue">string </span><span style="background: white; color: black">iconClass,</span><span style="background: white; color: blue">string </span><span style="background: white; color: black">cssClass)
{
</span><span style="background: white; color: blue">this</span><span style="background: white; color: black">.Id = id;
</span><span style="background: white; color: blue">this</span><span style="background: white; color: black">.Name = name;
</span><span style="background: white; color: blue">this</span><span style="background: white; color: black">.Tag = tag;
</span><span style="background: white; color: blue">this</span><span style="background: white; color: black">.IconClass = iconClass;
</span><span style="background: white; color: blue">this</span><span style="background: white; color: black">.CssClass = cssClass;
}
</span><span style="background: white; color: blue">public string </span><span style="background: white; color: black">CssClass { </span><span style="background: white; color: blue">get</span><span style="background: white; color: black">; </span><span style="background: white; color: blue">set</span><span style="background: white; color: black">; }
}</span></code></pre>
<a href="http://11011.net/software/vspaste"></a>
<div style="clear:both;"><strong>Second I added the options inside the Global.asax</strong></div>
<pre class="language-csharp"><code><span style="background: white; color: blue">public class </span><span style="background: white; color: #2b91af">EPiServerApplication </span><span style="background: white; color: black">: EPiServer.</span><span style="background: white; color: #2b91af">Global
</span><span style="background: white; color: black">{
</span><span style="background: white; color: blue">protected void </span><span style="background: white; color: black">Application_Start()
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">options = </span><span style="background: white; color: #2b91af">ServiceLocator</span><span style="background: white; color: black">.Current.GetInstance<</span><span style="background: white; color: #2b91af">DisplayOptions</span><span style="background: white; color: black">>();
options
.Add(</span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">DisplayOptionWithCss</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">ContentAreaTags</span><span style="background: white; color: black">.Col12, </span><span style="background: white; color: #a31515">"12/12 width"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">""</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col12 LayoutGrid"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col-sm-12"</span><span style="background: white; color: black">))
.Add(</span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">DisplayOptionWithCss</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">ContentAreaTags</span><span style="background: white; color: black">.Col8, </span><span style="background: white; color: #a31515">"8/12 width"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">""</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col8 LayoutGrid"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col-md-8 col-sm-6 col-xs-12"</span><span style="background: white; color: black">))
.Add(</span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">DisplayOptionWithCss</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">ContentAreaTags</span><span style="background: white; color: black">.Col6, </span><span style="background: white; color: #a31515">"6/12 width"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">""</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col6 LayoutGrid"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col-md-6 col-sm-6 col-xs-12"</span><span style="background: white; color: black">))
.Add(</span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">DisplayOptionWithCss</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">ContentAreaTags</span><span style="background: white; color: black">.Col4, </span><span style="background: white; color: #a31515">"4/12 width"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">""</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col4 LayoutGrid"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col-md-4 col-sm-6 col-xs-12"</span><span style="background: white; color: black">))
.Add(</span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">DisplayOptionWithCss</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">ContentAreaTags</span><span style="background: white; color: black">.Col3, </span><span style="background: white; color: #a31515">"3/12 width"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">""</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col3 LayoutGrid"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col-md-3 col-sm-4 col-xs-6"</span><span style="background: white; color: black">))
.Add(</span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">DisplayOptionWithCss</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">ContentAreaTags</span><span style="background: white; color: black">.Col2, </span><span style="background: white; color: #a31515">"2/12 width"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">""</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col2 LayoutGrid"</span><span style="background: white; color: black">, </span><span style="background: white; color: #a31515">"col-md-2 col-sm-4 col-xs-12"</span><span style="background: white; color: black">));
</span><span style="background: white; color: #2b91af">AreaRegistration</span><span style="background: white; color: black">.RegisterAllAreas();
}
</span><span style="background: white; color: blue">public static class </span><span style="background: white; color: #2b91af">ContentAreaTags
</span><span style="background: white; color: black">{
</span><span style="background: white; color: blue">public const string </span><span style="background: white; color: black">Col2 = </span><span style="background: white; color: #a31515">"Col2"</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">public const string </span><span style="background: white; color: black">Col3 = </span><span style="background: white; color: #a31515">"Col3"</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">public const string </span><span style="background: white; color: black">Col4 = </span><span style="background: white; color: #a31515">"Col4"</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">public const string </span><span style="background: white; color: black">Col6 = </span><span style="background: white; color: #a31515">"Col6"</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">public const string </span><span style="background: white; color: black">Col8 = </span><span style="background: white; color: #a31515">"Col8"</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">public const string </span><span style="background: white; color: black">Col12 = </span><span style="background: white; color: #a31515">"Col12"</span><span style="background: white; color: black">;
}</span></code></pre>
<a href="http://11011.net/software/vspaste"></a>
<div style="clear:both;"><strong>Third, I added my custom css to /module.config</strong></div>
<pre class="language-csharp"><code><span style="background: white; color: blue"><?</span><span style="background: white; color: #a31515">xml </span><span style="background: white; color: red">version</span><span style="background: white; color: blue">=</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">1.0</span><span style="background: white; color: black">" </span><span style="background: white; color: red">encoding</span><span style="background: white; color: blue">=</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">utf-8</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">?>
<</span><span style="background: white; color: #a31515">module</span><span style="background: white; color: blue">>
<</span><span style="background: white; color: #a31515">assemblies</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: #a31515">assemblies</span><span style="background: white; color: blue">>
<</span><span style="background: white; color: #a31515">clientResources</span><span style="background: white; color: blue">>
<</span><span style="background: white; color: #a31515">add </span><span style="background: white; color: red">name</span><span style="background: white; color: blue">=</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">epi-cms.widgets.base</span><span style="background: white; color: black">" </span><span style="background: white; color: red">path</span><span style="background: white; color: blue">=</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">Styles/Styles.css</span><span style="background: white; color: black">" </span><span style="background: white; color: red">resourceType</span><span style="background: white; color: blue">=</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">Style</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">/>
</</span><span style="background: white; color: #a31515">clientResources</span><span style="background: white; color: blue">>
<</span><span style="background: white; color: #a31515">dojo</span><span style="background: white; color: blue">>
<!-- </span><span style="background: white; color: green">Add a mapping from alloy to ~/ClientResources/Scripts to the dojo loader configuration </span><span style="background: white; color: blue">-->
<</span><span style="background: white; color: #a31515">paths</span><span style="background: white; color: blue">>
<</span><span style="background: white; color: #a31515">add </span><span style="background: white; color: red">name</span><span style="background: white; color: blue">=</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">alloy</span><span style="background: white; color: black">" </span><span style="background: white; color: red">path</span><span style="background: white; color: blue">=</span><span style="background: white; color: black">"</span><span style="background: white; color: blue">Scripts</span><span style="background: white; color: black">" </span><span style="background: white; color: blue">/>
</</span><span style="background: white; color: #a31515">paths</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: #a31515">dojo</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: #a31515">module</span><span style="background: white; color: blue">></span></code></pre>
<a href="http://11011.net/software/vspaste"></a>
<div style="clear:both;">and added my Css inside Styles.css. This code don’t use any images.</div>
<pre class="language-csharp"><code><span style="background: white; color: maroon">.Sleek .LayoutGrid </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">height</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">28px</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">44px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">height</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">28px</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">44px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid:before </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">content</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">''</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">display</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">block</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">float</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">left</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">background-color</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">silver</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">border</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">1px solid silver</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">margin</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">1px</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">height</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">24px</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">padding</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">0</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid:after </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">content</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">''</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">display</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">block</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">float</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">left</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">background-color</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">white</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">margin</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">1px</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">padding</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">0</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">border</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">1px solid silver</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">height</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">24px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col12:before </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">40px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col12:after </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">display</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">none</span><span style="background: white; color: black">;
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">12px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col8:before </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">24px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col8:after </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">12px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col6:before </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">18px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col6:after </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">18px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col4:before </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">12px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col4:after </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">24px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col3:before </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">9px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col3:after </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">27px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col2:before </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">6px</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: maroon">.Sleek .LayoutGrid.col2:after </span><span style="background: white; color: black">{
</span><span style="background: white; color: red">width</span><span style="background: white; color: black">: </span><span style="background: white; color: blue">30px</span><span style="background: white; color: black">;
}</span></code></pre>
<a href="http://11011.net/software/vspaste"></a>
<div style="clear:both;"><strong>Forth, I created my own content render ContentAreaRendererWithDisplayOptionWithCss</strong></div>
<div style="clear:both">Added a default Css render value DefaultChildrenCssClass that will be used if no Css Class is defined<br />
@Html.PropertyFor(p => p.CurrentPage.Common_Tasks, new { CssClass = "row", ChildrenCustomTagName = "div", DefaultChildrenCssClass = "col-md-3",Tag="Box" })
</div>
<pre class="language-csharp"><code><span style="background: white; color: blue">public class </span><span style="background: white; color: #2b91af">ContentAreaRendererWithDisplayOptionWithCss </span><span style="background: white; color: black">: </span><span style="background: white; color: #2b91af">ContentAreaRenderer
</span><span style="background: white; color: black">{
</span><span style="background: white; color: blue">private readonly </span><span style="background: white; color: #2b91af">DisplayOptions </span><span style="background: white; color: black">_displayOptionsOwn;
</span><span style="background: white; color: blue">private readonly </span><span style="background: white; color: #2b91af">IContentRepository </span><span style="background: white; color: black">_contentRepositoryOwn;
</span><span style="background: white; color: blue">public </span><span style="background: white; color: black">ContentAreaRendererWithDisplayOptionWithCss()
: </span><span style="background: white; color: blue">this</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">ServiceLocator</span><span style="background: white; color: black">.Current.GetInstance<</span><span style="background: white; color: #2b91af">IContentRenderer</span><span style="background: white; color: black">>(), </span><span style="background: white; color: #2b91af">ServiceLocator</span><span style="background: white; color: black">.Current.GetInstance<</span><span style="background: white; color: #2b91af">TemplateResolver</span><span style="background: white; color: black">>(), </span><span style="background: white; color: #2b91af">ServiceLocator</span><span style="background: white; color: black">.Current.GetInstance<</span><span style="background: white; color: #2b91af">ContentFragmentAttributeAssembler</span><span style="background: white; color: black">>(), </span><span style="background: white; color: #2b91af">ServiceLocator</span><span style="background: white; color: black">.Current.GetInstance<</span><span style="background: white; color: #2b91af">IContentRepository</span><span style="background: white; color: black">>(), </span><span style="background: white; color: #2b91af">ServiceLocator</span><span style="background: white; color: black">.Current.GetInstance<</span><span style="background: white; color: #2b91af">DisplayOptions</span><span style="background: white; color: black">>())
{
}
</span><span style="background: white; color: blue">public </span><span style="background: white; color: black">ContentAreaRendererWithDisplayOptionWithCss(</span><span style="background: white; color: #2b91af">IContentRenderer </span><span style="background: white; color: black">contentRenderer, </span><span style="background: white; color: #2b91af">TemplateResolver </span><span style="background: white; color: black">templateResolver, </span><span style="background: white; color: #2b91af">ContentFragmentAttributeAssembler </span><span style="background: white; color: black">attributeAssembler, </span><span style="background: white; color: #2b91af">IContentRepository </span><span style="background: white; color: black">contentRepository, </span><span style="background: white; color: #2b91af">DisplayOptions </span><span style="background: white; color: black">displayOptions)
: </span><span style="background: white; color: blue">base</span><span style="background: white; color: black">(contentRenderer, templateResolver, attributeAssembler, contentRepository, displayOptions)
{
_displayOptionsOwn = displayOptions;
_contentRepositoryOwn = contentRepository;
}
</span><span style="background: white; color: blue">public string </span><span style="background: white; color: black">DefaultChildrenCssClass { </span><span style="background: white; color: blue">get</span><span style="background: white; color: black">; </span><span style="background: white; color: blue">set</span><span style="background: white; color: black">; }
</span><span style="background: white; color: blue">protected override void </span><span style="background: white; color: black">RenderContentAreaItem(</span><span style="background: white; color: #2b91af">HtmlHelper </span><span style="background: white; color: black">htmlHelper, </span><span style="background: white; color: #2b91af">ContentAreaItem </span><span style="background: white; color: black">contentAreaItem, </span><span style="background: white; color: blue">string </span><span style="background: white; color: black">templateTag, </span><span style="background: white; color: blue">string </span><span style="background: white; color: black">htmlTag, </span><span style="background: white; color: blue">string </span><span style="background: white; color: black">cssClass)
{
</span><span style="background: white; color: #2b91af">ViewContext </span><span style="background: white; color: black">viewContext = htmlHelper.ViewContext;
DefaultChildrenCssClass = viewContext.ViewData[</span><span style="background: white; color: #a31515">"defaultchildrencssclass"</span><span style="background: white; color: black">] </span><span style="background: white; color: blue">as string</span><span style="background: white; color: black">;
</span><span style="background: white; color: #2b91af">IContent </span><span style="background: white; color: black">content = contentAreaItem.GetContent(</span><span style="background: white; color: blue">this</span><span style="background: white; color: black">._contentRepositoryOwn);
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(content == </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
{
</span><span style="background: white; color: blue">return</span><span style="background: white; color: black">;
}
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">templateModel = </span><span style="background: white; color: blue">this</span><span style="background: white; color: black">.ResolveTemplate(htmlHelper, content, templateTag);
</span><span style="background: white; color: blue">base</span><span style="background: white; color: black">.RenderContentAreaItem(htmlHelper, contentAreaItem, templateTag, htmlTag,</span><span style="background: white; color: #a31515">"tag_"</span><span style="background: white; color: black">+templateTag+</span><span style="background: white; color: #a31515">" resolver_"</span><span style="background: white; color: black">+((templateModel==</span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)?</span><span style="background: white; color: #a31515">"none"</span><span style="background: white; color: black">:templateModel.Name)+</span><span style="background: white; color: #a31515">" "</span><span style="background: white; color: black">+ cssClass);
}
</span><span style="background: white; color: blue">protected override string </span><span style="background: white; color: black">GetContentAreaItemTemplateTag(</span><span style="background: white; color: #2b91af">HtmlHelper </span><span style="background: white; color: black">htmlHelper, </span><span style="background: white; color: #2b91af">ContentAreaItem </span><span style="background: white; color: black">contentAreaItem)
{
</span><span style="background: white; color: #2b91af">DisplayOption </span><span style="background: white; color: black">displayOption = LoadDisplayOption(contentAreaItem);
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(displayOption != </span><span style="background: white; color: blue">null </span><span style="background: white; color: black">&& !</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">.IsNullOrEmpty(displayOption.Tag))
{
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">displayOption.Tag;
}
</span><span style="background: white; color: blue">return this</span><span style="background: white; color: black">.GetContentAreaTemplateTag(htmlHelper);
}
</span><span style="background: white; color: blue">protected override void </span><span style="background: white; color: black">BeforeRenderContentAreaItemStartTag(System.Web.Mvc.</span><span style="background: white; color: #2b91af">TagBuilder </span><span style="background: white; color: black">tagBuilder, EPiServer.Core.</span><span style="background: white; color: #2b91af">ContentAreaItem </span><span style="background: white; color: black">contentAreaItem)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">displayOption = LoadDisplayOption(contentAreaItem) </span><span style="background: white; color: blue">as </span><span style="background: white; color: #2b91af">DisplayOptionWithCss</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(displayOption != </span><span style="background: white; color: blue">null </span><span style="background: white; color: black">&& !</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">.IsNullOrEmpty(displayOption.CssClass))
{
tagBuilder.AddCssClass(displayOption.CssClass);
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(displayOption != </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
tagBuilder.Attributes[</span><span style="background: white; color: #a31515">"data-displayOption"</span><span style="background: white; color: black">] = displayOption.Id;
}
</span><span style="background: white; color: blue">else
</span><span style="background: white; color: black">AddNonEmptyCssClass(tagBuilder, DefaultChildrenCssClass);
}
</span><span style="background: white; color: blue">protected </span><span style="background: white; color: #2b91af">DisplayOption </span><span style="background: white; color: black">LoadDisplayOption(</span><span style="background: white; color: #2b91af">ContentAreaItem </span><span style="background: white; color: black">contentAreaItem)
{
</span><span style="background: white; color: blue">string </span><span style="background: white; color: black">displayOptionId = </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(contentAreaItem.RenderSettings != </span><span style="background: white; color: blue">null </span><span style="background: white; color: black">&& contentAreaItem.RenderSettings.ContainsKey(EPiServer.Core.Html.StringParsing.</span><span style="background: white; color: #2b91af">ContentFragment</span><span style="background: white; color: black">.ContentDisplayOptionAttributeName))
displayOptionId = </span><span style="background: white; color: #a31515">"" </span><span style="background: white; color: black">+ contentAreaItem.RenderSettings[EPiServer.Core.Html.StringParsing.</span><span style="background: white; color: #2b91af">ContentFragment</span><span style="background: white; color: black">.ContentDisplayOptionAttributeName];
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">.IsNullOrEmpty(displayOptionId))
</span><span style="background: white; color: blue">return null</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">_displayOptionsOwn.Get(displayOptionId);
}
}</span></code></pre>
<a href="http://11011.net/software/vspaste"></a>
<div style="clear:both;"><strong>Finally, I changed the default render to use my own contentarea render</strong></div>
<pre class="language-csharp"><code><span style="background: white; color: black">[</span><span style="background: white; color: #2b91af">InitializableModule</span><span style="background: white; color: black">]
</span><span style="background: white; color: blue">public class </span><span style="background: white; color: #2b91af">DependencyResolverInitialization </span><span style="background: white; color: black">: </span><span style="background: white; color: #2b91af">IConfigurableModule
</span><span style="background: white; color: black">{
</span><span style="background: white; color: blue">public void </span><span style="background: white; color: black">ConfigureContainer(</span><span style="background: white; color: #2b91af">ServiceConfigurationContext </span><span style="background: white; color: black">context)
{
context.Container.Configure(ConfigureContainer);
}
</span><span style="background: white; color: blue">private static void </span><span style="background: white; color: black">ConfigureContainer(</span><span style="background: white; color: #2b91af">ConfigurationExpression </span><span style="background: white; color: black">container)
{
</span><span style="background: white; color: green">//Swap out the default ContentRenderer for our custom
// container.For<IContentRenderer>().Use<ErrorHandlingContentRenderer>();
</span><span style="background: white; color: black">container.For<</span><span style="background: white; color: #2b91af">ContentAreaRenderer</span><span style="background: white; color: black">>().Use<</span><span style="background: white; color: #2b91af">ContentAreaRendererWithDisplayOptionWithCss</span><span style="background: white; color: black">>();
</span><span style="background: white; color: green">//Implementations for custom interfaces can be registered here.
</span><span style="background: white; color: black">}
</span><span style="background: white; color: blue">public void </span><span style="background: white; color: black">Initialize(</span><span style="background: white; color: #2b91af">InitializationEngine </span><span style="background: white; color: black">context)
{
}
</span><span style="background: white; color: blue">public void </span><span style="background: white; color: black">Uninitialize(</span><span style="background: white; color: #2b91af">InitializationEngine </span><span style="background: white; color: black">context)
{
}
</span><span style="background: white; color: blue">public void </span><span style="background: white; color: black">Preload(</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">[] parameters)
{
}
}
</span></code></pre>
<a href="http://11011.net/software/vspaste"></a>
<div style="clear:both;">And that’s it. Now you can have the display option to change the CSS of the items in a contentarea and have it to change the tag.</div>
Error when copy a page structure
/blogs/Anders-Hattestad/Dates/2014/8/Error-when-copy-a-page-structure/
2014-08-08T12:33:57.0000000Z
<p>If you experience that you get an error when trying to copy or export/import a page tree the reason could be that you are missing some files in the VPP (7.0) or Appdata(7.5).</p> <p>What you then need is to find what files you are missing. I have made a small utility that loops thru all properties, checks the IReferenceMap, and finds all documents and check if the file actually exists on the disk. </p> <p>It can be added as a gagdet: <br /><a href="/link/30d0e19947724fa98a945555bec33b39.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/9fe8af5272c24e6289626e3d9c2a8086.png" width="424" height="174" /></a> </p> <p>An will be shown like: <br /><a href="/link/bbab5022bd6545598c02d6af37dbb2b3.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/b05faefec07f4528a7dcda26a3f2e77c.png" width="402" height="209" /></a></p> <p>The code is simple and is</p> <pre class="language-csharp"><code> [IFrameComponent(
Url = <span class="str">"~/Custom/Plugins/CheckFiles.aspx"</span>,
ReloadOnContextChange = <span class="kwrd">true</span>,
PlugInAreas = <span class="str">"/episerver/cms/assets"</span>,
Title = <span class="str">"Check files used"</span>,
Categories = <span class="str">"cms"</span>, MinHeight = 100, MaxHeight = 500)]
<span class="rem">//Update: In EPiServer 7.5, the base class to use is: EPiServer.Shell.WebForms.ContentWebFormsBase</span>
<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> CheckFiles : ContentBaseWebForm
{
<span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
{
PageName.InnerHtml = CurrentContent.Name;
PageName.Attributes[<span class="str">"title"</span>] = <span class="str">""</span> + CurrentContent.ContentLink;
}
<span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnLoad(EventArgs e)
{
<span class="kwrd">base</span>.OnLoad(e);
<span class="kwrd">if</span> (UrlRewriteProvider.Module != <span class="kwrd">null</span>)
{
UrlRewriteProvider.Module.FURLRewriteResponse = <span class="kwrd">false</span>;
}
}
<span class="kwrd">protected</span> <span class="kwrd">void</span> BtnClicked_Click(<span class="kwrd">object</span> sender, EventArgs e)
{
var statusDic = <span class="kwrd">new</span> Dictionary<Guid, GuidStatus>();
Check(CurrentContent, statusDic, <span class="str">""</span>, DoChildren.Checked, CheckLinkedItems.Checked);<span class="rem">// CheckContent(CurrentContent, statusDic, CurrentContent.Name + "[" + CurrentContent.ContentLink + "]", DoChildren.Checked); </span>
var txt=<span class="str">""</span>;
var dontExists = statusDic.Values.Where(p => !p.Exists).ToList(); ;
txt+=<span class="str">"Dont exists:"</span>+dontExists.Count;
<span class="kwrd">foreach</span> (var item <span class="kwrd">in</span> dontExists)
{
txt+=<span class="str">"<div>* "</span>+item.UsedWhere+<span class="str">":<br />"</span>+ item.Name+<span class="str">" <div>"</span>+item.Debug+<span class="str">"</div></div>"</span>;
}
DebugLit.Text = txt;
}
GuidStatus CheckGuid(Guid guid)
{
var result = <span class="kwrd">new</span> GuidStatus();
result.Guid = guid;
var map = EPiServer.Web.PermanentLinkMapper.Instance.Find(guid);
<span class="kwrd">if</span> (map <span class="kwrd">is</span> EPiServer.Web.PermanentContentLinkMap)
{
result.TargetType = <span class="str">"PAGE"</span>;
<span class="kwrd">try</span> {
var p=EPiServer.DataFactory.Instance.Get<IContent>((map <span class="kwrd">as</span> EPiServer.Web.PermanentContentLinkMap).ContentReference);
result.Exists = <span class="kwrd">true</span>;
result.Content = p;
result.Name = p.Name + <span class="str">" ["</span> + (map <span class="kwrd">as</span> EPiServer.Web.PermanentContentLinkMap).ContentReference + <span class="str">"]"</span>;
}
<span class="kwrd">catch</span> (System.Exception error)
{
result.Exists = <span class="kwrd">false</span>;
result.Debug = error.Message;
}
}
<span class="kwrd">if</span> (map <span class="kwrd">is</span> EPiServer.Web.PermanentFileLinkMap)
{
result.TargetType = <span class="str">"FILE"</span>;
var filMap = (map <span class="kwrd">as</span> EPiServer.Web.PermanentFileLinkMap);
<span class="kwrd">if</span> (filMap != <span class="kwrd">null</span> && filMap.MappedUrl != <span class="kwrd">null</span>)
{
var filPath = Uri.UnescapeDataString(filMap.MappedUrl.ToString());
result.Name = filPath;
<span class="kwrd">if</span> (System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists(filPath))
{
var fil = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(filPath);
<span class="kwrd">try</span>
{
result.Exists = <span class="kwrd">false</span>;
<span class="kwrd">using</span> (var stream = fil.Open())
{
<span class="kwrd">if</span> (stream.ReadByte() > -1)
{
result.Exists = <span class="kwrd">true</span>;
}
}
}
<span class="kwrd">catch</span> (System.Exception error)
{
result.Exists = <span class="kwrd">false</span>;
result.Debug = error.Message;
}
}
}
}
<span class="kwrd">return</span> result;
}
<span class="kwrd">string</span> IContentName(IContent content)
{
<span class="kwrd">return</span> content.Name + <span class="str">" ["</span> + content.ContentLink + <span class="str">"]"</span>;
}
<span class="kwrd">void</span> Check(IContent content, Dictionary<Guid, GuidStatus> status, <span class="kwrd">string</span> path, <span class="kwrd">bool</span> addChildren,<span class="kwrd">bool</span> checkLinkedItems)
{
var contentName = IContentName(content);
<span class="kwrd">if</span> (!status.ContainsKey(content.ContentGuid))
{
status.Add(content.ContentGuid, <span class="kwrd">new</span> GuidStatus() { Exists = <span class="kwrd">true</span>, Name = contentName, UsedWhere = path });
}
Check(content <span class="kwrd">as</span> IContentData, status, path + contentName, addChildren);
<span class="kwrd">if</span> (checkLinkedItems)
{
var toDo = status.Values.Where(p => p.Parse).ToList();
<span class="kwrd">foreach</span> (var toDoItem <span class="kwrd">in</span> toDo)
{
toDoItem.Parse = <span class="kwrd">false</span>;
}
<span class="kwrd">foreach</span> (var toDoItem <span class="kwrd">in</span> toDo)
{
<span class="kwrd">if</span> (toDoItem.Content != <span class="kwrd">null</span>)
{
Check(toDoItem.Content, status, toDoItem.Name, <span class="kwrd">false</span>,<span class="kwrd">false</span>);
}
}
}
<span class="kwrd">if</span> (addChildren)
{
var children = EPiServer.DataFactory.Instance.GetChildren<IContent>(content.ContentLink);
<span class="kwrd">foreach</span> (var child <span class="kwrd">in</span> children)
{
Check(child, status, <span class="str">""</span>, addChildren, checkLinkedItems);
}
}
}
<span class="kwrd">void</span> Check(IContentData content, Dictionary<Guid, GuidStatus> status, <span class="kwrd">string</span> path, <span class="kwrd">bool</span> addChildren)
{
<span class="kwrd">foreach</span> (var prop <span class="kwrd">in</span> content.Property)
{
Check(prop, status, path+<span class="str">"."</span>+prop.Name, addChildren);
}
}
<span class="kwrd">void</span> Check(PropertyData prop, Dictionary<Guid, GuidStatus> status, <span class="kwrd">string</span> path, <span class="kwrd">bool</span> addChildren)
{
var refMap = prop <span class="kwrd">as</span> IReferenceMap;
<span class="kwrd">if</span> (refMap != <span class="kwrd">null</span>)
{
var guids = refMap.ReferencedPermanentLinkIds;
<span class="kwrd">if</span> (guids.Count > 0)
{
<span class="kwrd">foreach</span> (var filGuid <span class="kwrd">in</span> refMap.ReferencedPermanentLinkIds)
{
<span class="kwrd">if</span> (!status.ContainsKey(filGuid))
{
var check = CheckGuid(filGuid);
check.UsedWhere = path;
status.Add(filGuid, check); ;
<span class="kwrd">if</span> (check.Content != <span class="kwrd">null</span>)
{
check.Parse = <span class="kwrd">true</span>;
<span class="rem">//Check(check.Content, status, path + " =>", false);</span>
}
}
}
}
}
<span class="kwrd">else</span> <span class="kwrd">if</span> (prop <span class="kwrd">is</span> IContentData)
{
Check((prop <span class="kwrd">as</span> IContentData), status, path , <span class="kwrd">false</span>);
}
}
<span class="kwrd">public</span> <span class="kwrd">class</span> GuidStatus
{
<span class="kwrd">public</span> Guid Guid { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> UsedWhere { get; set; }
<span class="kwrd">public</span> <span class="kwrd">string</span> TargetType { get; set; }
<span class="kwrd">public</span> <span class="kwrd">bool</span> Exists {get;set;}
<span class="kwrd">public</span> <span class="kwrd">string</span> Debug { get; set; }
<span class="kwrd">public</span> IContent Content { get; set; }
<span class="kwrd">public</span> <span class="kwrd">bool</span> Parse { get; set; }
}
}</code></pre>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
<p>And the front code is</p>
<pre class="language-csharp"><code><span class="asp"><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CheckFiles.aspx.cs" Inherits="Itera.Custom.PlugIns.CheckFiles" %></span>
<span class="kwrd"><!</span><span class="html">DOCTYPE</span> <span class="attr">html</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">="http://www.w3.org/1999/xhtml"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">title</span><span class="kwrd">></</span><span class="html">title</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">head</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">body</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="form1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">div</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">h2</span> <span class="attr">id</span><span class="kwrd">="PageName"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">asp:Button</span> <span class="attr">ID</span><span class="kwrd">="BtnClicked"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Check"</span> <span class="attr">OnClick</span><span class="kwrd">="BtnClicked_Click"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">asp:CheckBox</span> <span class="attr">ID</span><span class="kwrd">="DoChildren"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Check children also"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">asp:CheckBox</span> <span class="attr">ID</span><span class="kwrd">="CheckLinkedItems"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Check linked items"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">div</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:Literal</span> <span class="attr">id</span><span class="kwrd">="DebugLit"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">div</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">div</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">form</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">body</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">html</span><span class="kwrd">></span></code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
EPiServer 7 and MVC Views using Tags
/blogs/Anders-Hattestad/Dates/2014/3/EPiServer-7-and-MVC-Views-using-Tags/
2014-03-18T21:17:40.0000000Z
<p>The pattern I use for utilize the MVC framework and EPiServer blocks is based on inheritance and the use of tags. I have one Default block controller that handles all the blocks. </p> <p>If a BlockTypeA that inherits from BlockData with tag=”Col4” if will look for </p> <ul> <li>/Views/Partials/Col4/BlockTypeA.cshtml </li> <li>/Views/Partials/Col4/BlockData.cshtml </li> <li>/Views/Partials/Default/BlockTypeA.cshtml </li> <li>/Views/Partials/Default/BlockData.cshtml </li> </ul> <p>Then it will pick the first view that exists. This enables us to serve different result depending on the tag. However, it is optional so one could only add the view in the default tag folder. One could also make a BlockTypeB that inherits from BlockTypeA and only change the default values, and then we do not need to add a new view.</p> <pre class="language-csharp"><code><span style="background: white; color: black">[</span><span style="background: white; color: #2b91af">TemplateDescriptor</span><span style="background: white; color: black">(Inherited = </span><span style="background: white; color: blue">true</span><span style="background: white; color: black">)]
</span><span style="background: white; color: blue">public class </span><span style="background: white; color: #2b91af">DefaultBlockController </span><span style="background: white; color: black">: </span><span style="background: white; color: #2b91af">BlockController</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">BlockData</span><span style="background: white; color: black">>
{
</span><span style="background: white; color: blue">public override </span><span style="background: white; color: #2b91af">ActionResult </span><span style="background: white; color: black">Index(</span><span style="background: white; color: #2b91af">BlockData </span><span style="background: white; color: black">currentBlock)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">tag = ControllerContext.ParentActionViewContext.ViewData[</span><span style="background: white; color: #a31515">"tag"</span><span style="background: white; color: black">] </span><span style="background: white; color: blue">as string </span><span style="background: white; color: black">?? </span><span style="background: white; color: #a31515">"Default"</span><span style="background: white; color: black">;
ViewData[</span><span style="background: white; color: #a31515">"Tag"</span><span style="background: white; color: black">] = tag;
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">path = </span><span style="background: white; color: #2b91af">FindViewer</span><span style="background: white; color: black">.Current.FindPartialTemplate(currentBlock, tag, </span><span style="background: white; color: #a31515">"Default"</span><span style="background: white; color: black">);
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">PartialView(path, currentBlock);
}
}</span></code></pre>
<p>The same concept do I use for the page templates. Instead of tags I’m using the channels.</p>
<pre class="language-csharp"><code><span style="background: white; color: black">[</span><span style="background: white; color: #2b91af">TemplateDescriptor</span><span style="background: white; color: black">(
Inherited = </span><span style="background: white; color: blue">true</span><span style="background: white; color: black">,
TemplateTypeCategory = </span><span style="background: white; color: #2b91af">TemplateTypeCategories</span><span style="background: white; color: black">.MvcController,
Tags = </span><span style="background: white; color: blue">new</span><span style="background: white; color: black">[] { </span><span style="background: white; color: #2b91af">RenderingTags</span><span style="background: white; color: black">.Preview, </span><span style="background: white; color: #2b91af">RenderingTags</span><span style="background: white; color: black">.Edit}, Default = </span><span style="background: white; color: blue">true</span><span style="background: white; color: black">,
AvailableWithoutTag = </span><span style="background: white; color: blue">true</span><span style="background: white; color: black">)]
</span><span style="background: white; color: blue">public class </span><span style="background: white; color: #2b91af">DefaultPageController </span><span style="background: white; color: black">: </span><span style="background: white; color: #2b91af">PageController</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">PageData</span><span style="background: white; color: black">>
{
</span><span style="background: white; color: blue">public </span><span style="background: white; color: #2b91af">ActionResult </span><span style="background: white; color: black">Index(</span><span style="background: white; color: #2b91af">PageData </span><span style="background: white; color: black">currentPage)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">tags = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">List</span><span style="background: white; color: black"><</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">> { </span><span style="background: white; color: #a31515">"Default" </span><span style="background: white; color: black">};
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">test = </span><span style="background: white; color: #2b91af">ServiceLocator</span><span style="background: white; color: black">.Current.GetInstance<</span><span style="background: white; color: #2b91af">DisplayChannelService</span><span style="background: white; color: black">>().GetActiveChannels(</span><span style="background: white; color: blue">this</span><span style="background: white; color: black">.ControllerContext.HttpContext).FirstOrDefault();
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(test != </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
tags.Insert(0, test.ChannelName);
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">type = </span><span style="background: white; color: blue">typeof</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">PageViewModel</span><span style="background: white; color: black"><>).MakeGenericType(currentPage.GetOriginalType());
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">model = </span><span style="background: white; color: #2b91af">Activator</span><span style="background: white; color: black">.CreateInstance(type, currentPage) </span><span style="background: white; color: blue">as </span><span style="background: white; color: #2b91af">IPageViewModel</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">PageData</span><span style="background: white; color: black">>;
model.CurrentObject = currentPage;
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">path = </span><span style="background: white; color: #2b91af">FindViewer</span><span style="background: white; color: black">.Current.FindMainTemplate(currentPage, </span><span style="background: white; color: #a31515">"Templates"</span><span style="background: white; color: black">, tags.ToArray());
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">View(path, model);
}
}</span></code></pre>
<p>If I have a ContentPage that inherits from SitePageData and I have selected Mobile channel the Controller will look for the first view that exists from these. </p>
<ul>
<li>/Views/Templates/Mobile/ContentPage.cshtml </li>
<li>/Views/Templates/Mobile/SitePageData.cshtml </li>
<li>/Views/Templates/Default/ContentPage.cshtml </li>
<li>/Views/Templates/ Default/SitePageData.cshtml </li>
</ul>
<p>Therefore, when I add a new pagetype I do not need to add a view for it, if it inherits from an existing type. Not that I usually have specific content for the mobile channel, but I have added myself some channels</p>
<p><a href="/link/f726514e5eeb4efca6c0c63e6e3f08fb.png"><img title="clip_image001[4]" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image001[4]" src="/link/5e74cc2d11f64094b9b143263f06fadb.png" width="244" height="239" /></a></p>
<p>There partial is a preview of this page in different kind of tags, and edit children will show an editable list of all the children for this page. The partial channel can so a page like this</p>
<a href="/link/5be14db989c747259f943563a6df10fe.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/4971769783d9475997e9ae8ebe1a38b8.png" width="644" height="476" /></a>
<p>With some of the code from /Views/Templates/Partial/SitePageData.cshtml like this</p>
<pre class="language-csharp"><code><span style="background: yellow; color: black">@model </span><span style="background: white; color: #2b91af">IPageViewModel</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">SitePageData</span><span style="background: white; color: black">>
</span><span style="background: yellow; color: black">@</span><span style="background: white; color: blue">using </span><span style="background: white; color: black">Itera.Web
</span><span style="background: white; color: blue"><</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="row addSpaceBellow">
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="col-md-3">
<</span><span style="background: white; color: maroon">h2</span><span style="background: white; color: blue">></span><span style="background: white; color: black">3 col</span><span style="background: white; color: blue"></</span><span style="background: white; color: maroon">h2</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="col-md-9">
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="row">
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="col-md-4">
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="hilightSelected">
</span><span style="background: yellow; color: black">@</span><span style="background: white; color: black">Html.RenderObjectMvcToString(Model.CurrentObject, </span><span style="background: white; color: #a31515">"Col4"</span><span style="background: white; color: black">,</span><span style="background: white; color: #a31515">"Default"</span><span style="background: white; color: black">)
</span><span style="background: white; color: blue"></</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="col-md-4">
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="hilight">
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="col-md-4">
<</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="hilight">
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
</</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">></span></code></pre>
<p>I use the same functions for handling the edit/preview of blocks and blobs. </p>
<pre class="language-csharp"><code><span style="background: white; color: black">[</span><span style="background: white; color: #2b91af">TemplateDescriptor</span><span style="background: white; color: black">(
Inherited = </span><span style="background: white; color: blue">true</span><span style="background: white; color: black">,
TemplateTypeCategory = </span><span style="background: white; color: #2b91af">TemplateTypeCategories</span><span style="background: white; color: black">.MvcController, </span><span style="background: white; color: green">//Required as controllers for blocks are registered as MvcPartialController by default
</span><span style="background: white; color: black">Tags = </span><span style="background: white; color: blue">new</span><span style="background: white; color: black">[] { </span><span style="background: white; color: #2b91af">RenderingTags</span><span style="background: white; color: black">.Preview, </span><span style="background: white; color: #2b91af">RenderingTags</span><span style="background: white; color: black">.Edit }, Default = </span><span style="background: white; color: blue">true</span><span style="background: white; color: black">,
AvailableWithoutTag = </span><span style="background: white; color: blue">false</span><span style="background: white; color: black">)]
</span><span style="background: white; color: blue">public class </span><span style="background: white; color: #2b91af">PreviewController </span><span style="background: white; color: black">: </span><span style="background: white; color: #2b91af">ActionControllerBase</span><span style="background: white; color: black">, </span><span style="background: white; color: #2b91af">IRenderTemplate</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">ContentData</span><span style="background: white; color: black">>
{
</span><span style="background: white; color: blue">public </span><span style="background: white; color: #2b91af">ActionResult </span><span style="background: white; color: black">Index(</span><span style="background: white; color: #2b91af">ContentData </span><span style="background: white; color: black">currentContent)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">tags = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">List</span><span style="background: white; color: black"><</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">> { </span><span style="background: white; color: #a31515">"Partial" </span><span style="background: white; color: black">};
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">startPage = _contentLoader.Get<</span><span style="background: white; color: #2b91af">PageData</span><span style="background: white; color: black">>(</span><span style="background: white; color: #2b91af">ContentReference</span><span style="background: white; color: black">.StartPage);
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">type = </span><span style="background: white; color: blue">typeof</span><span style="background: white; color: black">(</span><span style="background: white; color: #2b91af">PageViewModel</span><span style="background: white; color: black"><>).MakeGenericType(startPage.GetOriginalType());
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">model = </span><span style="background: white; color: #2b91af">Activator</span><span style="background: white; color: black">.CreateInstance(type, startPage) </span><span style="background: white; color: blue">as </span><span style="background: white; color: #2b91af">IPageViewModel</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">PageData</span><span style="background: white; color: black">>;
model.CurrentObject = currentContent;
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">path = </span><span style="background: white; color: #2b91af">FindViewer</span><span style="background: white; color: black">.Current.FindMainTemplate(currentContent, </span><span style="background: white; color: #a31515">"Templates"</span><span style="background: white; color: black">, tags.ToArray());
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">View(path, model);
}</span></code></pre>
<p><a href="/link/1120e8fde860461ea18a69b54e4c5777.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/a3cd37e753b34aa582ae2db205d34fd6.png" width="323" height="438" /></a></p>
<p>When it comes to so pages or blocks from a content area I had to add some code in the ContentAreaRenderer.</p>
<p>Instead of adding classes to the render from code I add a wrapper class (PartialViewWithLayout) if the tag is set, and render that item. That view will then add the layout classes, and then add the EPiServer edit tag div, then render the content with the current tag.</p>
<pre class="language-csharp"><code><span style="background: yellow; color: black">@model </span><span style="background: white; color: black">Itera.Web.Models.</span><span style="background: white; color: #2b91af">PartialViewWithLayout
</span><span style="background: yellow; color: black">@</span><span style="background: white; color: blue">using </span><span style="background: white; color: black">Itera.Web
</span><span style="background: white; color: blue"><</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">class</span><span style="background: white; color: blue">="col-md-4">
</span><span style="background: yellow; color: black">@</span><span style="background: white; color: black">Html.Raw(Model.TagBuilder.ToString(</span><span style="background: white; color: #2b91af">TagRenderMode</span><span style="background: white; color: black">.StartTag))
</span><span style="background: yellow; color: black">@</span><span style="background: white; color: black">Html.RenderObjectMvcToString(Model.Content,Model.Tag,</span><span style="background: white; color: #a31515">"Default"</span><span style="background: white; color: black">)
</span><span style="background: white; color: blue"><</span><span style="background: white; color: maroon">div </span><span style="background: white; color: red">style</span><span style="background: white; color: blue">="</span><span style="background: white; color: red">clear</span><span style="background: white; color: black">:</span><span style="background: white; color: blue">both"></</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">>
</span><span style="background: yellow; color: black">@</span><span style="background: white; color: black">Html.Raw(Model.TagBuilder.ToString(</span><span style="background: white; color: #2b91af">TagRenderMode</span><span style="background: white; color: black">.EndTag))
</span><span style="background: white; color: blue"></</span><span style="background: white; color: maroon">div</span><span style="background: white; color: blue">></span></code></pre>
<p><a href="/link/2633508aa3d64bfbbe508fa59ac4a602.jpg"><img title="clip_image004[4]" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image004[4]" src="/link/c133a620775048208c901086548a02e2.jpg" width="609" height="229" /></a></p>
<p>I also have made myself some easy to use extension methods like the RenderObjectMvcString that will render the object and find the view from different tags.</p>
<p>Have uploaded a sample prosject with these functions <a href="http://world.episerver.com/Code/Anders-Hattestad1/IteraCoreWeb/">here</a></p>
Query content of inherit type or those that implements an interface
/blogs/Anders-Hattestad/Dates/2014/2/Query-content-of-inherit-type-or-those-that-implements-an-interface/
2014-02-18T14:41:29.0000000Z
<p>Sometimes when I do import jobs, I check if a content type have a specific property. If a page exists I update it, and if not I create a new. Other times I want to find some pages that inherits form a basepage type and get those pages that have some properties set. <br />To find a page if it exists with testKey I used </p> <pre class="language-csharp"><code><span style="background: white; color: blue">var </span><span style="background: white; color: black">items = ContentModelUsage.Service.ListContentOfContentType(
ContentTypeRepository.Service.Load<</span><span style="background: white; color: #2b91af">MyPageType</span><span style="background: white; color: black">>())
.Select(x =>
x.ContentLink.CreateReferenceWithoutVersion())
.Distinct()
.Select(x => ContentLoader.Service.Get<</span><span style="background: white; color: #2b91af">MyPageType</span><span style="background: white; color: black">>(x))
.OfType<</span><span style="background: white; color: #2b91af">MyPageType</span><span style="background: white; color: black">>()
.Where(p => !p.IsDeleted)
.Where(p => p.MyTestProperty == testKey)
.ToList();</span></code></pre>
<p>The problem with this code is that it is slow. I could of course grab all items, and select on that collection, but then I need to update the list with new items. The ListContentOfContentType takes in my case 350ms to execute, and the Get<mypagetype> takes practical zero ms (after first time). Therefore, what I will do is to cache the ListContentOfType, but clear it content is added or removed.</mypagetype></p>
<p>Another problem is that the above code does not find content that inherits MyPageType, or implements an interface. </p>
<p>I therefore made myself a method that finds all content types that is, or inherits or implements an interface.</p>
<pre class="language-csharp"><code><span style="background: white; color: blue">public static </span><span style="background: white; color: #2b91af">List</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">ContentType</span><span style="background: white; color: black">> GetContentTypesOfType(</span><span style="background: white; color: #2b91af">Type </span><span style="background: white; color: black">inheritTypeOrInterface)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">list = ContentTypeRepository.Service.List().
Where(
p => p.ModelType != </span><span style="background: white; color: blue">null </span><span style="background: white; color: black">&&
(
p.ModelType.IsSubclassOf(inheritTypeOrInterface) ||
p.ModelType == inheritTypeOrInterface ||
(inheritTypeOrInterface.IsInterface && inheritTypeOrInterface.IsAssignableFrom(p.ModelType))
)
).
ToList();
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">list;
}</span></code></pre>
<p>In addition, used that to find all content reference for a type or interface</p>
<pre class="language-csharp"><code><span style="background: white; color: blue">public static </span><span style="background: white; color: #2b91af">IList</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">ContentReference</span><span style="background: white; color: black">> GetReferenceOf(</span><span style="background: white; color: #2b91af">Type </span><span style="background: white; color: black">inheritTypeOrInterface)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">list = GetContentTypesOfType(inheritTypeOrInterface);
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">result = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">List</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">ContentReference</span><span style="background: white; color: black">>();
</span><span style="background: white; color: blue">foreach </span><span style="background: white; color: black">(</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">contentType </span><span style="background: white; color: blue">in </span><span style="background: white; color: black">list)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">subResult = GetUsagesSpesificType(contentType);
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(subResult != </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
result.AddRange(subResult);
}
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">result;
}
</span><span style="background: white; color: blue">public static </span><span style="background: white; color: #2b91af">IList</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">ContentReference</span><span style="background: white; color: black">> GetUsagesSpesificType(</span><span style="background: white; color: #2b91af">ContentType </span><span style="background: white; color: black">contentType)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">cacheKey = CacheKeyStart + contentType.ModelType;
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">result = EPiServer.</span><span style="background: white; color: #2b91af">CacheManager</span><span style="background: white; color: black">.Get(cacheKey) </span><span style="background: white; color: blue">as </span><span style="background: white; color: #2b91af">CacheResult</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(result == </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
{
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(contentType != </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">allItems = ContentModelUsage.Service.ListContentOfContentType(contentType).
Select(x => x.ContentLink.CreateReferenceWithoutVersion()).
Distinct().ToList();
result = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">CacheResult</span><span style="background: white; color: black">(allItems);
}
</span><span style="background: white; color: blue">else
</span><span style="background: white; color: black">{
result = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">CacheResult</span><span style="background: white; color: black">(</span><span style="background: white; color: blue">null</span><span style="background: white; color: black">);
}
EPiServer.</span><span style="background: white; color: #2b91af">CacheManager</span><span style="background: white; color: black">.Add(cacheKey, result, System.Web.Caching.</span><span style="background: white; color: #2b91af">CacheItemPriority</span><span style="background: white; color: black">.BelowNormal);
}
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">result.GetList();
}</span></code></pre>
<p>I cache the result for the specific contentType but not for the aggregate list. This is because it is difficult to clear the cache of those aggregate lists. I can therefore easy make a method that returns all content of a specific type or interface.</p>
<pre class="language-csharp"><code><span style="background: white; color: blue">public static </span><span style="background: white; color: #2b91af">List</span><span style="background: white; color: black"><T> GetContentOf<T>(</span><span style="background: white; color: #2b91af">ILanguageSelector </span><span style="background: white; color: black">selector)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">result = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">List</span><span style="background: white; color: black"><T>();
</span><span style="background: white; color: blue">foreach </span><span style="background: white; color: black">(</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">item </span><span style="background: white; color: blue">in </span><span style="background: white; color: black">ContentLoader.Service.GetItems(GetReferenceOf(</span><span style="background: white; color: blue">typeof</span><span style="background: white; color: black">(T)), selector))
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(item </span><span style="background: white; color: blue">is </span><span style="background: white; color: black">T)
result.Add((T)item);;
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">result;
}</span></code></pre>
<p>The only thing I need now is to clear the cache if new content is added or deleted.</p>
<pre class="language-csharp"><code><span style="background: white; color: blue">public void </span><span style="background: white; color: black">Initialize(EPiServer.Framework.Initialization.</span><span style="background: white; color: #2b91af">InitializationEngine </span><span style="background: white; color: black">context)
{
</span><span style="background: white; color: #2b91af">DataFactory</span><span style="background: white; color: black">.Instance.CreatedContent += Instance_ClearCache;
</span><span style="background: white; color: #2b91af">DataFactory</span><span style="background: white; color: black">.Instance.DeletedContent += Instance_ClearCache;
}
</span><span style="background: white; color: blue">void </span><span style="background: white; color: black">Instance_ClearCache(</span><span style="background: white; color: blue">object </span><span style="background: white; color: black">sender, </span><span style="background: white; color: #2b91af">ContentEventArgs </span><span style="background: white; color: black">e)
{
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(e.Content != </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">contentType=ContentTypeRepository.Service.Load(e.Content.GetOriginalType());
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(contentType != </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">cacheKey = CacheKeyStart + contentType.ModelType;
EPiServer.</span><span style="background: white; color: #2b91af">CacheManager</span><span style="background: white; color: black">.Remove(cacheKey);
}
}
}</span></code></pre>
<p>So it can be used to find pages that inherits from a base pagetype that have a BasePropertyName equals to shouldBe </p>
<pre class="language-csharp"><code><span style="background: white; color: blue">var </span><span style="background: white; color: black">items3 = </span><span style="background: white; color: #2b91af">FindContent</span><span style="background: white; color: black">.GetContentOf<BasePageType>(</span><span style="background: white; color: #2b91af">LanguageSelector</span><span style="background: white; color: black">.MasterLanguage()).
Where(p => !p.IsDeleted).
Where(p => p.BasePropertyName == shouldBe);
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">items4 = </span><span style="background: white; color: #2b91af">FindContent</span><span style="background: white; color: black">.GetContentOfExcludeDeleted<IHaveInterface>(</span><span style="background: white; color: #2b91af">LanguageSelector</span><span style="background: white; color: black">.MasterLanguage()).
Where(p => p.InterfaceName==shouldBe);</span></code></pre>
<p>The complete code is <a href="http://snipt.org/Ggqg7">here</a></p>
How to get html from a view and change the content in MVC
/blogs/Anders-Hattestad/Dates/2014/2/How-to-get-html-from-a-view-and-change-the-content-in-MVC/
2014-02-11T09:13:07.0000000Z
<p>There are times you want to manipulate the html after it has created to change image references, or change the links outputted to friendly URL’s. Here is a trick how to get the content out of a view in MVC and use the HtmlAgilityPack to change the content.</p> <p>If you have a view you want to render, for instance in the _Layout.cshtml and you want to change html you could have lines like this:</p> <pre class="language-csharp"><code><span style="background: white; color: black"> </span><span style="background: yellow; color: black">@</span><span style="background: white; color: black">Html.PropertyForWithChangeHtml(p => p.StartPage.Row1)
</span><span style="background: yellow; color: black">@</span><span style="background: white; color: black">Html.RenderViewWithChange(</span><span style="background: white; color: #a31515">"~/Views/MasterPages/HtmlFooter.cshtml"</span><span style="background: white; color: black">, Model)
</span></code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The extension code that will render the PropertyFor is like this:</p>
<pre class="language-csharp"><code><span style="background: white; color: blue">public static </span><span style="background: white; color: #2b91af">MvcHtmlString </span><span style="background: white; color: black">PropertyForWithChangeHtml<TModel, TValue>(</span><span style="background: white; color: blue">this </span><span style="background: white; color: #2b91af">HtmlHelper</span><span style="background: white; color: black"><TModel> html, </span><span style="background: white; color: #2b91af">Expression</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">Func</span><span style="background: white; color: black"><TModel, TValue>> expression)
{
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">PropertyForWithChangeHtml(html, expression, </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">);
}
</span><span style="background: white; color: blue">public static </span><span style="background: white; color: #2b91af">MvcHtmlString </span><span style="background: white; color: black">PropertyForWithChangeHtml<TModel, TValue>(</span><span style="background: white; color: blue">this </span><span style="background: white; color: #2b91af">HtmlHelper</span><span style="background: white; color: black"><TModel> html, </span><span style="background: white; color: #2b91af">Expression</span><span style="background: white; color: black"><</span><span style="background: white; color: #2b91af">Func</span><span style="background: white; color: black"><TModel, TValue>> expression, </span><span style="background: white; color: blue">object </span><span style="background: white; color: black">additionalViewData)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">result = html.PropertyFor(expression, additionalViewData);
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">htmlTxt = result.ToString();
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">htmlTxtChanged = ChangeHtml(htmlTxt);
</span><span style="background: white; color: blue">return new </span><span style="background: white; color: #2b91af">MvcHtmlString</span><span style="background: white; color: black">(htmlTxtChanged);
}</span></code></pre>
<p>And the code that will render a view is like this</p>
<pre class="language-csharp"><code><span style="background: white; color: blue">public static </span><span style="background: white; color: #2b91af">MvcHtmlString </span><span style="background: white; color: black">RenderViewWithChange(</span><span style="background: white; color: blue">this </span><span style="background: white; color: #2b91af">HtmlHelper </span><span style="background: white; color: black">html, </span><span style="background: white; color: blue">string </span><span style="background: white; color: black">viewName, </span><span style="background: white; color: blue">object </span><span style="background: white; color: black">model)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">htmlTxt = RenderViewToString(html.ViewContext, viewName, model);
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">htmlTxtChanged = ChangeHtml(htmlTxt);
</span><span style="background: white; color: blue">return new </span><span style="background: white; color: #2b91af">MvcHtmlString</span><span style="background: white; color: black">(htmlTxtChanged);
}
</span><span style="background: white; color: blue">public static string </span><span style="background: white; color: black">RenderViewToString(</span><span style="background: white; color: #2b91af">ControllerContext </span><span style="background: white; color: black">context, </span><span style="background: white; color: blue">string </span><span style="background: white; color: black">viewName, </span><span style="background: white; color: blue">object </span><span style="background: white; color: black">model)
{
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(</span><span style="background: white; color: blue">string</span><span style="background: white; color: black">.IsNullOrEmpty(viewName))
viewName = context.RouteData.GetRequiredString(</span><span style="background: white; color: #a31515">"action"</span><span style="background: white; color: black">);
</span><span style="background: white; color: #2b91af">ViewDataDictionary </span><span style="background: white; color: black">viewData = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">ViewDataDictionary</span><span style="background: white; color: black">(model);
</span><span style="background: white; color: blue">using </span><span style="background: white; color: black">(</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">sw = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">StringWriter</span><span style="background: white; color: black">())
{
</span><span style="background: white; color: #2b91af">ViewEngineResult </span><span style="background: white; color: black">viewResult = </span><span style="background: white; color: #2b91af">ViewEngines</span><span style="background: white; color: black">.Engines.FindPartialView(context, viewName);
</span><span style="background: white; color: #2b91af">ViewContext </span><span style="background: white; color: black">viewContext = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">ViewContext</span><span style="background: white; color: black">(context, viewResult.View, viewData, </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">TempDataDictionary</span><span style="background: white; color: black">(), sw);
viewResult.View.Render(viewContext, sw);
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">ChangeHtml(sw.GetStringBuilder().ToString());
}
}</span></code></pre>
<p>The actully changing of the html is easy with the HtmlAgilityPack. This code will ensure that all links are friendly EPiServer URL's</p>
<pre class="language-csharp"><code><span style="background: white; color: blue">public static string </span><span style="background: white; color: black">ChangeHtml(</span><span style="background: white; color: blue">string </span><span style="background: white; color: black">html)
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">doc = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">HtmlDocument</span><span style="background: white; color: black">();
doc.LoadHtml(html);
FiksNodes(doc.DocumentNode);
</span><span style="background: white; color: blue">return </span><span style="background: white; color: black">doc.DocumentNode.OuterHtml;
}
</span><span style="background: white; color: blue">public static void </span><span style="background: white; color: black">FiksNodes(</span><span style="background: white; color: #2b91af">HtmlNode </span><span style="background: white; color: black">node)
{
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(node.Attributes.Contains(</span><span style="background: white; color: #a31515">"href"</span><span style="background: white; color: black">))
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">val = node.Attributes[</span><span style="background: white; color: #a31515">"href"</span><span style="background: white; color: black">].Value;
ChangeLinkToFriendly(node, val, </span><span style="background: white; color: #a31515">"href"</span><span style="background: white; color: black">);
}
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(node.Name == </span><span style="background: white; color: #a31515">"form" </span><span style="background: white; color: black">&& node.Attributes.Contains(</span><span style="background: white; color: #a31515">"action"</span><span style="background: white; color: black">))
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">val = node.Attributes[</span><span style="background: white; color: #a31515">"action"</span><span style="background: white; color: black">].Value;
ChangeLinkToFriendly(node, val, </span><span style="background: white; color: #a31515">"action"</span><span style="background: white; color: black">);
}
</span><span style="background: white; color: blue">for </span><span style="background: white; color: black">(</span><span style="background: white; color: blue">int </span><span style="background: white; color: black">i = 0; i < node.ChildNodes.Count; i++)
{
FiksNodes(node.ChildNodes[i]);
}
}
</span><span style="background: white; color: blue">private static void </span><span style="background: white; color: black">ChangeLinkToFriendly(</span><span style="background: white; color: #2b91af">HtmlNode </span><span style="background: white; color: black">node, </span><span style="background: white; color: blue">string </span><span style="background: white; color: black">val, </span><span style="background: white; color: blue">string </span><span style="background: white; color: black">key)
{
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(val.StartsWith(</span><span style="background: white; color: #a31515">"/link/"</span><span style="background: white; color: black">))
{
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">decoded = </span><span style="background: white; color: #2b91af">HttpUtility</span><span style="background: white; color: black">.HtmlDecode(val);
</span><span style="background: white; color: blue">var </span><span style="background: white; color: black">url = </span><span style="background: white; color: blue">new </span><span style="background: white; color: #2b91af">UrlBuilder</span><span style="background: white; color: black">(decoded);
</span><span style="background: white; color: #2b91af">PageReference </span><span style="background: white; color: black">pageRef = </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">;
</span><span style="background: white; color: blue">if </span><span style="background: white; color: black">(url.QueryCollection[</span><span style="background: white; color: #a31515">"id"</span><span style="background: white; color: black">] != </span><span style="background: white; color: blue">null </span><span style="background: white; color: black">&& </span><span style="background: white; color: #2b91af">PageReference</span><span style="background: white; color: black">.TryParse(url.QueryCollection[</span><span style="background: white; color: #a31515">"id"</span><span style="background: white; color: black">], </span><span style="background: white; color: blue">out </span><span style="background: white; color: black">pageRef))
{
EPiServer.</span><span style="background: white; color: #2b91af">Global</span><span style="background: white; color: black">.UrlRewriteProvider.ConvertToExternal(url, pageRef, System.Text.</span><span style="background: white; color: #2b91af">UTF8Encoding</span><span style="background: white; color: black">.UTF8);
node.Attributes[key].Value = url.Uri.IsAbsoluteUri ? url.Uri.AbsoluteUri : url.Uri.OriginalString;
}
</span><span style="background: white; color: blue">else
</span><span style="background: white; color: black">{
EPiServer.</span><span style="background: white; color: #2b91af">Global</span><span style="background: white; color: black">.UrlRewriteProvider.ConvertToExternal(url, </span><span style="background: white; color: blue">null</span><span style="background: white; color: black">, System.Text.</span><span style="background: white; color: #2b91af">UTF8Encoding</span><span style="background: white; color: black">.UTF8);
node.Attributes[key].Value = url.Uri.IsAbsoluteUri ? url.Uri.AbsoluteUri : url.Uri.OriginalString;
}
node.Attributes.Add(</span><span style="background: white; color: #a31515">"data-changed-" </span><span style="background: white; color: black">+ key + </span><span style="background: white; color: #a31515">"-from"</span><span style="background: white; color: black">, val);
}
}</span></code></pre>
It’s too good damn hard
/blogs/Anders-Hattestad/Dates/2014/1/Its-too-good-damn-hard/
2014-01-24T11:25:52.0000000Z
<p>I’m struggling to make more advanced properties but I keep hitting my head against a wall. I have downloaded the source code for the dojo javascript stuff, but as far as I have seen I need to copy a lot to make my necessary modifications. I tried to add some options to the new content area display attribute based on the type, or make my own menu item. (the missing text is mine <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smilefjes" src="/link/addcc3dddf3043f8984f9983ba2a0f0f.aspx" />)</p>
<p>I know that you can add options here form the factory, but I wanted options based on the type, and to add a text box with override title and intro.</p>
<p><a href="/link/acb1164237d84bc29f261de65a2ead47.aspx"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image_thumb1" alt="image_thumb1" src="/link/650f07706e444d6aa4855b084fc12644.aspx" height="328" width="612" /></a></p>
<p>But the process is a bit to much. The steps you have to do is to override the script to use your own class</p>
<ul>
<li>Override epi-cms/widget/overlay/ContentArea.js to use</li>
<li>own epi-cms/widget/overlay/Block where we override to use</li>
<li>own epi-cms/contentediting/command/ContentAreaCommands where we override to use</li>
<li>own epi-cms/contentediting/command/SelectDisplayOption where we override to use</li>
<li>own epi-cms/widget/DisplayOptionSelector</li>
</ul>
<p>here we can do changes to the Display option dialog. Then there is the issue with saving. You need to make your own View Model. If you just want to add a menu (Display as: Automatic) one could hope that one could use the SelectDisplayOption with a different kind of choses, but the DisplayOptionSelector is hardwired to the displayOption set value. This is a bit strange I think. widgets shouldn't be aware of the context they are added in.</p>
<p>The problem with this approach is that we change a lot, and it’s difficult to be sure the changes we do will not break anything.</p>
<p>The best way of doing this should maybe be that in ContentArea.js all the underline classes are define and is sent down to the underline widgets. this could have been done in the EditorDescription and the classes added to metadata.AdditionalValue. Then we could override the classes we want.</p>
<p>Should it be so hard?, or is there something I’m missing?</p>
<p><strong>Do any of you have any pointers in where to add custom values to the content in content areas?</strong></p>
<p>Then I looked at the new LinkCollection, and that it looked promising,.</p>
<p><a href="/link/f2512d3a619840fc9a7c05b457f5bef1.aspx"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="/link/57bf3ff8af4742dca0aec956b7d19846.aspx" height="238" width="538" /></a></p>
<p>But it’s lack the Display as: option</p>
<p>and the edit mode is like this</p>
<p><a href="/link/55ae5a2a7ba044e9af64b36f42e6b77c.aspx"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="/link/ca1679bb23214ea1ba0a7a5a67dab5d7.aspx" height="540" width="557" /></a></p>
<p>here we could have change this dialog to add a dropdown with display as options, and a override intro text field.</p>
<p>The ItemCollectionEditor.js is a bit easier to read, and it also add the buttons, so we don't need to override so much to do stuff.</p>
<p>And it also seems after some heavy reading in js files, and reflector that the items displayed is based on the modeltype we insert in the EditorDescription</p>
<pre class="language-csharp"><code>[EditorDescriptorRegistration(TargetType = typeof(LinkItemCollection),UIHint="Options")]
public class LinkCollectionEditorDescriptor : ItemCollectionEditorDescriptor
{
public LinkCollectionEditorDescriptor(System.Collections.Generic.IEnumerable<IContentRepositoryDescriptor> contentRepositoryDescriptors)
{
base.AllowedTypesFormatSuffix = "link";
base.AllowedTypes = (
from d in contentRepositoryDescriptors
where d.LinkableTypes != null && d.LinkableTypes.Any<System.Type>()
select d).SelectMany((IContentRepositoryDescriptor d) => d.LinkableTypes).Distinct<System.Type>().ToArray<System.Type>();
}
public override void ModifyMetadata(ExtendedMetadata metadata, System.Collections.Generic.IEnumerable<System.Attribute> attributes)
{
base.ClientEditingClass = "alloy/editors/ItemCollectionEditor";
base.ModifyMetadata(metadata, attributes);
var f__AnonymousType = new
{
ItemModelType = "epi-cms/contentediting/viewmodel/LinkItemModel",
CustomTypeIdentifier = typeof(LinkItem).FullName.ToLower()
};
var value = new
{
DialogContentParams = new
{
ModelType = typeof(LinkModel2).FullName.ToLower()
}
};
metadata.OverlayConfiguration["modelParams"] = f__AnonymousType;
metadata.EditorConfiguration["itemModelType"] = f__AnonymousType.ItemModelType;
metadata.EditorConfiguration["customTypeIdentifier"] = f__AnonymousType.CustomTypeIdentifier;
metadata.EditorConfiguration["commandOptions"] = value;
}
}</code></pre>
<p>So when I changed LinkModel to my own LinkModel2 and added a property it got displayed.</p>
<p><a href="/link/632e753d7a404ca686595906fb242b98.aspx"><img title="image" alt="image" src="/link/504b3415150048ceb9feb06254adb489.aspx" height="114" width="244" /></a></p>
<pre class="language-csharp"><code>public class LinkModel2
{
private readonly IContentRepository _contentRepository;
private readonly UIDescriptorRegistry _uiDescriptors;
private string _typeIdentifier;
[Required, DisplayName("/episerver/cms/widget/editlink/linkname")]
public string Text
{
get;
set;
}
[DisplayName("/episerver/cms/widget/editlink/linktitle")]
public string Title
{
get;
set;
}
[DisplayName("/episerver/cms/widget/editlink/linktitle")]
public string Intro
{
get;
set;
}</code></pre>
<p>This is good news. So I will work more on this way of doing thing.</p>
<p><strong>So if you want something similar to a contentarea don’t use contentarea but LinkCollection</strong></p>
Error: Deadlock risk detected…..
/blogs/Anders-Hattestad/Dates/2014/1/Error-Deadlock-risk-detected/
2014-01-13T12:25:11.0000000Z
<p>I got this error “Deadlock risk detected.Trying to read a page from the same thread that is already trying to read the same page”  and want to share with you what was my problem. </p> <p>I can seems that when you first access a page data, and if that page data object make a call to itself (direct or indirect) you will get this error.</p> <p>I got it in my <a href="http://world.episerver.com/Blogs/Anders-Hattestad/Dates/2013/11/File-selector-dojo-property-for-EPiServer-7/">file selector property</a> and I needed to rewrite the Value method. </p> <p>The problem was that if you in the file selector added files from the page folder to the page the</p> <p>System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(“/pagefiles/currentPageID/”) this code will make a new call to get the page and make a deadlock.</p> <p>The trick is to move the code from Value to the SaveData method. So instead of changing the code each time it’s read from the database, only to each time it’s saved.</p> <p>So the new code for instead of the Value method in  the PropertyFiles.cs class is</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0ef264c0-cdb4-4886-a499-8b95b8c40cb4" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">override</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">object</span><span style="background:#ffffff;color:#000000"> SaveData(</span><span style="background:#ffffff;color:#2b91af">PropertyDataCollection</span><span style="background:#ffffff;color:#000000"> properties)</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> str = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.LongString;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (str != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> doc = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">HtmlDocument</span><span style="background:#ffffff;color:#000000">();</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">doc.LoadHtml(str);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> refLinks = </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">foreach</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> item </span><span style="background:#ffffff;color:#0000ff">in</span><span style="background:#ffffff;color:#000000"> doc.DocumentNode.ChildNodes)</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (item.Name == </span><span style="background:#ffffff;color:#a31515">"div"</span><span style="background:#ffffff;color:#000000"> && item.Attributes.Contains(</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">) && item.Attributes[</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">].Value != </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">)</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> href = item.Attributes[</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">].Value;</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> inner = </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">refLinks += </span><span style="background:#ffffff;color:#a31515">"<a href=\""</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"\" class=\"ignore\" style=\"display:none;\">"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"</a>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">item.Attributes.Remove(</span><span style="background:#ffffff;color:#a31515">"style"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (href.EndsWith(</span><span style="background:#ffffff;color:#a31515">"/"</span><span style="background:#ffffff;color:#000000">))</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">item.Attributes.Add(</span><span style="background:#ffffff;color:#a31515">"style"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"border:1px solid black;margin-bottom:5px;"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner = </span><span style="background:#ffffff;color:#a31515">"<div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<input type=checkbox onclick=\"$(this).parent().parent().removeAttr('data-href');$(this).parent().parent().css('display','none');var obj=$(this).closest('.ownerDiv').find('.actionField');obj.val('"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"');obj.click();\" />delete"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> dir = System.Web.Hosting.</span><span style="background:#ffffff;color:#2b91af">HostingEnvironment</span><span style="background:#ffffff;color:#000000">.VirtualPathProvider.GetDirectory(href) </span><span style="background:#ffffff;color:#0000ff">as</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UnifiedDirectory</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (dir != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"All files from folder:<br />"</span><span style="background:#ffffff;color:#000000"> + dir.VirtualPath;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">foreach</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">UnifiedFile</span><span style="background:#ffffff;color:#000000"> fil2 </span><span style="background:#ffffff;color:#0000ff">in</span><span style="background:#ffffff;color:#000000"> dir.Files)</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">BaseMedia</span><span style="background:#ffffff;color:#000000">.IsMedia(fil2.VirtualPath))</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#000000">refLinks += </span><span style="background:#ffffff;color:#a31515">"<a href=\""</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"\" class=\"ignore\" style=\"display:none;\">"</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"</a>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<div style=\"float:left;\">"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<img style=\"width:80px;height:80px;\" src=\"/FileCache"</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"/width_80.height_80.mode_crop.jpg\" data-org=\""</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"\" title=\""</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"\" />"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">else</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">refLinks += </span><span style="background:#ffffff;color:#a31515">"<a href=\""</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"\" class=\"ignore\" style=\"display:none;\">"</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"</a>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<div title=\""</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"\">"</span><span style="background:#ffffff;color:#000000"> + fil2.Name + </span><span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">else</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">item.Attributes.Add(</span><span style="background:#ffffff;color:#a31515">"style"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"border:1px solid black;float:left;margin-right:5px;margin-bottom:5px;"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> filname = </span><span style="background:#ffffff;color:#2b91af">Path</span><span style="background:#ffffff;color:#000000">.GetFileName(href);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> path = href.Substring(0, href.Length - filname.Length);</span></li> <li> <span style="background:#ffffff;color:#000000">inner = </span><span style="background:#ffffff;color:#a31515">"<div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<input type=checkbox onclick=\"$(this).parent().parent().removeAttr('data-href');$(this).parent().parent().css('display','none');var obj=$(this).closest('.ownerDiv').find('.actionField');obj.val('"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"');obj.click();\" />delete"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<input type=checkbox onclick=\"$(this).parent().parent().attr('data-href','"</span><span style="background:#ffffff;color:#000000"> + path + </span><span style="background:#ffffff;color:#a31515">"');var obj=$(this).closest('.ownerDiv').find('.actionField');$(this).parent().html('All files from folder:<br />"</span><span style="background:#ffffff;color:#000000"> + path + </span><span style="background:#ffffff;color:#a31515">"');obj.val('"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"');obj.click();\" />all<br/>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">item.Attributes.Remove(</span><span style="background:#ffffff;color:#a31515">"onclick"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">BaseMedia</span><span style="background:#ffffff;color:#000000">.IsMedia(filname))</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<img style=\"width:80px;height:80px;\" src=\"/FileCache"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"/width_80.height_80.mode_crop.jpg\" data-org=\""</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"\" title=\""</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"\" />"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">else</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<div title=\""</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"\">"</span><span style="background:#ffffff;color:#000000"> + filname + </span><span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">item.InnerHtml = inner + </span><span style="background:#ffffff;color:#a31515">"<div style=\"clear:both;\"></div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> doc.DocumentNode.OuterHtml;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">else</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.Value;</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">}</span></li> </ol> </div> </div> </div>
Google map selector dojo property for EPiServer 7
/blogs/Anders-Hattestad/Dates/2013/11/Google-map-selector-dojo-property-for-EPiServer-7/
2013-11-30T11:13:46.0000000Z
<p>I have with collaboration with a colleague of mine made a Google map selector. It’s plain but effective.</p> <p>The basic concept is like this:</p> <table cellspacing="0" cellpadding="2" width="400" border="0"><tbody> <tr> <td valign="top" width="200"><a href="/link/97968817f15f4c10967f654803908aad.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/1338892e61a74b839a33dc2043193d73.png" width="254" height="85" /></a></td> <td valign="top" width="200">A user can add a query to search for.</td> </tr> <tr> <td valign="top" width="200"><a href="/link/15b046313af941d28f52d7ab9ee3ffad.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/bfd7919a94314281b8f29cc258bef060.png" width="254" height="160" /></a></td> <td valign="top" width="200">After searching the dropdown got populated with possible hits</td> </tr> <tr> <td valign="top" width="200"><a href="/link/6f0e46e8794e4ad3a110978eb253df9b.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/1dd858ab118047498a31241a6d49b1b4.png" width="254" height="288" /></a></td> <td valign="top" width="200">After selecting one we display the result.</td> </tr> <tr> <td valign="top" width="200"><a href="/link/854949b2093d48b39987a70ae1dd83dd.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/548df479fde740f4a80e6c5574008567.png" width="254" height="353" /></a></td> <td valign="top" width="200">After saving an reload of the page we show the ma</td> </tr> </tbody></table> <p>To archive this we have as always tag over definition like this</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9e54a9d3-fe48-4a00-9fa0-a0962479c9ce" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"> <li><span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">ContentType</span><span style="background:#ffffff;color:#000000">(GUID = </span><span style="background:#ffffff;color:#a31515">"64D8C8D0-87E8-4894-B8EA-B4654593741E"</span><span style="background:#ffffff;color:#000000">, AvailableInEditMode = </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">, DisplayName = </span><span style="background:#ffffff;color:#a31515">"Map"</span><span style="background:#ffffff;color:#000000">)]</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">BlockImageUrl</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">"Map.png"</span><span style="background:#ffffff;color:#000000">)]</span></li> <li><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">MapBlock</span><span style="background:#ffffff;color:#000000"> : </span><span style="background:#ffffff;color:#2b91af">BaseBlock</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">UIHint</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">"GoogleMapSelector"</span><span style="background:#ffffff;color:#000000">)]</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">virtual</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000"> Coords { </span><span style="background:#ffffff;color:#0000ff">get</span><span style="background:#ffffff;color:#000000">; </span><span style="background:#ffffff;color:#0000ff">set</span><span style="background:#ffffff;color:#000000">; }</span></li> <li><span style="background:#ffffff;color:#000000">}</span></li> </ol> </div> </div> </div> <p>as you can se we store the value of the search as text, so don’t need a own property. But we need a Descriptor to trigger our JavaScript. And that code look like this </p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6e5ee541-ca11-4e52-9683-08d3d2dcbeda" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">EditorDescriptorRegistration</span><span style="background:#ffffff;color:#000000">(TargetType = </span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000">), UIHint = </span><span style="background:#ffffff;color:#a31515">"GoogleMapSelector"</span><span style="background:#ffffff;color:#000000">)]</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">GoogleMapSelectorDescriptor</span><span style="background:#ffffff;color:#000000"> : </span><span style="background:#ffffff;color:#2b91af">EditorDescriptor</span></li> <li><span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">override</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> ModifyMetadata(Shell.ObjectEditing.</span><span style="background:#ffffff;color:#2b91af">ExtendedMetadata</span><span style="background:#ffffff;color:#000000"> metadata, </span><span style="background:#ffffff;color:#2b91af">IEnumerable</span><span style="background:#ffffff;color:#000000"><</span><span style="background:#ffffff;color:#2b91af">Attribute</span><span style="background:#ffffff;color:#000000">> attributes)</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">ClientEditingClass = </span><span style="background:#ffffff;color:#a31515">"itera.editors.GoogleMapSelector"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#0000ff">base</span><span style="background:#ffffff;color:#000000">.ModifyMetadata(metadata, attributes);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li><span style="background:#ffffff;color:#000000">}</span></li> </ol> </div> </div> </div> <p>In the actually script we have an iframe with the Google map JavaScript added. </p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7aa019f5-2809-44f4-969e-781fce4958b6" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"> <li><span style="background:#ffffff;color:#a31515"><iframe src=\"/modules/GoogleMap.aspx\" data-dojo-attach-point=\"iFrameBody\" data-dojo-attach-event='onload:_drawChart' style=\"width:300px;height:300px;\" ></iframe></span></li> </ol> </div> </div> </div> <p>And on that page have JavaScript functions that we call from the dojo functions. There is also important to notice that one should draw the chart after all other stuff have been done, else we looses focus to the function and </p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0409a27e-82fb-4047-b93a-a2a5b3f53c7a" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">GoogleMapSelector.js</div> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#008000">/*</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#008000">Dojo widget for editing a list of strings. Also see property type PropertyStringList in /Models/Properties.</span></li> <li><span style="background:#ffffff;color:#008000">*/</span></li> <li style="background: #f3f3f3"> </li> <li><span style="background:#ffffff;color:#000000">define([</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dojo/_base/array"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"dojo/_base/connect"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dojo/_base/declare"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"dojo/_base/lang"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#a31515">"dijit/_CssStateMixin"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dijit/_Widget"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"dijit/_TemplatedMixin"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dijit/_WidgetsInTemplateMixin"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dijit/form/Textarea"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"epi/epi"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"epi/shell/widget/_ValueRequiredMixin"</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">],</span></li> <li><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">array,</span></li> <li> <span style="background:#ffffff;color:#000000">connect,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">declare,</span></li> <li> <span style="background:#ffffff;color:#000000">lang,</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">_CssStateMixin,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_Widget,</span></li> <li> <span style="background:#ffffff;color:#000000">_TemplatedMixin,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_WidgetsInTemplateMixin,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">Textarea,</span></li> <li> <span style="background:#ffffff;color:#000000">epi,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_ValueRequiredMixin</span></li> <li><span style="background:#ffffff;color:#000000">) {</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> declare(</span><span style="background:#ffffff;color:#a31515">"itera.editors.GoogleMapSelector"</span><span style="background:#ffffff;color:#000000">, [_Widget, _TemplatedMixin, _WidgetsInTemplateMixin, _CssStateMixin, _ValueRequiredMixin], {</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">templateString: </span><span style="background:#ffffff;color:#a31515">"<div class=\"dijitInline\">"</span><span style="background:#ffffff;color:#000000">+</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">" <div data-dojo-attach-point=\"stateNode, tooltipNode\">"</span><span style="background:#ffffff;color:#000000">+</span></li> <li> <span style="background:#ffffff;color:#a31515">" <input type='text' data-dojo-attach-point=\"searchValue\" />"</span><span style="background:#ffffff;color:#000000"> +</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">" <input type='button' data-dojo-attach-event=\"onclick:_onClick\" value=\"Search\" /><br />"</span><span style="background:#ffffff;color:#000000">+ </span></li> <li> <span style="background:#ffffff;color:#a31515">" <select data-dojo-attach-point='searchResult' data-dojo-attach-event='onchange:_onChange' ><option value=''>skriv inn tekst og trykk Search</option></select><hr />"</span><span style="background:#ffffff;color:#000000"> +</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">" <iframe src=\"/modules/GoogleMap.aspx\" data-dojo-attach-point=\"iFrameBody\" data-dojo-attach-event='onload:_drawChart' style=\"width:300px;height:300px;\" ></iframe><br />"</span><span style="background:#ffffff;color:#000000"> +</span></li> <li> <span style="background:#ffffff;color:#a31515">" <input type='button' data-dojo-attach-event=\"onclick:_clearResult\" value=\"Clear\" />"</span><span style="background:#ffffff;color:#000000"> +</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">" <textarea data-dojo-attach-point=\"text\" data-dojo-attach-event=\"onchange:_onChange\" style=\"width:300px;height:40px;display:block;\" ></textarea>"</span><span style="background:#ffffff;color:#000000"> +</span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#a31515">" </div>"</span><span style="background:#ffffff;color:#000000">+</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">" <br />"</span><span style="background:#ffffff;color:#000000">+</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">baseClass: </span><span style="background:#ffffff;color:#a31515">"epiStringList"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">intermediateChanges: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">value: </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#000000">multiple: </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">onChange: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.text.value = value;</span></li> <li> <span style="background:#ffffff;color:#008000">// Event</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">postCreate: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> () {</span></li> <li> <span style="background:#ffffff;color:#008000">// call base implementation</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.inherited(arguments);</span></li> <li> <span style="background:#ffffff;color:#008000">//this.set('value', this.value);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">// this.savedValue.value = this.value;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Init textarea and bind event</span></li> <li> <span style="background:#ffffff;color:#008000">//this.textArea.set("intermediateChanges", this.intermediateChanges);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">//this.connect(this.textArea, "onChange", this._onTextAreaChanged);</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">isValid: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> () {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_drawChart: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> () {</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.iFrameBody.contentWindow) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value) {</span></li> <li> <span style="background:#ffffff;color:#000000">$(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.iFrameBody).css(</span><span style="background:#ffffff;color:#a31515">"display"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"block"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.iFrameBody.contentWindow.DrawChart(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value, </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.iFrameBody);</span></li> <li> <span style="background:#ffffff;color:#000000">} </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">$(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.iFrameBody).css(</span><span style="background:#ffffff;color:#a31515">"display"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"none"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> <span style="background:#ffffff;color:#000000">_onClick: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (event) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> address = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.searchValue.value;</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> options = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.iFrameBody.contentWindow.DoSearch(address, </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.searchResult);</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> <span style="background:#ffffff;color:#000000">_clearResult: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (event) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._set(</span><span style="background:#ffffff;color:#a31515">'value'</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.onChange(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._drawChart();</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.searchResult.innerHTML = </span><span style="background:#ffffff;color:#a31515">"<option value=''>skriv inn tekst og trykk Search</option>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.searchValue.value = </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_onChange: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (event) {</span></li> <li> <span style="background:#ffffff;color:#008000">// summary:</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Handles the textbox change event and populates this to the onChange method.</span></li> <li> <span style="background:#ffffff;color:#008000">// tags:</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// private</span></li> <li> <span style="background:#ffffff;color:#008000">//alert("yo");</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._set(</span><span style="background:#ffffff;color:#a31515">'value'</span><span style="background:#ffffff;color:#000000">, event.target.value);</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.onChange(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._drawChart();</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Setter for value property</span></li> <li> <span style="background:#ffffff;color:#000000">_setValueAttr: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._setValue(value, </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">//_setReadOnlyAttr: function (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// this._set("readOnly", value);</span></li> <li> <span style="background:#ffffff;color:#008000">// this.savedValue.set("readOnly", value);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">//},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Setter for intermediateChanges</span></li> <li> <span style="background:#ffffff;color:#000000">_setIntermediateChangesAttr: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">//this.textArea.set("intermediateChanges", value);</span></li> <li> <span style="background:#ffffff;color:#008000">//this._set("intermediateChanges", value);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Event handler for textarea</span></li> <li> <span style="background:#ffffff;color:#000000">_onTextAreaChanged: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._setValue(value, </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">_setValue: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value, updateTextarea) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Assume value is an array</span></li> <li> <span style="background:#ffffff;color:#008000">// this.savedValue.set("value", value);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Assume value is an array</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> list = value;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000"> value === </span><span style="background:#ffffff;color:#a31515">"string"</span><span style="background:#ffffff;color:#000000">) {</span></li> <li> <span style="background:#ffffff;color:#008000">// Split list</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">list = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._stringToList(value);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">} </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (!value) {</span></li> <li> <span style="background:#ffffff;color:#008000">// use empty array for empty value</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">list = [];</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (list.length == 1 && list[0] == </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">)</span></li> <li> <span style="background:#ffffff;color:#000000">list = [];</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> txt = list.join(</span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._set(</span><span style="background:#ffffff;color:#a31515">"value"</span><span style="background:#ffffff;color:#000000">, txt);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (updateTextarea && list.length>0) {</span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.text.value = txt;</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">// this.text.set("value", list.join("\n"));</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> elements = txt.split(</span><span style="background:#ffffff;color:#a31515">'$'</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.searchResult.innerHTML = </span><span style="background:#ffffff;color:#a31515">"<option value=\""</span><span style="background:#ffffff;color:#000000"> + txt + </span><span style="background:#ffffff;color:#a31515">"\">"</span><span style="background:#ffffff;color:#000000"> + elements[1] + </span><span style="background:#ffffff;color:#a31515">"</option>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._drawChart(txt);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">});</span></li> <li><span style="background:#ffffff;color:#000000">});</span></li> </ol> </div> </div> </div> <p>The /Modules/GoogleMap.aspx looks like this</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b463d572-1720-4aa4-b28c-caa378632779" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">GoogleMap.aspx</div> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#0000ff"><!</span><span style="background:#ffffff;color:#800000">DOCTYPE</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">html</span><span style="background:#ffffff;color:#0000ff">></span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">html</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">xmlns</span><span style="background:#ffffff;color:#0000ff">="http://www.w3.org/1999/xhtml"></span></li> <li><span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">head</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">runat</span><span style="background:#ffffff;color:#0000ff">="server"></span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">script</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">src</span><span style="background:#ffffff;color:#0000ff">="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></</span><span style="background:#ffffff;color:#800000">script</span><span style="background:#ffffff;color:#0000ff">></span></li> <li> <span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">style</span><span style="background:#ffffff;color:#0000ff">></span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#800000">html</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#800000">body</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#800000">#map-canvas</span><span style="background:#ffffff;color:#000000"> { </span><span style="background:#ffffff;color:#ff0000">height</span><span style="background:#ffffff;color:#000000">: </span><span style="background:#ffffff;color:#0000ff">300px</span><span style="background:#ffffff;color:#000000">; </span><span style="background:#ffffff;color:#ff0000">margin</span><span style="background:#ffffff;color:#000000">: </span><span style="background:#ffffff;color:#0000ff">0px</span><span style="background:#ffffff;color:#000000">; </span><span style="background:#ffffff;color:#ff0000">padding</span><span style="background:#ffffff;color:#000000">: </span><span style="background:#ffffff;color:#0000ff">0px</span><span style="background:#ffffff;color:#000000">; </span><span style="background:#ffffff;color:#ff0000">width</span><span style="background:#ffffff;color:#000000">: </span><span style="background:#ffffff;color:#0000ff">300px</span><span style="background:#ffffff;color:#000000">; }</span></li> <li> <span style="background:#ffffff;color:#0000ff"></</span><span style="background:#ffffff;color:#800000">style</span><span style="background:#ffffff;color:#0000ff">></span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">script</span><span style="background:#ffffff;color:#0000ff">></span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> map;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> currentMarker;</span></li> <li> <span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> DoSearch(query, obj) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">geocoder.geocode({ </span><span style="background:#ffffff;color:#a31515">'address'</span><span style="background:#ffffff;color:#000000">: query }, </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (results, status) {</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> html = </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">html += </span><span style="background:#ffffff;color:#a31515">"<option value=''>Resultater for "</span><span style="background:#ffffff;color:#000000"> + query + </span><span style="background:#ffffff;color:#a31515">"</option>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (status == google.maps.GeocoderStatus.OK) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">for</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> i = 0; i < results.length; i++) {</span></li> <li> <span style="background:#ffffff;color:#000000">html += </span><span style="background:#ffffff;color:#a31515">"<option value=\""</span><span style="background:#ffffff;color:#000000"> + results[i].geometry.location + </span><span style="background:#ffffff;color:#a31515">"$"</span><span style="background:#ffffff;color:#000000"> + results[i].formatted_address + </span><span style="background:#ffffff;color:#a31515">"\">"</span><span style="background:#ffffff;color:#000000"> + results[i].formatted_address + </span><span style="background:#ffffff;color:#a31515">"</option>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">obj.innerHTML = html;</span></li> <li> <span style="background:#ffffff;color:#000000">});</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> DrawChart(data, obj) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> elements = data.toString().split(</span><span style="background:#ffffff;color:#a31515">'$'</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> matches = elements[0].toString().substr(1, elements[0].length - 2);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> location = matches.toString().split(</span><span style="background:#ffffff;color:#a31515">','</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> myLatlng = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> google.maps.LatLng(parseFloat(location[0]), parseFloat(location[1]));</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> mapOptions = {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">draggable: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#000000">zoomControl: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">scrollwheel: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#000000">disableDoubleClickZoom: </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">mapTypeControl: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#000000">zoom: 15,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">center: myLatlng,</span></li> <li> <span style="background:#ffffff;color:#000000">mapTypeId: google.maps.MapTypeId.ROADMAP</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">map = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> google.maps.Map(document.getElementById(</span><span style="background:#ffffff;color:#a31515">"map-canvas"</span><span style="background:#ffffff;color:#000000">), mapOptions);</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">// To add the marker to the map, use the 'map' property</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">currentMarker = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> google.maps.Marker({</span></li> <li> <span style="background:#ffffff;color:#000000">position: myLatlng,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">map: map,</span></li> <li> <span style="background:#ffffff;color:#000000">title: elements[1]</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">});</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> initialize() {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">geocoder = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> google.maps.Geocoder();</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff"></</span><span style="background:#ffffff;color:#800000">script</span><span style="background:#ffffff;color:#0000ff">></span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li><span style="background:#ffffff;color:#0000ff"></</span><span style="background:#ffffff;color:#800000">head</span><span style="background:#ffffff;color:#0000ff">></span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">body</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">onload</span><span style="background:#ffffff;color:#0000ff">="initialize()"></span></li> <li> <span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">form</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">id</span><span style="background:#ffffff;color:#0000ff">="form1"</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">runat</span><span style="background:#ffffff;color:#0000ff">="server"></span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">div</span><span style="background:#ffffff;color:#0000ff">></span></li> <li> <span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">div</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">id</span><span style="background:#ffffff;color:#0000ff">="map-canvas"></</span><span style="background:#ffffff;color:#800000">div</span><span style="background:#ffffff;color:#0000ff">></span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff"></</span><span style="background:#ffffff;color:#800000">div</span><span style="background:#ffffff;color:#0000ff">></span></li> <li> <span style="background:#ffffff;color:#0000ff"></</span><span style="background:#ffffff;color:#800000">form</span><span style="background:#ffffff;color:#0000ff">></span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff"></</span><span style="background:#ffffff;color:#800000">body</span><span style="background:#ffffff;color:#0000ff">></span></li> <li><span style="background:#ffffff;color:#0000ff"></</span><span style="background:#ffffff;color:#800000">html</span><span style="background:#ffffff;color:#0000ff">></span></li> </ol> </div> </div> </div> <p>So after all this is done, we have a block with a Google map selector. Then the last piece is to show the value.</p> <p>There there are a  little trick. To ensure that the map is shown the JavaScript <a title="http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" href="http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false</a> needs to be loaded. But you don't want to load that JavaScript on all page requests.</p> <p>We therefore engineered a construct that we added to the footer of the page</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1ae04c81-93ec-4e96-ab53-edf488e6347e" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"> <li><span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">script</span><span style="background:#ffffff;color:#0000ff">></span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> AddIfGoogleMap(src) {</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> ($(document.body).find(</span><span style="background:#ffffff;color:#a31515">'div.googleMap'</span><span style="background:#ffffff;color:#000000">).length>0)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">document.write(</span><span style="background:#ffffff;color:#a31515">'<'</span><span style="background:#ffffff;color:#000000"> + </span><span style="background:#ffffff;color:#a31515">'script src="'</span><span style="background:#ffffff;color:#000000"> + src + </span><span style="background:#ffffff;color:#a31515">'"'</span><span style="background:#ffffff;color:#000000"> +</span></li> <li> <span style="background:#ffffff;color:#a31515">' type="text/javascript"><'</span><span style="background:#ffffff;color:#000000"> + </span><span style="background:#ffffff;color:#a31515">'/script>'</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">AddIfGoogleMap(</span><span style="background:#ffffff;color:#a31515">"http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff"></</span><span style="background:#ffffff;color:#800000">script</span><span style="background:#ffffff;color:#0000ff">></span></li> </ol> </div> </div> </div> <p>This finds if there is a div with class Google Map the JavaScript will be loaded</p> <p>Then we after this script add this script</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c2411746-e27a-4f93-a384-11a5045cc036" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> GetScale(scale, width, height) {</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (scale > 0) {</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (width)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> Math.ceil(width / scale);</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (height)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> Math.ceil(height * scale);</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> 0;</span></li> <li> </li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">}</span></li> <li><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> GetScaleInner(obj, key) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> h = obj.attr(</span><span style="background:#ffffff;color:#a31515">"data-image-"</span><span style="background:#ffffff;color:#000000"> + key + </span><span style="background:#ffffff;color:#a31515">"-height"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> w = obj.attr(</span><span style="background:#ffffff;color:#a31515">"data-image-"</span><span style="background:#ffffff;color:#000000"> + key + </span><span style="background:#ffffff;color:#a31515">"-width"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (h != </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000"> && w != </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> w / h;</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> 0;</span></li> <li><span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> ResizeGoogleMap100Procent(obj) {</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> scale = GetScaleInner(obj, </span><span style="background:#ffffff;color:#a31515">"scale"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">obj.css(</span><span style="background:#ffffff;color:#a31515">"width"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"100%"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#000000">obj.css(</span><span style="background:#ffffff;color:#a31515">"height"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> width = obj.width();</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> height = GetScale(scale, width);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">obj.css(</span><span style="background:#ffffff;color:#a31515">"height"</span><span style="background:#ffffff;color:#000000">, height);</span></li> <li> <span style="background:#ffffff;color:#000000">obj.css(</span><span style="background:#ffffff;color:#a31515">"width"</span><span style="background:#ffffff;color:#000000">, width);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> data = obj.attr(</span><span style="background:#ffffff;color:#a31515">"data-google-map-cords"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> elements = data.toString().split(</span><span style="background:#ffffff;color:#a31515">'$'</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> matches = elements[0].toString().substr(1, elements[0].length - 2);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> location = matches.toString().split(</span><span style="background:#ffffff;color:#a31515">','</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> myLatlng = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> google.maps.LatLng(parseFloat(location[0]), parseFloat(location[1]));</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> mapOptions = {</span></li> <li> <span style="background:#ffffff;color:#000000">draggable: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">zoomControl: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#000000">scrollwheel: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">disableDoubleClickZoom: </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#000000">mapTypeControl:</span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">zoom: 15,</span></li> <li> <span style="background:#ffffff;color:#000000">center: myLatlng,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">mapTypeId: google.maps.MapTypeId.ROADMAP</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">map = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> google.maps.Map(obj[0], mapOptions);</span></li> <li> <span style="background:#ffffff;color:#008000">// To add the marker to the map, use the 'map' property</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">currentMarker = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> google.maps.Marker({</span></li> <li> <span style="background:#ffffff;color:#000000">position: myLatlng,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">map: map,</span></li> <li> <span style="background:#ffffff;color:#000000">title: elements[1]</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">});</span></li> <li><span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">$(document).ready(</span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> () {</span></li> <li> <span style="background:#ffffff;color:#000000">$(document.body).find(</span><span style="background:#ffffff;color:#a31515">'div.googleMap'</span><span style="background:#ffffff;color:#000000">).each(</span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (i) {</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">ResizeGoogleMap100Procent($(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">));</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">});</span></li> <li><span style="background:#ffffff;color:#000000">});</span></li> </ol> </div> </div> </div> <p>With this in place we can add this html code anywhere</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4ca4a3b2-2683-4d31-bff6-7c9246d4f91c" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#0000ff"><</span><span style="background:#ffffff;color:#800000">div</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">class</span><span style="background:#ffffff;color:#0000ff">="googleMap"</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">data-image-scale-width</span><span style="background:#ffffff;color:#0000ff">="16"</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">data-image-scale-height</span><span style="background:#ffffff;color:#0000ff">="9"</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">data-epi-use-mvc</span><span style="background:#ffffff;color:#0000ff">='True'</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">data-google-map-cords</span><span style="background:#ffffff;color:#0000ff">="</span><span style="background:#ffff00;color:#000000">@</span><span style="background:#ffffff;color:#000000">Model.Coords</span><span style="background:#ffffff;color:#0000ff">"</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">data-epi-property-name</span><span style="background:#ffffff;color:#0000ff">='Coords'></</span><span style="background:#ffffff;color:#800000">div</span><span style="background:#ffffff;color:#0000ff">></span></li> </ol> </div> </div> </div> <p>And it will show a map with 100% width and 16/9 scale</p>
File selector dojo property for EPiServer 7
/blogs/Anders-Hattestad/Dates/2013/11/File-selector-dojo-property-for-EPiServer-7/
2013-11-26T09:17:54.0000000Z
<p>Have made myself a dojo property for selection images. Noting fancy, but I though I should share some of my findings when creating a dojo property. There is some examples out there, but another one can’t hurt.</p> <p>The basic concept here is that you can drag a file into an area. And I display a thumbnail of the file.</p> <table cellspacing="0" cellpadding="2" width="400" border="0"><tbody> <tr> <td valign="top" width="200"><a href="/link/b293a37c2e2b4bfdaf7b1023d73e83d6.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="/link/9f07edd74d2e4de9b78446e824c28a49.png" width="244" height="54" /></a></td> <td valign="top" width="200">Drag the file into the area</td> </tr> <tr> <td valign="top" width="200"><a href="/link/4674b9de2c124d9a98adc2a1c96805cc.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="/link/ec8637798fed44818d6616250d1a9559.png" width="244" height="140" /></a></td> <td valign="top" width="200">Show a thumbnail</td> </tr> <tr> <td valign="top" width="200"><a href="/link/677c7697a8a2458d8e9008b5139e1e15.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="/link/04b26075b9d14a199a51e80d9e11e5ef.png" width="244" height="114" /></a></td> <td valign="top" width="200">After saving, show delete and all files from folder</td> </tr> <tr> <td valign="top" width="200"><a href="/link/4788cea363ad41afb51aea0ecc352ade.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="/link/8bde3f8d40394e1e9a78dbca2223bdd5.png" width="156" height="51" /></a></td> <td valign="top" width="200">Select all files from folder</td> </tr> <tr> <td valign="top" width="200"><a href="/link/c891487a3f0742b6b8e5b548c27497fb.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="/link/45b0a2ab2637496a90fe2048a9e9e2eb.png" width="244" height="125" /></a></td> <td valign="top" width="200">after saving so a list of all the files. The property contains a href to all current files in that folder so IReference is set</td> </tr> </tbody></table> <p>Since I wanted to select more than one file, I created a normal property and tagged my property with that and a UIHint</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:86b6df86-f4be-460e-9515-8aeba9bffbe8" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">BackingType</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">PropertyFiles</span><span style="background:#ffffff;color:#000000">))]</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">CultureSpecific</span><span style="background:#ffffff;color:#000000">]</span></li> <li><span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">Display</span><span style="background:#ffffff;color:#000000">(Order = 1)]</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">UIHint</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">"Files"</span><span style="background:#ffffff;color:#000000">)]</span></li> <li><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">virtual</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000"> FileList { </span><span style="background:#ffffff;color:#0000ff">get</span><span style="background:#ffffff;color:#000000">; </span><span style="background:#ffffff;color:#0000ff">set</span><span style="background:#ffffff;color:#000000">; }</span></li> </ol> </div> </div> </div> <p>Then I created a EditorDescriptor, where I points to my JavaScript file</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:31bf8a67-5c53-419e-baa5-b90d3b531809" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System;</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System.Collections.Generic;</span></li> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> EPiServer.Shell.ObjectEditing.EditorDescriptors;</span></li> <li style="background: #f3f3f3"> </li> <li><span style="background:#ffffff;color:#0000ff">namespace</span><span style="background:#ffffff;color:#000000"> EPiServer.Templates.Alloy.Business.EditorDescriptors</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">EditorDescriptorRegistration</span><span style="background:#ffffff;color:#000000">(TargetType = </span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000">), UIHint = </span><span style="background:#ffffff;color:#a31515">"Files"</span><span style="background:#ffffff;color:#000000">)]</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">FilesEditorDescriptor</span><span style="background:#ffffff;color:#000000"> : </span><span style="background:#ffffff;color:#2b91af">EditorDescriptor</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">override</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> ModifyMetadata(Shell.ObjectEditing.</span><span style="background:#ffffff;color:#2b91af">ExtendedMetadata</span><span style="background:#ffffff;color:#000000"> metadata, </span><span style="background:#ffffff;color:#2b91af">IEnumerable</span><span style="background:#ffffff;color:#000000"><</span><span style="background:#ffffff;color:#2b91af">Attribute</span><span style="background:#ffffff;color:#000000">> attributes)</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">ClientEditingClass = </span><span style="background:#ffffff;color:#a31515">"itera.editors.FilesList"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">base</span><span style="background:#ffffff;color:#000000">.ModifyMetadata(metadata, attributes);</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li><span style="background:#ffffff;color:#000000">}</span></li> </ol> </div> </div> </div> <p>When I created the JavaScript file, I got some strange findings. Some examples out there do stuff in postCreate with the value, but as far as I can tell if there are more than one property being edited the value in postCreate is null. </p> <p>So one should do stuff in the <strong>_setValue: function (value, updateTextarea) {…}</strong> it can seems. On an other property I use we update an iframe. If you do that you must do that last in the _setValue function, since we lose focus to the function, and never returns.</p> <p>I added the Source and Target classes to handle drag and drop. But I got problem when having more than one target to drag items into. maybe a bug, or maybe some JavaScript code error on my part. (Guess my part <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smilefjes" src="/link/19af9292c56a491e9797dbbc6a0ddeae.png" /> )</p> <p>I also didn’t manage to drag folders into the area. Have you got that to work? please let me know.</p> <p>The code displays the current value of the property inside the targetDisplay, and if I add a new item I create a new div that I adds to the display. the div contains a data-href attribute with the selected file. I also have a text area with the same html code. That is maybe redundant. One should probably only use the html value of the targetDisplay as the master for the value. This property is used for files, so I display a small image. I have a File system in place /FileCache/ that resize the images based on the added filename (here height_70.height_70.mode_crop.jpg) So you need to change that to your resizing method.</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:aeb82a78-9396-4bfa-93e2-5e4327faaf55" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#000000">define([</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dojo/_base/array"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"dojo/_base/connect"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dojo/_base/declare"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"dojo/_base/lang"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#a31515">"dijit/_CssStateMixin"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dijit/_Widget"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"dijit/_TemplatedMixin"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dijit/_WidgetsInTemplateMixin"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"dijit/form/Textarea"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"epi/epi"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"epi/shell/widget/_ValueRequiredMixin"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#a31515">"epi/shell/dnd/Source"</span><span style="background:#ffffff;color:#000000">,</span></li> <li> <span style="background:#ffffff;color:#a31515">"epi/shell/dnd/Target"</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">],</span></li> <li><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">array,</span></li> <li> <span style="background:#ffffff;color:#000000">connect,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">declare,</span></li> <li> <span style="background:#ffffff;color:#000000">lang,</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">_CssStateMixin,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_Widget,</span></li> <li> <span style="background:#ffffff;color:#000000">_TemplatedMixin,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_WidgetsInTemplateMixin,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">Textarea,</span></li> <li> <span style="background:#ffffff;color:#000000">epi,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_ValueRequiredMixin,</span></li> <li> <span style="background:#ffffff;color:#000000">Source,</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">Target</span></li> <li><span style="background:#ffffff;color:#000000">) {</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> declare(</span><span style="background:#ffffff;color:#a31515">"itera.editors.FileList"</span><span style="background:#ffffff;color:#000000">, [_Widget, _TemplatedMixin, _WidgetsInTemplateMixin, _CssStateMixin, _ValueRequiredMixin], {</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">templateString: </span><span style="background:#ffffff;color:#a31515">"<div class=\"dijitInline ownerDiv\">\\par <div class=\"epi-content-area-editor\" >\\par <div dojoAttachPoint=\"target\" class=\"epi-content-area-actionscontainer files\">Drag files</div>\\par <div style=\"clear:both;\"></div>\\par <div dojoAttachPoint=\"targetDisplay\" ></div>\\par <div style=\"clear:both;\"></div>\\par </div>\\par <div style=\"clear:both;\"></div>\\par <input type=text value=\"\" class='actionField' style=\"display:none;\" data-dojo-attach-point=\"actions\" data-dojo-attach-event=\"click:_onAction\"/>\\par <div data-dojo-attach-point=\"stateNode, tooltipNode\">\\par <div data-dojo-attach-point=\"textArea\" data-dojo-type=\"dijit.form.Textarea\" style=\"width:200px;display:none;\"></div>\\par </div>\\par <br />\\par </div>"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">baseClass: </span><span style="background:#ffffff;color:#a31515">"epiStringList"</span><span style="background:#ffffff;color:#000000">,</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">intermediateChanges: </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">value: </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">multiple: </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">,</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">onChange: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li> <span style="background:#ffffff;color:#008000">// Event</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">postCreate: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> () {</span></li> <li> <span style="background:#ffffff;color:#008000">// call base implementation</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.inherited(arguments);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Init textarea and bind event</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.textArea.set(</span><span style="background:#ffffff;color:#a31515">"intermediateChanges"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.intermediateChanges);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.connect(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.textArea, </span><span style="background:#ffffff;color:#a31515">"onChange"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._onTextAreaChanged);</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._setupTarget();</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> <span style="background:#ffffff;color:#000000">_onAction: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> () {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">console.log(</span><span style="background:#ffffff;color:#a31515">"_onAction= "</span><span style="background:#ffffff;color:#000000"> + </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.targetDisplay.innerHTML);</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.textArea.value = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.targetDisplay.innerHTML;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._setValue(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.targetDisplay.innerHTML, </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_setupTarget: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> () {</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> target = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> Target(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.target, {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">accept: [</span><span style="background:#ffffff;color:#a31515">"fileurl"</span><span style="background:#ffffff;color:#000000">],</span></li> <li> <span style="background:#ffffff;color:#008000">//Set createItemOnDrop if you're only interested to receive the data, and not create a new node.</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">createItemOnDrop: </span><span style="background:#ffffff;color:#0000ff">true</span></li> <li> <span style="background:#ffffff;color:#000000">});</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.connect(target, </span><span style="background:#ffffff;color:#a31515">"onDropData"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"_onDropDataFile"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">//var targetFolders = new Target(this.targetFolders, {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// accept: ["link", "fileurl", "FM-FileLink"],</span></li> <li> <span style="background:#ffffff;color:#008000">// //Set createItemOnDrop if you're only interested to receive the data, and not create a new node.</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// createItemOnDrop: true</span></li> <li> <span style="background:#ffffff;color:#008000">//});</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">//this.connect(targetFolders, "onDropData", "_onDropDataFolder");</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_drawItems:</span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000">(list) {</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.targetDisplay.innerHTML = list;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_onDropData: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (path, source) {</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> value = path;</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (isFolder)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">value = path.substr(0, path.lastIndexOf(</span><span style="background:#ffffff;color:#a31515">"/"</span><span style="background:#ffffff;color:#000000">)+1);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> isFolder = </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (source == </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.targetFolders)</span></li> <li> <span style="background:#ffffff;color:#000000">isFolder = </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (source.parent == </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.targetFolders)</span></li> <li> <span style="background:#ffffff;color:#000000">isFolder = </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">console.log(path + </span><span style="background:#ffffff;color:#a31515">"="</span><span style="background:#ffffff;color:#000000"> + value + </span><span style="background:#ffffff;color:#a31515">" "</span><span style="background:#ffffff;color:#000000"> + source+</span><span style="background:#ffffff;color:#a31515">" "</span><span style="background:#ffffff;color:#000000">+isFolder);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> list = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value;</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value === </span><span style="background:#ffffff;color:#a31515">"string"</span><span style="background:#ffffff;color:#000000">) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Split list</span></li> <li> <span style="background:#ffffff;color:#000000">list = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._stringToList(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">} </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (!</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// use empty array for empty value</span></li> <li> <span style="background:#ffffff;color:#000000">list = [];</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> txt = list.join(</span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> stringCheck = </span><span style="background:#ffffff;color:#a31515">"/"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (txt.indexOf(</span><span style="background:#ffffff;color:#a31515">'data-href="'</span><span style="background:#ffffff;color:#000000"> + value + </span><span style="background:#ffffff;color:#a31515">'"'</span><span style="background:#ffffff;color:#000000">) == -1) {</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> foundIt = (value.lastIndexOf(stringCheck) === value.length - stringCheck.length) > 0;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (foundIt)</span></li> <li> <span style="background:#ffffff;color:#000000">txt += </span><span style="background:#ffffff;color:#a31515">'<div style="float:left;border:1px solid black;padding-right:5px;" data-href="'</span><span style="background:#ffffff;color:#000000"> + value + </span><span style="background:#ffffff;color:#a31515">'">All files from folder:<br />'</span><span style="background:#ffffff;color:#000000"> + value + </span><span style="background:#ffffff;color:#a31515">'</div>'</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">else</span></li> <li> <span style="background:#ffffff;color:#000000">txt += </span><span style="background:#ffffff;color:#a31515">'<div style="float:left;border:1px solid black;padding-right:5px;" data-href="'</span><span style="background:#ffffff;color:#000000"> + value + </span><span style="background:#ffffff;color:#a31515">'"><img src="/FileCache'</span><span style="background:#ffffff;color:#000000"> + value + </span><span style="background:#ffffff;color:#a31515">'/height_70.height_70.mode_crop.jpg" style="width:70px;height:70px;" title="'</span><span style="background:#ffffff;color:#000000"> + value + </span><span style="background:#ffffff;color:#a31515">'" /></div>'</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._setValue(txt, </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_onDropDataFolder: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (dndData, source, nodes, copy) {</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">//Drop item is an array with dragged items. This example just handles the first item.</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> dropItem = dndData ? (dndData.length ? dndData[0] : dndData) : </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">console.log(dropItem + </span><span style="background:#ffffff;color:#a31515">" "</span><span style="background:#ffffff;color:#000000"> + dndData);</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (dropItem) {</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">//The data property might be a deffered so we need to call dojo.when just in case.</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">dojo.when(dropItem.data, dojo.hitch(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li> <span style="background:#ffffff;color:#008000">//Do something with the data, here we just log it to the console.</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._onDropData(value, source);</span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}));</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> <span style="background:#ffffff;color:#000000">_onDropDataFile: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (dndData, source, nodes, copy) {</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">//Drop item is an array with dragged items. This example just handles the first item.</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> dropItem = dndData ? (dndData.length ? dndData[0] : dndData) : </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">console.log(dropItem + </span><span style="background:#ffffff;color:#a31515">" "</span><span style="background:#ffffff;color:#000000"> + dndData);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (dropItem) {</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">//The data property might be a deffered so we need to call dojo.when just in case.</span></li> <li> <span style="background:#ffffff;color:#000000">dojo.when(dropItem.data, dojo.hitch(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">//Do something with the data, here we just log it to the console.</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._onDropData(value, source);</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}));</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">isValid: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> () {</span></li> <li> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Setter for value property</span></li> <li> <span style="background:#ffffff;color:#000000">_setValueAttr: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._setValue(value, </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">_setReadOnlyAttr: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._set(</span><span style="background:#ffffff;color:#a31515">"readOnly"</span><span style="background:#ffffff;color:#000000">, value);</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.textArea.set(</span><span style="background:#ffffff;color:#a31515">"readOnly"</span><span style="background:#ffffff;color:#000000">, value);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Setter for intermediateChanges</span></li> <li> <span style="background:#ffffff;color:#000000">_setIntermediateChangesAttr: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.textArea.set(</span><span style="background:#ffffff;color:#a31515">"intermediateChanges"</span><span style="background:#ffffff;color:#000000">, value);</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._set(</span><span style="background:#ffffff;color:#a31515">"intermediateChanges"</span><span style="background:#ffffff;color:#000000">, value);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">},</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Event handler for textarea</span></li> <li> <span style="background:#ffffff;color:#000000">_onTextAreaChanged: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._setValue(value, </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">_setValue: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value, updateTextarea) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Assume value is an array</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> list = value;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000"> value === </span><span style="background:#ffffff;color:#a31515">"string"</span><span style="background:#ffffff;color:#000000">) {</span></li> <li> <span style="background:#ffffff;color:#008000">// Split list</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">list = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._stringToList(value);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">} </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (!value) {</span></li> <li> <span style="background:#ffffff;color:#008000">// use empty array for empty value</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">list = [];</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._started && epi.areEqual(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.value, list)) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> txt = list.join(</span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (txt == </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._set(</span><span style="background:#ffffff;color:#a31515">"value"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">else</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._set(</span><span style="background:#ffffff;color:#a31515">"value"</span><span style="background:#ffffff;color:#000000">, txt);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">updateTextarea && </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.textArea.set(</span><span style="background:#ffffff;color:#a31515">"value"</span><span style="background:#ffffff;color:#000000">, txt);</span></li> <li> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._drawItems(txt);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">._started && </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.validate()) {</span></li> <li> <span style="background:#ffffff;color:#008000">// Trigger change event</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.onChange(list);</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">},</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">// Convert a string to a list</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">_stringToList: </span><span style="background:#ffffff;color:#0000ff">function</span><span style="background:#ffffff;color:#000000"> (value) {</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Return empty array for </span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (!value || </span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000"> value !== </span><span style="background:#ffffff;color:#a31515">"string"</span><span style="background:#ffffff;color:#000000">) {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> [];</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">// Trim whitespace at start and end</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> trimmed = value.replace(</span><span style="background:#ffffff;color:#800000">/^\s+|\s+$/g</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#008000">// Trim whitespace around each linebreak</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> trimmedLines = trimmed.replace(</span><span style="background:#ffffff;color:#800000">/(\s*\n+\s*)/g</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"\n"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#008000">// Split into list</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> list = trimmedLines.split(</span><span style="background:#ffffff;color:#a31515">"\n"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> list;</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">});</span></li> <li><span style="background:#ffffff;color:#000000">});</span></li> </ol> </div> </div> </div> <p>After the property is saved  have changed the Value in my PropertyFiles property. I find all the div.'s with the data-href attribute and creates a new html value with the div and some checkboxes to delete or select all files in that folder. I also add <a href to the files in the end of the html so the IReference will be set, and editors will get warning if they try to delete a file in use by this property.</p> <p>To communicate to the dojo property I use this line of JavaScript </p> <p>var obj=$(this).closest('.ownerDiv').find('.actionField')</p> <p>this line will get a hold of the textbox in the dojo property</p> <p><input type=text value=\"\" class='actionField'  data-dojo-attach-point=\"actions\" data-dojo-attach-event=\"click:_onAction\" style=\"display:none;\"/>\</p> <p>If i then do obj.click() the _onAction will be triggered. I don't use the value of the textbox here, since i only hide the div, and remove the data-href attribute, but the pattern is nice for using that value for something <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smilefjes" src="/link/19af9292c56a491e9797dbbc6a0ddeae.png" /></p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ef2d663c-7eb5-4dc8-b2b9-b61fdf0851d9" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #fff; max-height: 300px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System;</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System.Collections.Generic;</span></li> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System.Linq;</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System.Web;</span></li> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> EPiServer.Core;</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> EPiServer.Web.PropertyControls;</span></li> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System.Web.UI.WebControls;</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> EPiServer.PlugIn;</span></li> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> EPiServer.Web.Hosting;</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> HtmlAgilityPack;</span></li> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System.IO;</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> EPiServer;</span></li> <li><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> System.Web.Hosting;</span></li> <li style="background: #f3f3f3"> </li> <li><span style="background:#ffffff;color:#0000ff">namespace</span><span style="background:#ffffff;color:#000000"> Itera.Models.Properties</span></li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#000000">[</span><span style="background:#ffffff;color:#2b91af">PropertyDefinitionTypePlugIn</span><span style="background:#ffffff;color:#000000">]</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">[System.</span><span style="background:#ffffff;color:#2b91af">Serializable</span><span style="background:#ffffff;color:#000000">]</span></li> <li> <span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">PropertyFiles</span><span style="background:#ffffff;color:#000000"> : </span><span style="background:#ffffff;color:#2b91af">PropertyLongString</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">override</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">object</span><span style="background:#ffffff;color:#000000"> Value</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">get</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">base</span><span style="background:#ffffff;color:#000000">.Value;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#0000ff">set</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> str = </span><span style="background:#ffffff;color:#0000ff">value</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">as</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (str != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> doc = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">HtmlDocument</span><span style="background:#ffffff;color:#000000">();</span></li> <li> <span style="background:#ffffff;color:#000000">doc.LoadHtml(str);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> refLinks = </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#0000ff">foreach</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> item </span><span style="background:#ffffff;color:#0000ff">in</span><span style="background:#ffffff;color:#000000"> doc.DocumentNode.ChildNodes)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (item.Name == </span><span style="background:#ffffff;color:#a31515">"div"</span><span style="background:#ffffff;color:#000000"> && item.Attributes.Contains(</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">) && item.Attributes[</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">].Value!=</span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> href = item.Attributes[</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">].Value;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> inner = </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">refLinks += </span><span style="background:#ffffff;color:#a31515">"<a href=\""</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"\" class=\"ignore\" style=\"display:none;\">"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"</a>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">item.Attributes.Remove(</span><span style="background:#ffffff;color:#a31515">"style"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (href.EndsWith(</span><span style="background:#ffffff;color:#a31515">"/"</span><span style="background:#ffffff;color:#000000">))</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#000000">item.Attributes.Add(</span><span style="background:#ffffff;color:#a31515">"style"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"border:1px solid black;margin-bottom:5px;"</span><span style="background:#ffffff;color:#000000">);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">inner = </span><span style="background:#ffffff;color:#a31515">"<div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<input type=checkbox onclick=\"$(this).parent().parent().removeAttr('data-href');$(this).parent().parent().css('display','none');var obj=$(this).closest('.ownerDiv').find('.actionField');obj.val('"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"');obj.click();\" />delete"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> dir = System.Web.Hosting.</span><span style="background:#ffffff;color:#2b91af">HostingEnvironment</span><span style="background:#ffffff;color:#000000">.VirtualPathProvider.GetDirectory(href) </span><span style="background:#ffffff;color:#0000ff">as</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UnifiedDirectory</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (dir != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"All files from folder:<br />"</span><span style="background:#ffffff;color:#000000"> + dir.VirtualPath;</span></li> <li> <span style="background:#ffffff;color:#0000ff">foreach</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">UnifiedFile</span><span style="background:#ffffff;color:#000000"> fil2 </span><span style="background:#ffffff;color:#0000ff">in</span><span style="background:#ffffff;color:#000000"> dir.Files)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">BaseMedia</span><span style="background:#ffffff;color:#000000">.IsMedia(fil2.VirtualPath))</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">refLinks += </span><span style="background:#ffffff;color:#a31515">"<a href=\""</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"\" class=\"ignore\" style=\"display:none;\">"</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"</a>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<div style=\"float:left;\">"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<img style=\"width:80px;height:80px;\" src=\"/FileCache"</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"/width_80.height_80.mode_crop.jpg\" data-org=\""</span><span style="background:#ffffff;color:#000000"> + fil2.VirtualPath + </span><span style="background:#ffffff;color:#a31515">"\" />"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">else</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">item.Attributes.Add(</span><span style="background:#ffffff;color:#a31515">"style"</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#a31515">"border:1px solid black;float:left;margin-right:5px;margin-bottom:5px;"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> filname = </span><span style="background:#ffffff;color:#2b91af">Path</span><span style="background:#ffffff;color:#000000">.GetFileName(href);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> path = href.Substring(0, href.Length - filname.Length);</span></li> <li> <span style="background:#ffffff;color:#000000">inner = </span><span style="background:#ffffff;color:#a31515">"<div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<input type=checkbox onclick=\"$(this).parent().parent().removeAttr('data-href');$(this).parent().parent().css('display','none');var obj=$(this).closest('.ownerDiv').find('.actionField');obj.val('"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"');obj.click();\" />delete"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<input type=checkbox onclick=\"$(this).parent().parent().attr('data-href','"</span><span style="background:#ffffff;color:#000000"> + path + </span><span style="background:#ffffff;color:#a31515">"');var obj=$(this).closest('.ownerDiv').find('.actionField');$(this).parent().html('All files from folder:<br />"</span><span style="background:#ffffff;color:#000000"> + path + </span><span style="background:#ffffff;color:#a31515">"');obj.val('"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"');obj.click();\" />all<br/>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">item.Attributes.Remove(</span><span style="background:#ffffff;color:#a31515">"onclick"</span><span style="background:#ffffff;color:#000000">);</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"<img style=\"width:80px;height:80px;\" src=\"/FileCache"</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"/width_80.height_80.mode_crop.jpg\" data-org=\""</span><span style="background:#ffffff;color:#000000"> + href + </span><span style="background:#ffffff;color:#a31515">"\" />"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">inner += </span><span style="background:#ffffff;color:#a31515">"</div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">item.InnerHtml = inner+</span><span style="background:#ffffff;color:#a31515">"<div style=\"clear:both;\"></div>"</span><span style="background:#ffffff;color:#000000">;</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">base</span><span style="background:#ffffff;color:#000000">.Value = doc.DocumentNode.OuterHtml;</span></li> <li> <span style="background:#ffffff;color:#000000">} </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> {</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">base</span><span style="background:#ffffff;color:#000000">.Value = </span><span style="background:#ffffff;color:#0000ff">value</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">List</span><span style="background:#ffffff;color:#000000"><</span><span style="background:#ffffff;color:#2b91af">VirtualFile</span><span style="background:#ffffff;color:#000000">> GetFiles()</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> result = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">List</span><span style="background:#ffffff;color:#000000"><</span><span style="background:#ffffff;color:#2b91af">VirtualFile</span><span style="background:#ffffff;color:#000000">>();</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> str = </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.LongString;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (str != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span></li> <li> <span style="background:#ffffff;color:#000000">{</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> doc = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">HtmlDocument</span><span style="background:#ffffff;color:#000000">();</span></li> <li> <span style="background:#ffffff;color:#000000">doc.LoadHtml(str);</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">foreach</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> item </span><span style="background:#ffffff;color:#0000ff">in</span><span style="background:#ffffff;color:#000000"> doc.DocumentNode.ChildNodes)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (item.Name == </span><span style="background:#ffffff;color:#a31515">"div"</span><span style="background:#ffffff;color:#000000"> && item.Attributes.Contains(</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">) && item.Attributes[</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">].Value != </span><span style="background:#ffffff;color:#a31515">""</span><span style="background:#ffffff;color:#000000">)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> href = item.Attributes[</span><span style="background:#ffffff;color:#a31515">"data-href"</span><span style="background:#ffffff;color:#000000">].Value;</span></li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (href.EndsWith(</span><span style="background:#ffffff;color:#a31515">"/"</span><span style="background:#ffffff;color:#000000">))</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> dir = System.Web.Hosting.</span><span style="background:#ffffff;color:#2b91af">HostingEnvironment</span><span style="background:#ffffff;color:#000000">.VirtualPathProvider.GetDirectory(href) </span><span style="background:#ffffff;color:#0000ff">as</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UnifiedDirectory</span><span style="background:#ffffff;color:#000000">;</span></li> <li> <span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (dir != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">foreach</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">UnifiedFile</span><span style="background:#ffffff;color:#000000"> fil2 </span><span style="background:#ffffff;color:#0000ff">in</span><span style="background:#ffffff;color:#000000"> dir.Files)</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#000000">result.Add(fil2);</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#0000ff">else</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">{</span></li> <li> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> file = System.Web.Hosting.</span><span style="background:#ffffff;color:#2b91af">HostingEnvironment</span><span style="background:#ffffff;color:#000000">.VirtualPathProvider.GetFile(href) ;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">result.Add(file);</span></li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> </li> <li> </li> <li style="background: #f3f3f3"> </li> <li> <span style="background:#ffffff;color:#000000">}</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> <span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> result;</span></li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> </li> <li style="background: #f3f3f3"> <span style="background:#ffffff;color:#000000">}</span></li> <li> </li> <li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">}</span></li> </ol> </div> </div> </div> <p>I guess I could have done this more dojo <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smilefjes" src="/link/19af9292c56a491e9797dbbc6a0ddeae.png" />, but with my current knowledge this was the best I managed. If some of you have made a more advanced dojo property in EPiServer 7 please make a blog so we can learn from you.</p>
Using Page Properties as dynamic properties in EPiServer 7
/blogs/Anders-Hattestad/Dates/2013/8/Using-Page-Properties-as-dynamic-properties-in-EPiServer-7/
2013-08-06T12:48:40.0000000Z
<p>Dynamic properties was great for having properties that is inherit. But the new interface of EPiServer 7 makes this a bit difficult. One solution is to modify the EPiServer: Property code so it allows for finding the property that have value up in the page structure. And if the Property exist on the page allow the editor to add values to the current property and break the inherit chain.</p> <p>The code is simple. Find the first property (can be a page block) that have value and display that</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6629b79e-de11-48b1-854d-bfb6532568a5" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #fff; max-height: 500px; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">PropertyInherit</span> : EPiServer.Web.WebControls.<span style="color:#2b91af">Property</span></li> <li style="background: #f3f3f3">{</li> <li> <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> CreateChildControls()</li> <li style="background: #f3f3f3"> {</li> <li> <span style="color:#0000ff">try</span></li> <li style="background: #f3f3f3"> {</li> <li> InnerProperty = FindInheritBlock(PageSource.CurrentPage, PropertyName);</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">if</span> (!InnerProperty.IsNull && PageSource.CurrentPage.Property[PropertyName] != <span style="color:#0000ff">null</span> && PageSource.CurrentPage.Property[PropertyName].IsNull)</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#008000">//Is using inherit isUsingInherit = true;</span></li> <li> }</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">if</span> (PageSource.CurrentPage.Property[PropertyName] != <span style="color:#0000ff">null</span>)</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">this</span>.Editable = <span style="color:#0000ff">true</span>; <span style="color:#008000">//Property exist on current page, make it editable</span></li> <li> }</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">base</span>.CreateChildControls();</li> <li> </li> <li style="background: #f3f3f3"> }</li> <li> <span style="color:#0000ff">catch</span></li> <li style="background: #f3f3f3"> {</li> <li> AddLiteral(<span style="color:#a31515">"Error in PropertyInherit"</span>);</li> <li style="background: #f3f3f3"> }</li> <li> </li> <li style="background: #f3f3f3"> }</li> <li> <span style="color:#0000ff">protected</span> <span style="color:#2b91af">PropertyData</span> FindInheritBlock(<span style="color:#2b91af">PageData</span> page, <span style="color:#0000ff">string</span> key)</li> <li style="background: #f3f3f3"> {</li> <li> <span style="color:#0000ff">var</span> prop = page.Property[key];</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">if</span> (prop != <span style="color:#0000ff">null</span> && !prop.IsNull)</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">return</span> prop;</li> <li> }</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">if</span> (<span style="color:#2b91af">PageReference</span>.RootPage.CompareToIgnoreWorkID(page.PageLink))</li> <li> <span style="color:#0000ff">return</span> <span style="color:#0000ff">null</span>;</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">return</span> FindInheritBlock(EPiServer.<span style="color:#2b91af">DataFactory</span>.Instance.GetPage(page.ParentLink), key);</li> <li> }</li> <li style="background: #f3f3f3"> </li> <li> <span style="color:#2b91af">Literal</span> AddLiteral(<span style="color:#0000ff">string</span> key)</li> <li style="background: #f3f3f3"> {</li> <li> <span style="color:#0000ff">var</span> lit = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Literal</span>() { ID = key };</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">this</span>.Controls.Add(lit);</li> <li> <span style="color:#0000ff">return</span> lit;</li> <li style="background: #f3f3f3"> }</li> <li>}</li> </ol> </div> </div> </div> <p>If you have page block SideBarImage with no data, but the parent page have data it will display</p> <p><a href="/link/0108a378efcd4431a670dd9aed919680.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/709e5538cd244f798ec3de4adb12bf51.png" width="354" height="277" /></a> </p> <p>but when you try to edit it it will be empty</p> <p><a href="/link/b0c3ce64c3e24910b2a51ac059b4d441.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/63dc4bf9821b4fc8a33bc61f6c309347.png" width="487" height="272" /></a></p> <p>if you go to the parent page and try to edit it it will have data of course <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smilefjes" src="/link/987d53a7362f4101aa17725a6a9df1ff.png" /></p> <p> </p> <p><a href="/link/c326d254a3424e499ca1b262db866abc.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/a79750005e4c4c7db934e7dc9a400549.png" width="402" height="163" /></a></p> <p>You will need to register you new web control </p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d46a92e7-a40b-43d9-b7f3-e3284124dd39" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff"><</span><span style="color:#a31515">httpRuntime</span><span style="color:#0000ff"> </span><span style="color:#ff0000">requestValidationMode</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">2.0</span>"<span style="color:#0000ff"> /></span></li> <li style="background: #f3f3f3"><span style="color:#0000ff"><</span><span style="color:#a31515">pages</span><span style="color:#0000ff"> </span><span style="color:#ff0000">validateRequest</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">false</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">enableEventValidation</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">true</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">pageParserFilterType</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35</span>"<span style="color:#0000ff">></span></li> <li> <span style="color:#0000ff"><</span><span style="color:#a31515">controls</span><span style="color:#0000ff">></span></li> <li style="background: #f3f3f3"> <span style="color:#0000ff"><</span><span style="color:#a31515">add</span><span style="color:#0000ff"> </span><span style="color:#ff0000">tagPrefix</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Itera</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">namespace</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Itera.WebControls</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">assembly</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Itera</span>"<span style="color:#0000ff"> /></span></li> </ol> </div> </div> </div> <p>And you can use it like this</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d0cfbd96-d8c3-429d-a021-ca7f62049a98" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"> <li><span style="color:#0000ff"><</span><span style="color:#800000">Itera</span><span style="color:#0000ff">:</span><span style="color:#800000">PropertyInherit</span> <span style="color:#ff0000">runat</span><span style="color:#0000ff">="server"</span> <span style="color:#ff0000">PropertyName</span><span style="color:#0000ff">="SidebarImage"</span> <span style="color:#ff0000">id</span><span style="color:#0000ff">="SidebarImage1"</span> <span style="color:#0000ff">/></span></li> </ol> </div> </div> </div>
How to make automatically preview of an IContent item in other blocks
/blogs/Anders-Hattestad/Dates/2013/6/How-to-make-automatically-preview-of-an-IContent-item-in-other-blocks/
2013-06-28T10:13:19.0000000Z
<p>It is possible in EPiServer 7 to make a preview page, where you can edit the blocks properties and show how it will be displayed in different settings. But some times you are making a block that will be displayed in other blocks, and you want to show how  the current block will be shown in those.</p> <style>
.wlWriterEditableSmartContent,.wlWriterEditableSmartContent div {clear: both !important;}</style> <p>You could make some logic in the preview template that takes care of this, but if you want to make it automatically this is a way to archive that.</p> <p>If you are using the Alloy template it’s the /Views/Blocks/BlockPreview.aspx file you should change.</p> <p>I change the front code to this</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:dc7e5509-f21f-4bbf-9fc8-6a72ab862e9e" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"> <li><span style="color:#0000ff"><</span><span style="color:#800000">asp</span><span style="color:#0000ff">:</span><span style="color:#800000">Content</span> <span style="color:#ff0000">ID</span><span style="color:#0000ff">="Content1"</span> <span style="color:#ff0000">ContentPlaceHolderID</span><span style="color:#0000ff">="PageContent"</span> <span style="color:#ff0000">runat</span><span style="color:#0000ff">="server"></span></li> <li style="background: #f3f3f3"> <span style="color:#0000ff"><</span><span style="color:#800000">EPiServer</span><span style="color:#0000ff">:</span><span style="color:#800000">Property</span> <span style="color:#ff0000">ID</span><span style="color:#0000ff">="EditProperty"</span> <span style="color:#ff0000">runat</span><span style="color:#0000ff">="server"></span></li> <li> <span style="color:#0000ff"><</span><span style="color:#800000">RenderSettings</span> <span style="color:#ff0000">EnableEditFeaturesForChildren</span><span style="color:#0000ff">="true"</span> <span style="color:#ff0000">Tag</span><span style="color:#0000ff">="Edit"</span> <span style="color:#0000ff">/></span></li> <li style="background: #f3f3f3"> <span style="color:#0000ff"></</span><span style="color:#800000">EPiServer</span><span style="color:#0000ff">:</span><span style="color:#800000">Property</span><span style="color:#0000ff">></span></li> <li> <span style="color:#0000ff"><</span><span style="color:#800000">asp</span><span style="color:#0000ff">:</span><span style="color:#800000">PlaceHolder</span> <span style="color:#ff0000">ID</span><span style="color:#0000ff">="PreviewArea"</span> <span style="color:#ff0000">runat</span><span style="color:#0000ff">="server"</span> <span style="color:#0000ff">/></span></li> <li style="background: #f3f3f3"><span style="color:#0000ff"></</span><span style="color:#800000">asp</span><span style="color:#0000ff">:</span><span style="color:#800000">Content</span><span style="color:#0000ff">></span></li> </ol> </div> </div> </div> <p>As you can see I have made a tag for Edit, so my edit view will be used for the current block.</p> <p>The code behind looks like this</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5ea64901-1dea-405f-95cd-a39c487426c2" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"> <li>[<span style="color:#2b91af">TemplateDescriptor</span>(Inherited = <span style="color:#0000ff">true</span>, Tags = <span style="color:#0000ff">new</span>[] { <span style="color:#2b91af">RenderingTags</span>.Preview })]</li> <li style="background: #f3f3f3"><span style="color:#0000ff">public</span> <span style="color:#0000ff">partial</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">ItemPreviewControl</span> : <span style="color:#2b91af">PreviewPage</span>, <span style="color:#2b91af">IRenderTemplate</span><<span style="color:#2b91af">SiteItemBlockData</span>></li> <li>{</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> OnInit(<span style="color:#2b91af">EventArgs</span> e)</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">base</span>.OnInit(e);</li> <li> <span style="color:#008000">//(Master as ResponsivtDesign).BodyClass = "";</span></li> <li style="background: #f3f3f3"> EditProperty.DataBind();</li> <li> <span style="color:#2b91af">ContentAPI</span>.Current.CreatePreiviewOfItemInLists(PreviewArea, CurrentData,<span style="color:#0000ff">this</span>);</li> <li style="background: #f3f3f3"> RenderBlockPreviews();</li> <li> }</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> OnSaveStateComplete(<span style="color:#2b91af">EventArgs</span> e)</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">base</span>.OnSaveStateComplete(e);</li> <li> SetupPreviewPropertyControl(EditProperty, <span style="color:#0000ff">new</span>[] { CurrentData });</li> <li style="background: #f3f3f3"> </li> <li> }</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">private</span> <span style="color:#0000ff">void</span> RenderBlockPreviews()</li> <li> {</li> <li style="background: #f3f3f3"> SetupPreviewPropertyControl(EditProperty, <span style="color:#0000ff">new</span>[] { CurrentData });</li> <li> }</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">private</span> <span style="color:#0000ff">void</span> SetupPreviewPropertyControl(<span style="color:#2b91af">Property</span> propertyControl, <span style="color:#2b91af">IEnumerable</span><<span style="color:#2b91af">IContent</span>> contents)</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">var</span> contentArea = <span style="color:#0000ff">new</span> <span style="color:#2b91af">ContentArea</span>();</li> <li> <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> content <span style="color:#0000ff">in</span> contents)</li> <li style="background: #f3f3f3"> {</li> <li> contentArea.Add(content);</li> <li style="background: #f3f3f3"> }</li> <li> <span style="color:#0000ff">var</span> previewProperty = <span style="color:#0000ff">new</span> <span style="color:#2b91af">PropertyContentArea</span> { Value = contentArea, Name = <span style="color:#a31515">"PreviewPropertyData"</span> };</li> <li style="background: #f3f3f3"> propertyControl.InnerProperty = previewProperty;</li> <li> } </li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div> <p>The code that makes the preview are in the ContentAPI class. You could use that class for preview of pages in different kinds of settings also. </p> <p>The code that finds all the blocks that is defined and checks if the block should display is like this</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0aee54dc-09fd-4e0c-ab59-ce1898142d38" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">ContentAPI</span></li> <li style="background: #f3f3f3">{</li> <li> <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#2b91af">ContentAPI</span> Current = <span style="color:#0000ff">new</span> <span style="color:#2b91af">ContentAPI</span>();</li> <li style="background: #f3f3f3"> </li> <li> <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> CreatePreiviewOfItemInLists(<span style="color:#2b91af">Control</span> container, <span style="color:#2b91af">IContent</span> data,<span style="color:#2b91af">TemplateControl</span> templateControl)</li> <li style="background: #f3f3f3"> {</li> <li> <span style="color:#0000ff">var</span> repository = <span style="color:#2b91af">ServiceLocator</span>.Current.GetInstance<<span style="color:#2b91af">BlockTypeRepository</span>>();</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> block <span style="color:#0000ff">in</span> repository.List())</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">var</span> blockType = block.ModelType;</li> <li> <span style="color:#0000ff">if</span> (blockType.GetInterface(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">ICanBeUsedForPewivewOfItems</span>).Name)!=<span style="color:#0000ff">null</span>)</li> <li style="background: #f3f3f3"> {</li> <li> <span style="color:#0000ff">var</span> obj = EPiServer.<span style="color:#2b91af">DataFactory</span>.Instance.GetDefault<<span style="color:#2b91af">IContent</span>>(<span style="color:#2b91af">ContentReference</span>.GlobalBlockFolder, block.ID);</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">if</span> (obj <span style="color:#0000ff">is</span> <span style="color:#2b91af">ICanBeUsedForPewivewOfItems</span>)</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">var</span> add=(obj <span style="color:#0000ff">as</span> <span style="color:#2b91af">ICanBeUsedForPewivewOfItems</span>).AddInPreview(data);</li> <li> <span style="color:#0000ff">if</span> (add)</li> <li style="background: #f3f3f3"> {</li> <li> <span style="color:#2b91af">Control</span> control = <span style="color:#0000ff">this</span>.TemplateControlLoader.Service.LoadControl(<span style="color:#2b91af">HttpContext</span>.Current.ContextBaseOrNull(), obj, templateControl, <span style="color:#a31515">"Default"</span>);</li> <li style="background: #f3f3f3"> container.Controls.Add(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Literal</span>() { Text = <span style="color:#a31515">"<div class='preview'><h2>"</span> + block.DisplayName + <span style="color:#a31515">" ["</span> + block.Name + <span style="color:#a31515">"]"</span> + <span style="color:#a31515">"</h2>"</span> });</li> <li> container.Controls.Add(control);</li> <li style="background: #f3f3f3"> container.Controls.Add(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Literal</span>() { Text = <span style="color:#a31515">"</div>"</span> });</li> <li> }</li> <li style="background: #f3f3f3"> }</li> <li> }</li> <li style="background: #f3f3f3"> }</li> <li> }</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">public</span> <span style="color:#0000ff">virtual</span> <span style="color:#2b91af">Injected</span><<span style="color:#2b91af">TemplateControlLoader</span>> TemplateControlLoader</li> <li> {</li> <li style="background: #f3f3f3"> <span style="color:#0000ff">get</span>;</li> <li> <span style="color:#0000ff">set</span>;</li> <li style="background: #f3f3f3"> }</li> <li>}</li> </ol> </div> </div> </div> <p>What this code do is that it checks every block if it implements the interface ICanBeUsedForPewivewOfItems.</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fbb1de2d-dbc7-4cc4-a29e-abfb38b0cc90" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">interface</span> <span style="color:#2b91af">ICanBeUsedForPewivewOfItems</span> </li> <li style="background: #f3f3f3">{</li> <li> <span style="color:#0000ff">bool</span> AddInPreview(<span style="color:#2b91af">IContent</span> item);</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div> <p>And returns true if the current item could or should be displayed in that block view.</p> <p>This will result in </p> <p><a href="/link/48e78567c6224f7e9b3f3c443bbf09f8.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/9c08788f189c4541b156184936e75ba1.png" width="644" height="436" /></a></p> <p> </p> <p>This can also be used for a page, and show how it will appear in different kind of blocks.</p> <p>if you add in your aspx or masterpage</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:47046677-5c1e-4292-a40e-1b6161e21298" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"> <li><span style="color:#0000ff"><</span><span style="color:#800000">asp</span><span style="color:#0000ff">:</span><span style="color:#800000">Panel</span> <span style="color:#ff0000">ID</span><span style="color:#0000ff">="PreviewStuff"</span> <span style="color:#ff0000">runat</span><span style="color:#0000ff">="server"</span> <span style="color:#ff0000">Visible</span><span style="color:#0000ff">="false"></span></li> <li style="background: #f3f3f3"> <span style="color:#0000ff"><</span><span style="color:#800000">input</span> <span style="color:#ff0000">type</span><span style="color:#0000ff">="button"</span> <span style="color:#ff0000">onclick</span><span style="color:#0000ff">="$('#preivewItem').toggle();"</span> <span style="color:#ff0000">value</span><span style="color:#0000ff">="Show page in different settings"</span> <span style="color:#0000ff">/></span></li> <li> <span style="color:#0000ff"><</span><span style="color:#800000">div</span> <span style="color:#ff0000">id</span><span style="color:#0000ff">="preivewItem"</span> <span style="color:#ff0000">style</span><span style="color:#0000ff">="</span><span style="color:#ff0000">display</span><span style="color:#0000ff">:none;"></span></li> <li style="background: #f3f3f3"> <span style="color:#0000ff"><</span><span style="color:#800000">asp</span><span style="color:#0000ff">:</span><span style="color:#800000">PlaceHolder</span> <span style="color:#ff0000">ID</span><span style="color:#0000ff">="PreviewArea"</span> <span style="color:#ff0000">runat</span><span style="color:#0000ff">="server"</span> <span style="color:#0000ff">/></span></li> <li> <span style="color:#0000ff"></</span><span style="color:#800000">div</span><span style="color:#0000ff">></span></li> <li style="background: #f3f3f3"><span style="color:#0000ff"></</span><span style="color:#800000">asp</span><span style="color:#0000ff">:</span><span style="color:#800000">Panel</span><span style="color:#0000ff">></span></li> </ol> </div> </div> </div> <p>and this to your code behind</p> <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0c5d382f-66f1-40f3-85e7-fadecc142171" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> OnLoad(<span style="color:#2b91af">EventArgs</span> e)</li> <li style="background: #f3f3f3">{</li> <li> <span style="color:#0000ff">if</span> (EPiServer.Editor.<span style="color:#2b91af">PageEditing</span>.PageIsInEditMode)</li> <li style="background: #f3f3f3"> {</li> <li> <span style="color:#0000ff">if</span> (PreviewArea != <span style="color:#0000ff">null</span> && PreviewStuff!=<span style="color:#0000ff">null</span>)</li> <li style="background: #f3f3f3"> {</li> <li> PreviewStuff.Visible = <span style="color:#0000ff">true</span>;</li> <li style="background: #f3f3f3"> <span style="color:#2b91af">ContentAPI</span>.Current.CreatePreiviewOfItemInLists(PreviewArea, CurrentPage, <span style="color:#0000ff">this</span>);</li> <li> }</li> <li style="background: #f3f3f3"> }</li> <li> <span style="color:#0000ff">base</span>.OnLoad(e);</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div> <p> </p> <p>this will give you</p> <p><a href="/link/a495bc8adc7e490fae4f54e220186ed6.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/d67d04fd6fcf40518686ab07ee83b307.png" width="644" height="391" /></a></p> <p><a href="/link/161d110b21814fe6ba265a6901fb814f.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="/link/7761ed8fdc934d63bc82d1f1d2cb5745.png" width="551" height="484" /></a></p> <p>Thats all. Hope you all a nice summer<img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smilefjes som blunker" src="/link/a2daa89255854247af91724233d620f4.png" /></p>
Render ContentArea with temporarily content
/blogs/Anders-Hattestad/Dates/2013/5/Render-ContentArea-with-temporarily-content/
2013-05-08T09:16:31.0000000Z
<p><span style="background-color: #ffffff; color: #000000;">One nice feature in EPiServer 7 is the ability to render content based on tags and type. But sometimes you want to add temporary items to a collection and then render them. This can be a RSS feed, or if you want to add one link list with and existing ContentArea.</span></p>
<p><span style="background-color: #ffffff; color: #000000;">The problem is that temporary items will not be rendered thru the PropertyContentAreaControl. So if you add some temporarily items like some RSS articles it will not render.</span></p>
<p><span style="background-color: #ffffff; color: #000000;">You can add IContent to a ContentArea, but internally it is stored as content reference, and the object is not preserved. It basically add the content Reference ID, and then when you render it it gets the content again. That means you cant manipulate the IContent items before you render them. Personally I think this behaviour is a bit odd, and makes it a bit harder to do cool stuff <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="/link/5ed273741bc349b6a7e78a0936959af6.png" alt="Smilefjes" /></span></p>
<p><strong><span style="background-color: #ffffff; color: #000000;">Create temporarily content</span></strong></p>
<p><span style="color: #000000;"><span style="background-color: #ffffff;"><span>Before it was possible to create pages and add them to a page list. You had to add the ACL to the page so it was not filtered out.</span> </span></span></p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:84d019f2-44f5-4e0d-8b6e-4bc669981e6b" class="wlWriterEditableSmartContent" style="float: none; margin: 0px; display: inline; padding: 0px;">
<div style="font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #fff; max-height: 300px; overflow: auto;"><ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;">
<li><span style="color: #0000ff;">var</span> page = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">TempPageType</span>();</li>
<li style="background: #f3f3f3;">page.Property.Add(<span style="color: #a31515;">"PageTypeID"</span>, <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">PropertyNumber</span>(pageID));</li>
<li>page.Property.Add(<span style="color: #a31515;">"PageLink"</span>, <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">PropertyPageReference</span>(<span style="color: #2b91af;">PageReference</span>.EmptyReference));</li>
<li style="background: #f3f3f3;"> </li>
<li>page.Property.Add(<span style="color: #a31515;">"PagePendingPublish"</span>, <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">PropertyBoolean</span>(<span style="color: #0000ff;">false</span>));</li>
<li style="background: #f3f3f3;">page.Property.Add(<span style="color: #a31515;">"PageWorkStatus"</span>,</li>
<li> <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">PropertyNumber</span>(<span style="color: #2b91af;">Convert</span>.ToInt32(<span style="color: #2b91af;">VersionStatus</span>.Published)));</li>
<li style="background: #f3f3f3;">page.ACL.Add(<span style="color: #0000ff;">new</span> <span style="color: #2b91af;">AccessControlEntry</span>(<span style="color: #a31515;">"Everyone"</span>, <span style="color: #2b91af;">AccessLevel</span>.Read));</li>
</ol></div>
</div>
</div>
<p><span style="background-color: #ffffff;"> </span></p>
<p><span style="background-color: #ffffff; color: #000000;">In EPiServer 7 you have to register this page type and also add the PageTypeID to the temporarily page</span></p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5a728c0b-8ea0-4c8b-9109-eb058b245005" class="wlWriterEditableSmartContent" style="float: none; margin: 0px; display: inline; padding: 0px;">
<div style="font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color: #0000ff;">var</span> repository = <span style="color: #2b91af;">ServiceLocator</span>.Current.GetInstance<<span style="color: #2b91af;">IContentTypeRepository</span><<span style="color: #2b91af;">PageType</span>>>();</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">var</span> pageType = repository.Load(<span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">TempPageType</span>));</li>
<li><span style="color: #0000ff;">var</span> pageID=-1;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (pageType!=<span style="color: #0000ff;">null</span>)</li>
<li> pageID=pageType.ID;</li>
<li style="background: #f3f3f3;">page.Property.Add(<span style="color: #a31515;">"PageTypeID"</span>, <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">PropertyNumber</span>(pageID));</li>
</ol></div>
</div>
</div>
<p><span style="background-color: #ffffff;">And then register the page type.</span></p>
<p> </p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:efffc6fd-d239-4864-997a-44549870adab" class="wlWriterEditableSmartContent" style="float: none; margin: 0px; display: inline; padding: 0px;">
<div style="font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #fff; max-height: 300px; overflow: auto;"><ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;">
<li>[<span style="color: #2b91af;">ContentType</span>(GUID = <span style="color: #a31515;">"454E47D6-BC76-4596-BC03-8BA519BB4650"</span>, GroupName = <span style="color: #a31515;">"Default"</span>,AvailableInEditMode=<span style="color: #0000ff;">false</span>)]</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">TempPageType</span> : <span style="color: #2b91af;">SitePageData</span></li>
<li>{</li>
<li style="background: #f3f3f3;"> [<span style="color: #2b91af;">Ignore</span>]</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">object</span> InnerObject { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; }</li>
<li style="background: #f3f3f3;"> </li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> EPiServer.Security.<span style="color: #2b91af;">ISecurityDescriptor</span> GetSecurityDescriptor()</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #0000ff;">if</span> (<span style="color: #2b91af;">PageReference</span>.IsNullOrEmpty(PageLink))</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">OwnSecurityDescriptor</span>();</li>
<li> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">base</span>.GetSecurityDescriptor();</li>
<li style="background: #f3f3f3;"> }</li>
<li> </li>
<li style="background: #f3f3f3;">}</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #2b91af;">OwnSecurityDescriptor</span>:<span style="color: #2b91af;">ISecurityDescriptor</span></li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #2b91af;">AccessLevel</span> GetAccessLevel(<span style="color: #2b91af;">IPrincipal</span> principal)</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #0000ff;">return</span> <span style="color: #2b91af;">AccessLevel</span>.FullAccess;</li>
<li style="background: #f3f3f3;"> }</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> HasAccess(<span style="color: #2b91af;">IPrincipal</span> principal, <span style="color: #2b91af;">AccessLevel</span> access)</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>;</li>
<li style="background: #f3f3f3;"> }</li>
<li>}</li>
</ol></div>
</div>
</div>
<p> </p>
<p><span style="background-color: #ffffff;"> </span></p>
<p><strong><span style="background-color: #ffffff;">To render</span></strong></p>
<p><span style="background-color: #ffffff;">The solution is to make your own render of a List of IContent</span></p>
<p><span style="background-color: #ffffff;">Lucky for us it’s still easy to look at the current code using Reflector or some other app. </span></p>
<p><span style="background-color: #ffffff;">This code will take a list of IContent and render them accordingly to the tags. So you can use it like this, where Result is a List<IContent></span></p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ff25dbbc-3654-4779-b4dc-4a3136f278cf" class="wlWriterEditableSmartContent" style="float: none; margin: 0px; display: inline; padding: 0px;">
<div style="font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #fff; max-height: 300px; overflow: auto;"><ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;">
<li> <span style="color: #0000ff;">public</span><span style="color: #0000ff;">bool</span> AddResult2Container(<span style="color: #2b91af;">Control</span> container, <span style="color: #0000ff;">string</span> tag, <span style="color: #0000ff;">bool</span> add_Ul_Li)</li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: #0000ff;">var</span> haveContent = <span style="color: #0000ff;">false</span>;</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">var</span> result = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">RenderContentArea</span>() { Data = Result };</li>
<li> result.Tag = tag;</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> (add_Ul_Li)</li>
<li> {</li>
<li style="background: #f3f3f3;"> result.TagName = <span style="color: #a31515;">"ul"</span>;</li>
<li> result.TagChildName = <span style="color: #a31515;">"li"</span>;</li>
<li style="background: #f3f3f3;"> }</li>
<li> container.Controls.Add(result);</li>
<li style="background: #f3f3f3;"> haveContent = result.CreateContent();</li>
<li> <span style="color: #0000ff;">return</span> haveContent;</li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
<p><span style="background-color: #ffffff;">The code that runs is this</span></p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8e27801d-557c-4a9a-894e-9ca18dc1a16c" class="wlWriterEditableSmartContent" style="float: none; margin: 0px; display: inline; padding: 0px;">
<div style="font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;"><ol style="background: #ffffff; margin: 0 0 0 3em; padding: 0 0 0 5px; white-space: nowrap;">
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">RenderContentArea</span> : <span style="color: #2b91af;">PlaceHolder</span></li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">IContent</span>> Data { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> TagName { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; }</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> TagChildName { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; }</li>
<li style="background: #f3f3f3;"> </li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> ItemCssClass { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> ItemChildCssClass { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; }</li>
<li> </li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> Tag { <span style="color: #0000ff;">get</span>; <span style="color: #0000ff;">set</span>; }</li>
<li> </li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">private</span> <span style="color: #2b91af;">ContentControlResolver</span> _contentControlResolver;</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #2b91af;">ContentControlResolver</span> ContentControlResolver</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #0000ff;">get</span></li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #2b91af;">ContentControlResolver</span> arg_1D_0;</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> ((arg_1D_0 = <span style="color: #0000ff;">this</span>._contentControlResolver) == <span style="color: #0000ff;">null</span>)</li>
<li> {</li>
<li style="background: #f3f3f3;"> arg_1D_0 = (<span style="color: #0000ff;">this</span>._contentControlResolver = <span style="color: #2b91af;">ServiceLocator</span>.Current.GetInstance<<span style="color: #2b91af;">ContentControlResolver</span>>());</li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">return</span> arg_1D_0;</li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">set</span></li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">this</span>._contentControlResolver = <span style="color: #0000ff;">value</span>;</li>
<li> }</li>
<li style="background: #f3f3f3;"> }</li>
<li> </li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">protected</span> <span style="color: #2b91af;">IList</span><<span style="color: #2b91af;">Control</span>> GetContentRenderers2()</li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> (Data == <span style="color: #0000ff;">null</span> || Data.Count<<span style="color: #2b91af;">IContent</span>>() == 0)</li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Control</span>>();</li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">string</span> itemTagName = TagChildName;</li>
<li> <span style="color: #0000ff;">string</span> itemCssClass = ItemChildCssClass;</li>
<li style="background: #f3f3f3;"> </li>
<li> <span style="color: #0000ff;">return</span> ResolveContentControls(<span style="color: #0000ff;">this</span>, <span style="color: #0000ff;">this</span>.Tag, itemCssClass, itemTagName);</li>
<li style="background: #f3f3f3;"> }</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">virtual</span> <span style="color: #2b91af;">Injected</span><<span style="color: #2b91af;">TemplateControlLoader</span>> TemplateControlLoader</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #0000ff;">get</span>;</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">set</span>;</li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">private</span> <span style="color: #2b91af;">WebFormsContentValidator</span> _contentValidator;</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">virtual</span> <span style="color: #2b91af;">WebFormsContentValidator</span> ContentValidator</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #0000ff;">get</span></li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #2b91af;">WebFormsContentValidator</span> arg_1D_0;</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> ((arg_1D_0 = <span style="color: #0000ff;">this</span>._contentValidator) == <span style="color: #0000ff;">null</span>)</li>
<li> {</li>
<li style="background: #f3f3f3;"> arg_1D_0 = (<span style="color: #0000ff;">this</span>._contentValidator = <span style="color: #2b91af;">ServiceLocator</span>.Current.GetInstance<<span style="color: #2b91af;">WebFormsContentValidator</span>>());</li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">return</span> arg_1D_0;</li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">set</span></li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">this</span>._contentValidator = <span style="color: #0000ff;">value</span>;</li>
<li> }</li>
<li style="background: #f3f3f3;"> }</li>
<li> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">virtual</span> <span style="color: #2b91af;">IList</span><<span style="color: #2b91af;">Control</span>> ResolveContentControls( <span style="color: #2b91af;">Control</span> parentControl, <span style="color: #0000ff;">string</span> tag, <span style="color: #0000ff;">string</span> itemCssClass, <span style="color: #0000ff;">string</span> itemTagName)</li>
<li style="background: #f3f3f3;"> {</li>
<li> </li>
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">IContentFilter</span> filter = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">FilterContentForVisitor</span>(<span style="color: #2b91af;">TemplateTypeCategories</span>.WebFormsPartial, tag);</li>
<li> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Control</span>> list = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Control</span>>();</li>
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">IEnumerable</span><<span style="color: #2b91af;">IContent</span>> source = Data;</li>
<li> <span style="color: #2b91af;">IEnumerable</span><<span style="color: #2b91af;">IContent</span>> enumerable =</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">from</span> c <span style="color: #0000ff;">in</span> source</li>
<li> <span style="color: #0000ff;">where</span> !filter.ShouldFilter(c)</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">select</span> c;</li>
<li> <span style="color: #0000ff;">foreach</span> (<span style="color: #2b91af;">IContent</span> current <span style="color: #0000ff;">in</span> enumerable)</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #2b91af;">Control</span> control = <span style="color: #0000ff;">this</span>.TemplateControlLoader.Service.LoadControl(<span style="color: #2b91af;">HttpContext</span>.Current.ContextBaseOrNull(), current, parentControl.TemplateControl, tag);</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.ContentValidator.ExistInControlHierarchy(parentControl, current, control))</li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #008000;">//if (enableEditFeatures)</span></li>
<li> <span style="color: #008000;">//{</span></li>
<li style="background: #f3f3f3;"> <span style="color: #008000;">// HtmlGenericControl item = this.BuildCircularReferenceControl(current, itemTagName, itemCssClass);</span></li>
<li> <span style="color: #008000;">// list.Add(item);</span></li>
<li style="background: #f3f3f3;"> <span style="color: #008000;">//}</span></li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">else</span></li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">IVersionable</span> versionable = current <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">IVersionable</span>;</li>
<li> <span style="color: #0000ff;">if</span> (versionable == <span style="color: #0000ff;">null</span> || versionable.Status == <span style="color: #2b91af;">VersionStatus</span>.Published)</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: #2b91af;">ContentRenderer</span> item2 = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">ContentRenderer</span></li>
<li style="background: #f3f3f3;"> {</li>
<li> CurrentControl = control,</li>
<li style="background: #f3f3f3;"> CurrentData = current,</li>
<li> CurrentContent = current,</li>
<li style="background: #f3f3f3;"> Tag = tag,</li>
<li> CustomTagName = itemTagName,</li>
<li style="background: #f3f3f3;"> CssClass = itemCssClass,</li>
<li> TemplateControlLoader = <span style="color: #0000ff;">this</span>.TemplateControlLoader,</li>
<li style="background: #f3f3f3;"> RenderType =<span style="color: #2b91af;">RenderType</span>.Default</li>
<li> };</li>
<li style="background: #f3f3f3;"> list.Add(item2);</li>
<li> }</li>
<li style="background: #f3f3f3;"> }</li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">return</span> list;</li>
<li> }</li>
<li style="background: #f3f3f3;"> </li>
<li> </li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> CreateContent()</li>
<li> {</li>
<li style="background: #f3f3f3;"> </li>
<li> <span style="color: #0000ff;">string</span> containerTagName = (!<span style="color: #0000ff;">string</span>.IsNullOrEmpty(TagName)) ? TagName : <span style="color: #a31515;">"div"</span>;</li>
<li style="background: #f3f3f3;"> System.Collections.Generic.<span style="color: #2b91af;">IList</span><<span style="color: #2b91af;">Control</span>> contentRenderers = <span style="color: #0000ff;">this</span>.GetContentRenderers2();</li>
<li> <span style="color: #2b91af;">Control</span> control = CreateMainContainer(containerTagName);</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">foreach</span> (<span style="color: #2b91af;">Control</span> current <span style="color: #0000ff;">in</span> contentRenderers)</li>
<li> {</li>
<li style="background: #f3f3f3;"> control.Controls.Add(current);</li>
<li> <span style="color: #2b91af;">ContentRenderer</span> contentRenderer = current <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">ContentRenderer</span>;</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">if</span> (contentRenderer != <span style="color: #0000ff;">null</span>)</li>
<li> {</li>
<li style="background: #f3f3f3;"> contentRenderer.EnsureChildControlsCreated();</li>
<li> }</li>
<li style="background: #f3f3f3;"> }</li>
<li> <span style="color: #0000ff;">if</span> (contentRenderers.Count > 0)</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>;</li>
<li> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>;</li>
<li style="background: #f3f3f3;"> </li>
<li> }</li>
<li style="background: #f3f3f3;"> <span style="color: #0000ff;">protected</span> <span style="color: #2b91af;">HtmlGenericControl</span> CreateMainContainer( <span style="color: #0000ff;">string</span> containerTagName)</li>
<li> {</li>
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">HtmlGenericControl</span> htmlGenericControl = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">HtmlGenericControl</span>(containerTagName);</li>
<li> <span style="color: #0000ff;">this</span>.Controls.Add(htmlGenericControl);</li>
<li style="background: #f3f3f3;"> </li>
<li> <span style="color: #008000;">//if (enableEditFeatures)</span></li>
<li style="background: #f3f3f3;"> <span style="color: #008000;">//{</span></li>
<li> <span style="color: #008000;">// base.ApplyEditAttributes();</span></li>
<li style="background: #f3f3f3;"> <span style="color: #008000;">//}</span></li>
<li> <span style="color: #0000ff;">return</span> htmlGenericControl;</li>
<li style="background: #f3f3f3;"> }</li>
<li> </li>
<li style="background: #f3f3f3;">}</li>
</ol></div>
</div>
</div>
Upload within Xform
/blogs/Anders-Hattestad/Dates/2013/1/Upload-within-Xform/
2013-01-08T23:49:34.0000000Z
<p>Sometimes one would like to enable users to upload files in a Xform. Based on <a href="http://world.episerver.com/Blogs/Anders-Hattestad/Dates/2010/5/Extend-EPiServer-XForm/">my blog post about extending xforms</a>, I have added an upload function.</p> <p>I check if an textbox have a css class called FileUpload. If it has it will replace that textbox with an upload function.</p> <p><a href="/link/a768136fec16436286c429723105a5c5.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="/link/1c5fce819d7e4b8da68e639aab9238dd.jpg" width="644" height="387" /></a></p> <p>So it will look something like this</p> <p><a href="/link/5fe726587920491399c86322c66905a5.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clip_image002[5]" border="0" alt="clip_image002[5]" src="/link/b6193ebf69b946dc80ddfb396d3c9322.jpg" width="644" height="352" /></a></p> <p>It handles also more than one file</p> <p><a href="/link/a3fd0c668b824030be095f8451dbd972.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clip_image002[7]" border="0" alt="clip_image002[7]" src="/link/5777f7daf8ab41cc8940025185419644.jpg" width="628" height="484" /></a></p> <p>The stuff that will be saved is like this</p> <p><a href="/link/6b2c53544e8d4ced868fc85f368033ae.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clip_image002[9]" border="0" alt="clip_image002[9]" src="/link/57a78a0958654ed69785cc0e8abd3d13.jpg" width="644" height="134" /></a></p> <p><a href="/link/6e5eb4bc5536490d981f98c615665752.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="/link/835bcbcdc1b94602aca38d4b8e247af0.png" width="644" height="77" /></a></p> <p>The code will upload files to a seperate VPP folder </p> <pre class="language-csharp"><code> <add showInFileManager=<span class="str">"true"</span> virtualName=<span class="str">"XformFiles"</span>
virtualPath=<span class="str">"~/XformFiles/"</span> bypassAccessCheck=<span class="str">"true"</span>
physicalPath=<span class="str">"C:\EPiServer\VPP\XformFiles"</span>
name=<span class="str">"XformFiles"</span> type=<span class="str">"EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer"</span> /></code></pre>
<pre class="language-csharp"><code>I havent testet the code with CMS7 thou.</code></pre>
<pre class="language-csharp"><code><a href="http://world.episerver.com/Code/Anders-Hattestad1/Upload-using-XForm/">The code is uploaded here</a> </code></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>