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

推荐订阅源

Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
About on SuperTechFans
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Help Net Security
Help Net Security
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
O
OpenAI News
美团技术团队
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
Cyberwarzone
Cyberwarzone
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
T
Tenable Blog
S
Security Affairs
博客园_首页
S
Schneier on Security
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
Spread Privacy
Spread Privacy
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
TaoSecurity Blog
TaoSecurity Blog
博客园 - 聂微东
Vercel News
Vercel News
M
MIT News - Artificial intelligence
T
Troy Hunt's Blog
B
Blog
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 最新话题
D
DataBreaches.Net
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - Franky
W
WeLiveSecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Fortinet All Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Check Point Blog
H
Hacker News: Front Page

博客园 - 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