Showing posts with label umbraco. Show all posts
Showing posts with label umbraco. Show all posts

Friday, 8 August 2014

Add new Document Type icons to Umbraco 7

The process for adding new document type icons is a little more complicated in Umbraco 7.

Document type icons are now displayed as fonts (svg/woff/eot files), the icon sets are created using Icomoon.io.

To add new icons you have to create a new set, these can then be included in Umbraco by created a new plugin.

Step 1 - Create new icon set


Go to https://icomoon.io/app, here you can load in icons from other available sets or create your own.

Select any icons you want to include in your new set.



Next, click on the "Font" button at the bottom.

In the next screen:


You'll see a list of the selected icons, take note of the values below each icon, these "code points" are used in CSS to locate each icon in the final file.

Click download and unzip.


Step 2 - Add to Umbraco


To include the new icons in Umbraoo, you have to create a new plugin to load in CSS which references the font files.

Create a new folder in "App_Plugins" for your plugin, in here create a new "package.manifest" and CSS file, next copy in the downloaded font files.

My package is called "IcoElegant", here's my layout:



Package Manifest
{
    css: [
        '~/App_Plugins/NewIcons/css/icoelegant.css'
 ]
}


Change this to reference your CSS file.

CSS
@font-face {
    font-family: 'icoelegant';
    src:url('../Fonts/icoelegant.eot');
    src:url('../Fonts/icoelegant.eot?#iefix') format('embedded-opentype'),
    url('../Fonts/icoelegant.svg') format('svg'),
    url('../Fonts/icoelegant.woff') format('woff'),
    url('../Fonts/icoelegant.ttf') format('truetype');
}


[class^="icon-icoelegant-"], [class*=" icon-icoelegant-"] {font-family:'icoelegant';width:auto;height:auto;}
.icon-icoelegant-mobile:before{content:'\e000'}
.icon-icoelegant-laptop:before{content:'\e001'}
.icon-icoelegant-desktop:before{content:'\e002'}
.icon-icoelegant-tablet:before{content:'\e003'}
.icon-icoelegant-phone:before{content:'\e004'}
.icon-icoelegant-document:before{content:'\e005'}
.icon-icoelegant-documents:before{content:'\e006'}
.icon-icoelegant-search:before{content:'\e007'}
.icon-icoelegant-clipboard:before{content:'\e008'}
.icon-icoelegant-newspaper:before{content:'\e009'}
.icon-icoelegant-notebook:before{content:'\e00a'}
.icon-icoelegant-book-open:before{content:'\e00b'}
.icon-icoelegant-browser:before{content:'\e00c'}
.icon-icoelegant-calendar:before{content:'\e00d'}
.icon-icoelegant-presentation:before{content:'\e00e'}


Change the font-family name and src attributes to match your font files.

Each icon needs a prefix (starting with ".icon"), you'll also have to swap the content value for the "code point" value when exporting from Icomoon.

Save the files and refresh Umbraco, you may have to clear the ClientDependency cache "\App_Data\TEMP\ClientDependency" first, the new icons should now be available in the Document Type section of Umbraco.

Monday, 2 June 2014

Programmatically add new member to a group in Umbraco 7

If you want to assign a new member to an Umbraco member group in .net, you have to use the "MemberService.AssignRole" method.


IMember _newMember = ApplicationContext.Current.Services.MemberService.CreateMember("username", "user@email.com", "Full Name", "Member");
Services.MemberService.Save(_newMember);
Services.MemberService.AssignRole(_newMember.Id, "Group Name");


The new member has to be saved first before you can assign it to role/group.

Thursday, 19 July 2012

Umbraco Examine - Indexing Custom XML Data

I recently ran into a problem with an Umbraco Examine indexer suddenly stopping after trying to index the first node in the content tree.

The only error information I could get was:

Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
at UmbracoExamine.UmbracoContentIndexer.OnGatheringNodeData(IndexingNodeDataEventArgs e)
at Examine.LuceneEngine.Providers.LuceneIndexer.GetDataToIndex(XElement node, String type)




I tried using NodeIndexing & GatheringNodeData handlers to find out more but all I could see was the Examine was trying to index the root node (100 in this case), then looking for Node 1 (Which didn't exist).

Eventually I found out it was due a custom data type (TheFarm - EmbeddedContent) saving content as XML.

The data was being stored as:


    
      
        Node 1 content
        Node 2 content
      
    


The problem seems to be with using "id" as an attribute as it is used in umbraco.config:

<NodeType id="100" parentID="99" level="4" ...



It appears the indexer assumes it is parsing a new node when it reads this.

There are a few options to resolve this problem:
  1. Wrap custom XML data in <![CDATA[
  2. Try using a NodeIndexing handler on the BaseIndexProvider to deal with the XML.
  3. Avoid using id as an attribute in custom XML data.
Option 3 seemed the easiest for me, I updated the  EmbeddedContent source code to use another id attribute.

Monday, 18 April 2011

Umbraco - Missing node in content tree.


I've encountered this problem a few times, a page will go missing from the Umbraco content tree but it will still display on the front end.

It doesn’t show up in the recycle bin but you can find it when you search for it by name, and when you try and open it you get the following server error:

“No Document exists with Version 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx”

It turns out to be due to data being orphaned when the database is updating, you can find out more here .

I followed the advice on the Umbraco issue tracker and deleted the last entry for the affected node in the cmsContentVersion table, it worked for me.

Tuesday, 12 April 2011

Umbraco login problem - Missing style


I recently ran into a problem when I had to update an Umbraco site that was running fine on a 2008 Server.
To be on the safe side, I took a local copy and set it up on my PC (which runs Vista).

When I tried to run the site, it would work, but none of the images or style sheets would load.  I’ve had similar problems in the past so I thought I would just log into the CMS and republish the site. When I tried this, the welcome page would not display properly either and I could not log in:



After ruling out a problem with permissions or the Client Dependancy cache I checked the request console in firebug. Every css, js and image file being requested was returning a “500 internal server error”.

Basically every request that was not for a .net page was getting a configuration error, so I checked the web.config for anything out of place. After a bit of trial and error I found removing this section fixed it:



 

The site had been setup in Windows Server 2008 and a new mime-type had been added in IIS.

This shouldn’t be a problem viewing the site on Vista as they should both be using the same version of IIS. Also, the file extension had not already been added as a global mime type.

I’m not sure if this is a problem specific to Umbraco sites running on Vista. I’ll have to try and test on a blank site to see.

Wednesday, 23 February 2011

301 Redirects for HTML files in Umbraco

When replacing an older website with a new content managed system, either the site structure or the server side technology will likely change. This can lead to problems from an SEO point of view as users searching for your site can directed to pages that no longer exist, or now have a different file extension.

The best way to deal with this is for your site to provide a "301 Redirect" whenever this happens. This will tell search engines a page has moved permanently and will preserve its ranking.
Recently I was migrating an existing classic ASP site to Umbraco and had to deal with this problem, here is my solution:

1. Install Redirect package

Luckily, there is a great package called "301 URL Tracker" that does a lot of the work, you can find it here
After installing the package I began getting "Invalid object name 'infocaster301'" server errors, I figured out the required database table hadn’t been installed.
After a quick search on the developer’s forum it turns out someone had a similar problem:
http://our.umbraco.org/projects/developer-tools/301-url-tracker/bug-reports/8974-I%27m-getting-an-Invalid-object-name-%27infocaster301%27-server-error
Unfortunately, the author’s solution was missing a declaration for the ‘IsRegex’ column in the SQL statement, here is an amended version that I got working:

CREATE TABLE infocaster301(
NodeID int NOT NULL,
OldUrl nvarchar(400) NOT NULL,
IsCustom bit NOT NULL,
IsRegex bit NOT NULL,
Message nvarchar(400) NULL,
Inserted datetime NOT NULL,
CONSTRAINT PK_infocaster301 PRIMARY KEY CLUSTERED
(
NodeID ASC,
OldUrl ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
ALTER TABLE infocaster301 ADD  CONSTRAINT DF_infocaster301_Custom  DEFAULT ((0)) FOR IsCustom
ALTER TABLE infocaster301 ADD  CONSTRAINT DF_infocaster301_Inserted  DEFAULT (getdate()) FOR Inserted

The package is great once installed; it allows you to create multiple custom URL’s , all mapping to an existing content node, just what I needed...well almost.

2. Mapping HTML and ASP

The package only seems to work for url’s with a .aspx extension, the URL’s from the old site would be a mixture of .HTML and .asp.

To fix this I had to map .HTML and .ASP extensions to run as .aspx in IIS.
There is a lot of information about this out there, a few sites that helped were:

http://our.umbraco.org/wiki/recommendations/recommended-reading-for-web-developers/urlrewriting-html-to-aspx
http://weblogs.asp.net/scottgu/archive/2007/03/04/tip-trick-integrating-asp-net-security-with-classic-asp-and-non-asp-net-urls.aspx
http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/

My new Umbraco site runs on IIS7, in integrated pipeline mode. Most of what I read suggested creating a wildcard Handler mapping in IIS to "%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll". I tried this, but whenever I viewed an HTML or ASP page in the site it would return a blank page.

I finally got it working by creating a new Managed Handler for *.html that uses the "umbraco.BasePages.BasePage" type.

This will add an entry like this to your web.config:

 

3. URL Rewriting

The next step is to create a redirect within Umbraco so .html extensions are replaced with .aspx. To do this, open /config/UrlRewriting.config and add an entry like this:
 

Now all HTML page will be recognised .net calls and can be dealt with by Umbraco and the redirect package.

4. Finally

The final job is to create a list of redirects within Umbraco. When adding a new url redirect to "301 URL Tracker" (and using this method of Handler Mapping), you will have to replace ".html" with ".aspx".
If you wanted "oldsite.com/homepage.html" to redirect to "newsite.com/home.aspx", you would have to add it as "oldsite.com/homepage.aspx".
Hope this helps, if you can think of any way to improve the solution let me know.