Friday, March 20, 2020

C#, SMTP - Mail to folder


 <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="d:\SMTP_Drop" />
        <network host="localhost" />
      </smtp>
    </mailSettings>

Wednesday, February 19, 2020

Javscript, React - Simple React Toggle Example


state = {
showSomething: false
}

toogleSomething = () => {

const holder = this.state.showSomething;
this.setState({showSomething: !holder});
//Holder holds the previous value so that the next time you call the function it will be updated with the other new state value and therefore toggle. }

Monday, February 17, 2020

Create React App Instructions

install npm
create-react-app

npm install -g create-react-app

or with specific version
create-react-app assignment1 --scripts-version 1.1.5

cd myappname
npm start.

Tuesday, January 14, 2020

C# - EpiServer - Get Url To a Image


1
2
3
4
5
6
7
8
 DEFINE MODEL:

 [UIHint(UIHint.Image)]
        [Display(Name = "MainLogo",
            Description = "Main Sites Logo",
            GroupName = SystemTabNames.Content)]
        public virtual ContentReference MainLogo { get; set; }

GET:
   var urlHelper = ServiceLocator.Current.GetInstance<UrlHelper>();
    var friendlyUrl = urlHelper.ContentUrl(Model.CurrentBlock.MainLogo);

Sunday, January 12, 2020

C#, EPiserver - Get all descending pages of all types


var currentCultureInfo = new CultureInfo("no");
               
                var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
                var startPage = contentLoader.GetChildren<StartPage>(ContentReference.RootPage, currentCultureInfo).FirstOrDefault();

                ICollection<PageData> listOfPages = new List<PageData>();
                ContentReferenceExtensions.GetDescendantsOfType<PageData>(startPage, listOfPages, currentCultureInfo);

  /// <summary>
        /// Recursive GetDescendantsOfType
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="page"></param>
        /// <param name="descendants">results</param>
        /// <param name="language"></param>
        public static void GetDescendantsOfType<T>(PageData page, ICollection<T> descendants, CultureInfo language) where T : class
        {
            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
            var children = contentRepository.GetChildren<PageData>(page.ContentLink, language);
            foreach (var child in children)
            {
                if (child is T)
                {
                    descendants.Add(child as T);
                }
                GetDescendantsOfType(child, descendants, language);
            }
        }

C#, EPiserver - Page Type Criteria (200112)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  var currentCultureInfo = new CultureInfo("no");
                
                var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
                var startPage = contentLoader.GetChildren<StartPage>(ContentReference.RootPage, currentCultureInfo).FirstOrDefault();

                var ptRepo = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
                var myPage = ptRepo.Load("StandardPage").ID;
                
                PropertyCriteria pageTypeCriteria = new PropertyCriteria();
                pageTypeCriteria.Condition = EPiServer.Filters.CompareCondition.Equal;
                pageTypeCriteria.Name = "PageTypeID";
                pageTypeCriteria.Type = PropertyDataType.PageType;
                pageTypeCriteria.Value = myPage.ToString();
                PropertyCriteriaCollection criteriaCollection = new PropertyCriteriaCollection();
                criteriaCollection.Add(pageTypeCriteria);

                DescendantPages =
                    DataFactory.Instance.FindPagesWithCriteria(startPage?.PageLink, criteriaCollection)
                        .Cast<PageData>();

Friday, November 29, 2019

C# - The " ? " Operator explained

var g1 = parent?.child?.child?.child;
if (g1 != null) // TODO

Wow! This is the  equivalent of testing every single level, but in a single line of code. The “?.” operator is basically saying: 
if the object to the left is not null, then fetch what is to the right, otherwise return null and halt the access chain.