Quien alguna vez no necesito traer información de los
distintos subsite desde un site
collection, no? Bueno les presento a la class “SPSiteDataQuery”.
Les voy a dejar un ejemplo muy práctico de donde vamos a obtener
valores de todas las lista cuyo templete sea el que determinemos, en nuestro
caso “ServerTemplate=100” que representa listas genéricas.
Para
hacer el ejemplo un poco más interesante al siguiente método le vamos a agregar
dos parámetros [string Col, string Val] esto nos va a permitir tener un filtro
determinando la columna y el valor a filtrar de dicha columna.
[METODO]
private string GetContentList(string Col, string Val)
{
StringBuilder Result = new StringBuilder();
try
{
SPWeb web = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
//Ask for all lists created from the announcement template.
query.Lists = "";
// Get the Title field. Define here all you need.
query.ViewFields = "";
query.ViewFields += "";
query.ViewFields += "";
// Set the sort order. Content Type
query.Query =
"" +
"" +
"" +
"" + Val + " " +
" " +
" ";
// Query all Web sites in this site collection.
query.Webs = "";
DataTable dt = web.GetSiteData(query);
string tem = string.Empty;
Result.Append("");
foreach (DataRow item in dt.Rows)
{
if (tem == string.Empty)
{
tem = item["ListProperty.title"].ToString();
Result.Append("");
Result.Append("");
Result.Append("");
}
if (tem != item["ListProperty.title"].ToString())
{
Result.Append("");
Result.Append("");
Result.Append("");
tem = item["ListProperty.title"].ToString();
}
else
{
Result.Append("");
Result.Append("");
Result.Append("");
Result.Append("");
}
}
Result.Append("
" + " Nombre de la Lista: " + item["ListProperty.title"].ToString() + " | Nombre del SubSite:" + item["ProjectProperty.title"].ToString() + "
" + " Nombre de la Lista: " + item["ListProperty.title"].ToString() + " | Nombre del SubSite:" + item["ProjectProperty.title"].ToString() + "
" + item["Title"].ToString() + "
");
web.AllowUnsafeUpdates = false;
return Result.ToString();
}
catch (SPException)
{
throw;
}
}
[COMO USAR EL METODO]
protected void btoFiltrar_Click(object sender, EventArgs e)
{
ContentNoticias.InnerHtml = GetContentList(txtCol.Text, txtVal.Text);
ContentNoticias.InnerHtml += "
";
}
Comentarios
Publicar un comentario