EPiServer 7.5 – Klipp och klistra

Nedan följer några bra klipp och klistra kodsnuttar för EPiServer 7.5.

1
2
3
4
/*  Tvinga användaren att endast kunna välja en viss sidtyp som ContentReference */
[Display(GroupName = SystemTabNames.Content, Order = 400)]
[AllowedTypes(typeof(ProducerPage))]
public virtual ContentReference ProducerPage { get; set; }

Ladda ner jättestora filer

Ibland kan det vara svårt att via webbläsaren kunna hämta jättestora filer. Nedan finner du en kodsnutt hur detta kan göras via asp.net c# kod istället.

 

//Kom åt filen bakom ”fejkad” SSL
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

WebClient webClient = new WebClient();

//ange URL till källan och till lokala mappen
webClient.DownloadFile(”https://xxx.com/xml/test.xml”, @”C:\Temp\test.xml”);

 

Force restore on MsSql database

No exclusive access to database

No exclusive access to database

You’re trying to restore a database in SQL Server Management Studion using the UI and you get an error message

Exclusive access cound not be obtained because the database is in use.

This means that some process is still using the database and can therefore not be altered. There is no way getting around this using the UI. The only way to force the restore of the database is to use an SQL query.

In the query we start by setting the database in single user mode – now the database can only be accessed by one user/process at time. When this is done we can alter the database anyway we like. Don’t forget to add WITH REPLACE at the end of the query in order to force a replace on the database. You can find an example below.

1
2
3
4
5
6
7
USE master
GO
ALTER DATABASE databasename SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE databasename FROM DISK = 'D:\data\SQL\Backup\databasename.bak'
WITH REPLACE
GO

Custom dropdown property in EPiServer 7

This is how to create a custom dropdown property in EPiServer 7.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[ContentType(GUID = "GUIDHERE")]
public class MyPage : CustomBase
{
    [Display(GroupName = SystemTabNames.Content, Order = 40)]
    [UIHint("CustomLanguage")]
    public virtual string LanguageSelector { get; set; }
}

public class LanguageSelectorSelectionFactory : ISelectionFactory
{
    public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
    {
        var typeOfLanguage = new List<SelectItem>
        {
            new SelectItem() {Value = "sv", Text = "svenska"},
            new SelectItem() {Value = "en", Text = "engelska"},
            new SelectItem() {Value = "fi", Text = "finska"}
        };
   
        return typeOfLanguage;
    }
}

[EditorDescriptorRegistration(TargetType = typeof(string), UIHint = "CustomLanguage")]
public class LanguageMultipleEditorDescriptor : EditorDescriptor {
    public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
    {
        SelectionFactoryType = typeof(LanguageSelectorSelectionFactory);
        ClientEditingClass = "epi.cms.contentediting.editors.SelectionEditor";
        base.ModifyMetadata(metadata, attributes);
    }
}

More information on Linus Ekströms blog.

JavaScript error in EPiServer 7 Filemanager

Every time when accessing EPiServer 7 Filemanager I got two Javascript error that stated:

Timestamp: 2013-05-16 16:41:08
Error: SyntaxError: unterminated string literal
Sourcecodefile: http://local/ui/CMS/admin/FileManagement.aspx
Row: 482, column: 13
Sourcecode: wdoc.write( ’<script type=”text/javascript”>var NREUMQ=NREUMQ||[];NREUMQ

Timestamp: 2013-05-16 16:41:08
Error: ReferenceError: SetupContextMenuHandler is not defined
Sourcecodefile: http://local/ui/CMS/admin/FileManagement.aspx
row: 1016

Also the editmode looks messed up:

EPiServer 7 Filemanager error

EPiServer 7 Filemanager error

After contacting the EPiServer operations I got the solution from them. They asked me to update the file DhtmlSupport.aspx in C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Application\UI\CMS\Hosting folder with this code

1
2
//Change:
wdoc.write(';');

//To:
wdoc.write(’<bo’+’dy>’);

Regex exempel

E-postadress (epostadress@doman.com): @^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$ Svenskt mobilnummer (070-1234567): @”^[0]{1}[7]{1}[0,2,3,6,9]{1}-[0-9]{7}$” Svenskt personnummer (ååååmmdd-nnnn): @”^[12]{1}[90]{1}[0-9]{6}-[0-9]{4}$”

WordPress klipp och klistra

Nedan finner du några bra snippets för WordPress. 12//Hämta bild url <img src="<?php echo get_template_directory_uri();?>/images/logo.png" alt="Logo">

Komplett metadata?

Jag har försökt saxa ihop en komplett lista på metadata som ska finnas på alla moderna webbplatser. 12345678910111213141516<meta name="description" content="" /> <link rel="author" href="https://plus.google.com/[din kod]/" /> <!– Open Graph metadata –> <meta property="og:title" content="" /> <meta property="og:type" content="[website/article]" /> <meta property="og:image" content="" /> <meta property="og:url" content="" /> <meta property="og:description" content="" /> <!– Twitter –> <meta […]

Aktivera cachning av blobs i EPiServer

Lägg till följande i web.config för att aktivera cachningen av alla mediafiler som kommer från EPiServer (Blobs). 123456<configuration>     <configSections>         <section name="staticFile" type="EPiServer.Framework.Configuration.StaticFileSection" />     </configSections> </configuration> <staticFile expirationTime="365.0:0:0" />

EPiServer 7.5 – Klipp och klistra

Nedan följer några bra klipp och klistra kodsnuttar för EPiServer 7.5. 1234/*  Tvinga användaren att endast kunna välja en viss sidtyp som ContentReference */ [Display(GroupName = SystemTabNames.Content, Order = 400)] [AllowedTypes(typeof(ProducerPage))] public virtual ContentReference ProducerPage { get; set; }