So, let's create our own ExpressionBuilder. I didn't implement 'language' support - obviously I need just Site and SiteCollection.
...
using System.Web.Compilation;
using Microsoft.SharePoint;
...
public class WSSUrlExpressionBuilder : ExpressionBuilder
{
public override CodeExpression GetCodeExpression
(System.Web.UI.BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
{
CodeTypeReferenceExpression thisType = new CodeTypeReferenceExpression(base.GetType());
CodePrimitiveExpression expression = new CodePrimitiveExpression(entry.Expression.Trim().ToString());
string evaluationMethod = "GetKeyValue";
return new CodeMethodInvokeExpression(thisType, evaluationMethod, new CodeExpression[] { expression });
}
public static object GetKeyValue(string expression)
{
SPWeb web = SPContext.Current.Web;
string key = "~SiteCollection";
if (expression.IndexOf(key, StringComparison.InvariantCultureIgnoreCase) == 0)
return web.Site.Url+expression.Substring(key.Length);
key = "~Site";
if (expression.IndexOf(key, StringComparison.InvariantCultureIgnoreCase) == 0)
return web.Url+ expression.Substring(key.Length);
return expression;
}
}
...
You need to put this class to some assembly and register it with your prefix(e.g. WSSUrl) in Web.Config
<configuration>
<system.web>
<compilation>
<expressionBuilders>
<add expressionPrefix="WSSUrl"
type="{your Namespace}.WSSUrlExpressionBuilder,{Assembly Name}"/>
</expressionBuilders>
</compilation>
</system.web>
</configuration>
Assembly Name should be fully qualified if you put the assembly into GAC.
You forgot one thing
ReplyDelete..
using System.CodeDom;
...
1. I can't modify web.config correctly.
ReplyDelete{your Namespace} & {Assembly Name} what is this?
2. In what place/module/file is correct to put the public class WSSUrlExpressionBuilder : ExpressionBuilder?