Caml Help


public static class SharePointHelpExtension
{
/// <summary>
/// 获取链接地址的Url传参
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
public static NameValueCollection GetQueryString(this Uri uri)
{
return HttpUtility.ParseQueryString(uri.Query);
}

/// <summary>
/// 获取链接地址的Url传参
/// </summary>
/// <param name="uri"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public static NameValueCollection GetQueryString(this Uri uri, Encoding encoding)
{
return HttpUtility.ParseQueryString(uri.Query, encoding);
}

/// <summary>
/// 获取当前页面的命称
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
public static string GetPageName(this Uri uri)
{
if (uri.Segments.Length > 0)
{
return uri.Segments[uri.Segments.Length - 1];
}
else
{
return "";
}
}
/// <summary>
/// 创建一个新的列表
/// </summary>
/// <param name="web"></param>
/// <param name="templateName"></param>
/// <param name="url"></param>
/// <param name="title"></param>
/// <param name="description"></param>
public static void CreateList(this SPWeb web, string templateName, string url, string title, string description)
{
SPListTemplate template = web.ListTemplates[templateName];
Guid listId = web.Lists.Add(url, description, template);
SPList list = web.Lists[listId];
list.OnQuickLaunch = true;
list.Title = title;
list.Update();
}

/// <summary>
/// 超过长度截断字符串,并在后面加...
/// </summary>
/// <param name="input"></param>
/// <param name="len"></param>
/// <returns></returns>
public static string SubStringByLength(this string input, int len)
{
return SharePointHelp.SubStringByLength(input, len);
}
/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void OrCamlAnd(this XElement where, XElement newNode)
{
if (where.HasElements)
{
XElement and = new XElement("Or", where.FirstNode, newNode);
where.RemoveAll();
where.Add(and);
}
else
{
where.Add(newNode);
}
}

/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void OrCamlAnd(this XElement where, string operators, string fieldName, string value, string valueType)
{
XElement el = new XElement(operators
, new XElement("FieldRef", new XAttribute("Name", fieldName))
, new XElement("Value", new XAttribute("Type", valueType), value));
where.OrCamlAnd(el);
}


/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void AddCamlAnd(this XElement where, XElement newNode)
{
if (where.HasElements)
{
XElement and = new XElement("And", where.FirstNode, newNode);
where.RemoveAll();
where.Add(and);
}
else
{
where.Add(newNode);
}
}

/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void AddCamlAnd(this XElement where, string operators, string fieldName, string value, string valueType)
{
XElement el = new XElement(operators
, new XElement("FieldRef", new XAttribute("Name", fieldName))
, new XElement("Value", new XAttribute("Type", valueType), value));
where.AddCamlAnd(el);
}

/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void AddCamlAnd(this XElement where, string operators, string fieldName, string value)
{
where.AddCamlAnd(operators, fieldName, value, "Text");
}

/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void AddCamlAnd(this XElement where, string operators, Guid fieldId, string value, string valueType)
{
XElement el = new XElement(operators
, new XElement("FieldRef", new XAttribute("ID", fieldId))
, new XElement("Value", new XAttribute("Type", valueType), value));
where.AddCamlAnd(el);
}

/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void AddCamlAnd(this XElement where, string operators, Guid fieldId, string value)
{
where.AddCamlAnd(operators, fieldId, value, "Text");
}
/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void AddCamlAnd(this XElement where, string operators, Guid fieldId)
{
XElement el = new XElement(operators
, new XElement("FieldRef", new XAttribute("ID", fieldId)));
where.AddCamlAnd(el);
}
/// <summary>
/// 为Where添加一个与原有条件And关系的条件
/// </summary>
/// <param name="where"></param>
/// <param name="newNode"></param>
public static void AddCamlAnd(this XElement where, string operators, string fieldName)
{
XElement el = new XElement(operators
, new XElement("FieldRef", new XAttribute("Name", fieldName)));
where.AddCamlAnd(el);
}

/// <summary>
/// 创建一个条件
/// </summary>
/// <param name="where"></param>
/// <param name="operators"></param>
/// <param name="fieldId"></param>
/// <param name="value"></param>
/// <param name="valueType"></param>
/// <returns></returns>
public static XElement BuildCamlCondition(this XElement where, string operators, Guid fieldId, string value, string valueType)
{
XElement el = new XElement(operators
, new XElement("FieldRef", new XAttribute("ID", fieldId))
, new XElement("Value", new XAttribute("Type", valueType), value));
return el;
}
/// <summary>
/// 创建一个条件
/// </summary>
/// <param name="where"></param>
/// <param name="operators"></param>
/// <param name="fieldName"></param>
/// <param name="value"></param>
/// <param name="valueType"></param>
/// <returns></returns>
public static XElement BuildCamlCondition(this XElement where, string operators, string fieldName, string value, string valueType)
{
XElement el = new XElement(operators
, new XElement("FieldRef", new XAttribute("Name", fieldName))
, new XElement("Value", new XAttribute("Type", valueType), value));
return el;
}
}

你可能感兴趣的:(Caml Help)