Tuesday, May 31, 2016

C# Recursive Method Call Example

Problem to solve. We need to calculate:
4! = 4*3*2*1 = 24
This can be done with a reverse for loop like this:

 public double calcfactor(int number)  
     {  
       if (number == 0) return 1;  
       double factorial = 1;  
       for(int i = number; i>=1; i--)  
       {  
         Console.WriteLine(factorial = factorial*i);  
       }  
       return factorial;  
     }  

But it can also be solved like this with a recursive method call:

4! = 4* (4-1) *(4-2)*(4-3) = 24

But be careful to break out of the loop with some condition.

 public double calcfactor(int number)  
     {  
       if (number == 0) return 1;  
       return number * calcfactor(number - 1);  
     }  

Tuesday, May 17, 2016


EPiserver.Url Class Looks like this:

{/link/a7c7ae76a093403183be1ffcf2c52857.aspx}
    Authority: ""
    DnsSafeHost: ""
    Encoding: {System.Text.UTF8Encoding}
    Fragment: ""
    Host: ""
    IsAbsoluteUri: false
    IsRelative: true
    LocalPath: ""
    OriginalString: "/link/a7c7ae76a093403183be1ffcf2c52857.aspx"
    Path: "/link/a7c7ae76a093403183be1ffcf2c52857.aspx"
    PathAndQuery: "/link/a7c7ae76a093403183be1ffcf2c52857.aspx"
    Port: -1
    Query: ""
    QueryCollection: {EPiServer.Url.ReadOnlyNameValueCollection}
    Scheme: ""
    Segments: {string[3]}
    Split: {string[3]}
    Uri: {/link/a7c7ae76a093403183be1ffcf2c52857.aspx}
    UriInternal: {http://localhost/link/a7c7ae76a093403183be1ffcf2c52857.aspx}
    UserEscaped: false
    UserInfo: ""
}

To get External url:


    public static string GetExternalUrl(this PageData p)  
     {  
       UrlBuilder pageUrlBuilder = new UrlBuilder(p.LinkURL);  
       Global.UrlRewriteProvider.ConvertToExternal(pageUrlBuilder, p.PageLink, UTF8Encoding.UTF8);  
       string pageURL = pageUrlBuilder.ToString();  
       UriBuilder uriBuilder = new UriBuilder(EPiServer.Web.SiteDefinition.Current.SiteUrl);  
       uriBuilder.Path = pageURL;  
       return uriBuilder.Uri.AbsoluteUri;  
     }  

Wednesday, May 11, 2016

EPiServer - Basic Get Pages Content and blocks



Loading multiple instances

It is also possible to load several content instances at the same time by calling 
GetItems<T> where T : IContentData 
(corresponds to GetPages in previous versions). Below is an example on GetItems:
IEnumerable<ContentReference> references = GetSomeReferences();
IEnumerable<IContent> items = Locate.ContentRepository()
.GetItems<IContent>(references, LanguageSelector.AutoDetect());



Very useful article:
http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2012/8/EPiServer7-Working-with-IContentRepositoryDataFactory/

Tuesday, May 10, 2016

MSSQL - Cannot Save backup to other SQL Server Instance with Management Studio

The user that is running is MSSQLSERVER.
But to be able to add this user to Security you probably need to type:
NT SERVICE\MSSQLSERVER for the server the backup is going to be saved on and add correct permissions.