惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
腾讯CDC
Jina AI
Jina AI
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
小众软件
小众软件
M
MIT News - Artificial intelligence
MyScale Blog
MyScale Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
月光博客
月光博客
L
LangChain Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
C
Check Point Blog
U
Unit 42
人人都是产品经理
人人都是产品经理

博客园 - jerreychen

常用的JavaScript验证正则表达式 用CSS设置打印换页 使用Form认证实现用户登录 (LoginView的使用) 向容器(PlaceHolder)中动态添加多个用户控件(UserControl) C#.Net中WinForm采用Active Directory进行身份认证 Windows XP 如何设置系统自动关机任务 - jerreychen DataList嵌套GridView实现文章分类列表显示(2) visual studio 2008 sp1中如何让WebBrowser控件可编辑 - jerreychen SQLite 数据库初学 学习笔记 - jerreychen - 博客园 如何将.xsd文件自动生成对象 ASP.NET页面事件:顺序与回传详解 读取自定义的config文件 - jerreychen - 博客园 格式化数据 Net支持gzip 压缩格式 压缩与解压 .net 序列化数据对象 .net 下,日期的格式化 太久太久没来了,久违了-博客园 showModelDialog 关闭后改变GridView某个单元格的值
Umbraco 设置Document Types 的默认值
jerreychen · 2008-05-06 · via 博客园 - jerreychen

Umbraco 里面设置DocumentTypes 的时候它是没有默认值选项的
那么新建页面的时候怎么样去设置他的默认值?
DocumentType 里面 新建新的Property时候 它有个Description 让我们输入该Property的描述信息
那么现在我们就在Description里做文章了,比如:我们在Description里面输入的内容,两个'#'符号内的内容为默认值
这里我们使用Umbraco的ActionHandler接口,单当前的Action为New的时候,处理设置默认值

 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using umbraco.cms.businesslogic.web;
 5using umbraco.interfaces;
 6using System.Text.RegularExpressions;
 7using umbraco.BusinessLogic.Actions;
 8
 9namespace BetterTrades.CMS.UmbracoPlugins
10{
11    public class SetDefaultValueHandler : IActionHandler
12    {
13        IActionHandler Members
27
28        public bool Execute(Document documentObject, IAction action)
29        {
30            foreach (umbraco.cms.businesslogic.property.Property Uproperty in documentObject.getProperties)
31            {
32                if (!string.IsNullOrEmpty(Uproperty.PropertyType.Description))
33                {
34                    try
35                    {
36                        object obj = GetDefaultValue(Uproperty.PropertyType.Description);
37                        if (Uproperty.PropertyType.DataTypeDefinition.DataType.DataTypeName == "True/False (Ja/Nej)")
38                            Uproperty.Value = Convert.ToBoolean(obj);
39                        else
40                            Uproperty.Value = obj;
41                    }

42                    catch
43                    { }
44                }

45            }

46            return true;
47        }

48
49        object GetDefaultValue(string content)
50        {
51            Regex regex = new Regex(@"#(?<value>.*)#", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline);
52            Match match = regex.Match(content);
53
54            return match.Groups["value"].Value;
55        }

56
57    }

58}

59