U4-2118 - Text encoding error when saving partial view macro files

Created by Tito 16 Apr 2013, 09:57:52 Updated by Sebastiaan Janssen 19 Apr 2013, 06:55:22

When i create a partial view macro file in Umbraco 6.0.3 (with mvc rendering configured) i can not save text with accents in the file. It saves ok but it does not show right. ie. "Teléfono" in the partial view macro, and shows "Teléfono" in the web page. I remember this happened in the Umbraco 5, and it was solved, this issue was marked as a Text encoding error when saving macro file.


Sebastiaan Janssen 17 Apr 2013, 11:08:12

What do you mean "can not save text file with accents in it"? Where exactly does it go wrong? I've just tried and it seems to work fine (see screenshot).

Tito 17 Apr 2013, 12:06:16

Hi Sebastiaan, i mean writing this: "Teléfono" in a partial view macro. When i visualize the web page where the macro is in, it shows "Teléfono" instead "Teléfono" because it doesnt render the "é". It is saved ok, because i reopen the partial view macro file and it shows "Teléfono" inside umbraco backoffice. I have to write "Teléfono" to work. I have searched my email, because a similar issue happened in Umbraco 5 when editing templates, the title of that issue was "U5-459 Text encoding in file when saving the template" and the link http://issues.umbraco.org/issue/U5-459?projectKey=U5 It is not available now, but may be it can help.

Sebastiaan Janssen 17 Apr 2013, 12:15:59

Okay, I see what you mean now, it works fine until you view it on the frontend, am able to reproduce. We deleted the U5 project but I'm sure Shannon will be able to figure this one out, seems like a common issue.

Tito 17 Apr 2013, 13:55:15

If you are refering to Shannon Deminick , in my email from that post, this was his answer: "Ive chatted to Matt briefly about this and VS when saving a .cshtml template does include a BOM when saving a file. The problem is figuring out when we are saving a text file vs a binary file." I remember the team solved this issued in v5. Thanks

Sebastiaan Janssen 17 Apr 2013, 14:23:25

Thanks that helps, I had a look for the commits in V5 so we can figure out how to fix it: https://bitbucket.org/UmbracoHQ/umbraco/commits/all/tip/BOM

Tito 17 Apr 2013, 15:38:20

Perfect, will it be for next release ie. 6.0.4?

Shannon Deminick 17 Apr 2013, 16:42:24

pretty sure this will affect 4.x too for mvc views, will check.

Shannon Deminick 18 Apr 2013, 16:54:30

Have confirmed it is only for partial view macros, real strange that it doesn't do it for normal views. Will fix up.

Shannon Deminick 18 Apr 2013, 17:03:06

This is fixed in 93fa581173c7.

Turns out there is a MUCH simpler way to fix this than manually stripping out BOM bytes. If we just use

System.IO.File.WriteAllText(savePath, val, Encoding.UTF8);

it all works, this is why we didn't have problems with normal views.

using this does not work:

using (var sw = System.IO.File.CreateText(savePath)) { sw.Write(val); }

even though the default is enforcing UTF8 encoding.

Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.3

Due in version: 6.0.4


Story Points: