本文整理汇总了C#中SPQuery类的典型用法代码示例。如果您正苦于以下问题:C# SPQuery类的具体用法?C# SPQuery怎么用?C# SPQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SPQuery类属于命名空间,在下文中一共展示了SPQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadSiteSkin
void LoadSiteSkin( )
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedsiteColl = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb elevatedWeb = elevatedsiteColl.OpenWeb(SPContext.Current.Web.ID))
{
SPQuery qry = new SPQuery();
qry.Query = "<Where><Contains><FieldRef Name='FileLeafRef'/><Value Type='Text'>" +
".temp.html</Value></Contains></Where>";
//try opening the file
SPList xList = elevatedWeb.GetCatalog(SPListTemplateType.MasterPageCatalog);
if (xList == null) return;
SPListItemCollection xItems = xList.GetItems(qry);
if ((xItems != null) && (xItems.Count > 0))
{
foreach (SPListItem item in xItems)
{
string html = Encoding.UTF8.GetString(item.File.OpenBinary());
ParserHtmlTemplate(html);
}
}
}
}
});
}
示例2: BatchDeleteItems
public static void BatchDeleteItems(string listName, SPQuery query)
{
// Set up the variables to be used.
StringBuilder methodBuilder = new StringBuilder();
string batch = string.Empty;
string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Batch onError=\"Return\">{0}</Batch>";
string methodFormat = "<Method ID=\"{0}\">" +
"<SetList Scope=\"Request\">{1}</SetList>" +
"<SetVar Name=\"ID\">{2}</SetVar>" +
"<SetVar Name=\"Cmd\">Delete</SetVar>" +
"</Method>";
// Get the list containing the items to update.
SPList list = WorkFlowUtil.GetWorkflowList(listName);
// Query to get the unprocessed items.
SPListItemCollection unprocessedItems = list.GetItems(query);
// Build the CAML delete commands.
foreach (SPListItem item in unprocessedItems)
{
methodBuilder.AppendFormat(methodFormat, "1", item.ParentList.ID, item.ID.ToString());
}
// Put the pieces together.
batch = string.Format(batchFormat, methodBuilder.ToString());
// Process the batch of commands.
string batchReturn = SPContext.Current.Web.ProcessBatchData(batch.ToString());
}
示例3: BindDropDownList
protected void BindDropDownList()
{
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (var adminSite = new SPSite(CurrentWeb.Site.ID))
{
using (var adminWeb = adminSite.OpenWeb(CurrentWeb.ID))
{
try
{
adminWeb.AllowUnsafeUpdates = true;
SPList iconLink = Utilities.GetCustomListByUrl(adminWeb, ListsName.InternalName.WebsiteLink);
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy>";
SPListItemCollection items = iconLink.GetItems(query);
DataTable dt = items.GetDataTable();
if (dt != null && dt.Rows.Count > 0)
{
lbWebURL.DataSource = dt;
lbWebURL.DataTextField = FieldsName.WebsiteLink.InternalName.Title;
lbWebURL.DataValueField = FieldsName.WebsiteLink.InternalName.WebURL;
lbWebURL.DataBind();
}
//lbWebURL.Items.Insert(0, new ListItem("--Liên kết website--", string.Empty));
lbWebURL.Attributes.Add("onclick", string.Format("RedirectURL('{0}')", lbWebURL.ClientID));
}
catch (SPException ex)
{
Utilities.LogToULS(ex);
}
}
}
});
}
示例4: Execute
// Executes the expression tree that is passed to it.
internal static object Execute(SPList list, Expression expression, bool isEnumerable)
{
// The expression must represent a query over the data source.
if (!IsQueryOverDataSource(expression))
throw new InvalidProgramException("No query over the data source was specified.");
var caml = (new CamlTranslator()).Translate(null, expression);
var query = new SPQuery();
var viewFieldsXml = caml.Element(Tags.ViewFields);
var rowLimitXml = caml.Element(Tags.RowLimit);
var queryXml = caml.Elements()
.Where(n => n.Name != Tags.ViewFields && n.Name != Tags.RowLimit)
.ToList();
query.Query = (new XElement(Tags.Query, queryXml)).Value;
if (viewFieldsXml != null)
{
query.ViewFields = viewFieldsXml.Value;
query.ViewFieldsOnly = true;
}
if (rowLimitXml != null)
{
query.RowLimit = (int)rowLimitXml.Value;
}
return list.GetItems(query);
}
示例5: CreateChildControls
protected override void CreateChildControls()
{
return;
SPQuery query = new SPQuery();
// supports less than 130,000 records
// query.Query = "<Where><Eq><FieldRef Name='_x804c__x4f4d_'/><Value Type='Text'>J</Value></Eq></Where>";
query.Query = "<Where><And><Eq><FieldRef Name='_x6027__x522b_'/><Value Type='Text'>男</Value></Eq><Eq><FieldRef Name='_x804c__x4f4d_'/><Value Type='Text'>J</Value></Eq></And></Where>";
SPWeb web = SPContext.Current.Web;
PortalSiteMapProvider ps = PortalSiteMapProvider.WebSiteMapProvider;
PortalWebSiteMapNode psNode = (PortalWebSiteMapNode)ps.FindSiteMapNode(web.ServerRelativeUrl);
if (psNode != null)
{
Stopwatch timer = new Stopwatch();
timer.Start();
SiteMapNodeCollection items = ps.GetCachedListItemsByQuery(psNode, "人物列表", query, web);
StringBuilder sb = new StringBuilder();
foreach (PortalListItemSiteMapNode item in items)
{
sb.Append(item["性别"]);
sb.Append(",");
}
timer.Stop();
sb.Append("<hr>");
sb.Append(string.Format("{0:N}",timer.Elapsed.Ticks / 10m));
LiteralControl lc = new LiteralControl();
lc.Text = sb.ToString();
this.Controls.Add(lc);
}
}
示例6: Build
public SPQuery Build()
{
SPQuery spQuery = new SPQuery();
StringBuilder queryBuilder = new StringBuilder("<Where>");
if (filters.Count > 1)
{
queryBuilder.Append("<And>");
}
foreach (CAMLFilter filter in this.filters)
{
queryBuilder.Append(filter.FilterExpression);
}
if (filters.Count > 1)
{
queryBuilder.Append("</And>");
}
queryBuilder.Append("</Where>");
spQuery.Query = queryBuilder.ToString();
return spQuery;
}
示例7: CheckandAddEntry
public static void CheckandAddEntry(SPList configurationList, Guid ProjectGuid, Project Project_Svc)
{
try
{
// Checking whether the project id is already available.
var query = new SPQuery
{
Query =
@"<Where><Eq><FieldRef Name='" + ProjectUIDFieldName + "' /><Value Type='Text'>" + ProjectGuid.ToString() + "</Value></Eq></Where>"
};
var ProjectItemCollection = configurationList.GetItems(query);
if (ProjectItemCollection.Count == 0)
{
configurationList.ParentWeb.Site.RootWeb.AllowUnsafeUpdates = true;
SPListItem item = configurationList.Items.Add();
//first project name
item["Title"] = Project_Svc.GetProjectNameFromProjectUid(ProjectGuid, DataStoreEnum.WorkingStore);
item[GroupFieldName] = DefaultGroupValue;
item[ProjectUIDFieldName] = ProjectGuid.ToString();
item.Update();
configurationList.ParentWeb.Site.RootWeb.Update();
}
}
catch (Exception ex)
{
ErrorLog("Error at adding configuration item to the list due to " + ex.Message, EventLogEntryType.Error);
}
}
示例8: GetPendingFiles
public void GetPendingFiles()
{
SPListItemCollection items = null;
using (SPSite site = new SPSite("http://kamlesh-lt:2013"))
{
using (SPWeb web = site.OpenWeb())
{
try
{
SPList list = web.Lists["BulkUpload"];
fldErrorLogs = web.Folders["ErrorLogs"];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name=\"Status\" /><Value Type=\"Choice\">Pending</Value></Eq></Where>";
query.ViewAttributes = "Scope='Recursive'";
items = list.GetItems(query);
for (int i = 0; i < items.Count; i++)
{
this.ProcessFile(items[i]);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
示例9: isUnique
//string sTitle, string sAssignedTo)//sTitle, sAssignedTo
/// <summary>
/// 检测list里是否存在重复的task记录
/// </summary>
/// <param name="splCompletedTasks"></param>
/// <param name="id"></param>
/// <returns></returns>
public static bool isUnique(SPList splCompletedTasks,string id)
{
SPQuery query = new SPQuery();
query.Query = string.Format(@"
<Where>
<Eq>
<FieldRef Name='TaskID' />
<Value Type='Text'>{0}</Value>
</Eq>
</Where>", id);
// query.Query = string.Format(@" <Where>
// <And>
// <Eq>
// <FieldRef Name='AssignedTo' />
// <Value Type='User'>{0}</Value>
// </Eq>
// <Contains>
// <FieldRef Name='Title' />
// <Value Type='Text'>{1}</Value>
// </Contains>
// </And>
// </Where>",sAssignedTo,sTitle);
int iCount = splCompletedTasks.GetItems(query).Count;
if (iCount > 0)
{
return false;
}
else
{
return true;
}
}
示例10: GetNewsRecords
public DataTable GetNewsRecords(string query)
{
DataTable table = new DataTable();
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (var site = new SPSite(SPContext.Current.Web.Site.ID))
{
using (var web = site.OpenWeb(SPContext.Current.Web.ID))
{
try
{
SPQuery spQuery = new SPQuery
{
Query = query
};
SPList list = Utilities.GetDocListFromUrl(web, ListsName.English.ImageCatList);
if (list != null)
{
SPListItemCollection items = list.GetItems(spQuery);
table = items.GetDataTable();
}
}
catch (Exception ex)
{
table = null;
}
}
}
});
return table;
}
示例11: GetByName
public Customer GetByName(string name)
{
var web = SPContext.Current.Web;
var list = web.Lists[ListName];
var query = new SPQuery();
query.Query = @"
<Where>
<Eq><FieldRef Name='Title' />
<Value Type='Text'>" + name + @"</Value>
</Eq>
</Where>";
query.RowLimit = 1;
var results = list.GetItems(query);
if (results.Count == 0)
{
return null;
}
var item = results.Cast<SPListItem>().First();
return new Customer
{
Name = item.Title,
CustomerId = item.ID
};
}
示例12: CheckDuplicate
/// <summary>
/// Checks the duplicate.
/// </summary>
/// <param name="siteURL">The site URL.</param>
/// <param name="value">The value.</param>
/// <param name="columnName">Name of the column.</param>
/// <param name="listName">Name of the list.</param>
/// <returns>bool</returns>
internal bool CheckDuplicate(string siteURL, string value, string columnName, string listName)
{
bool blnIsValueExist = false;
SPList list;
SPQuery query;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
list = web.Lists[listName];
query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='" + columnName + "' /><Value Type='Text'>" + value + "</Value></Eq></Where>";
if (list.GetItems(query).Count > 0)
{
blnIsValueExist = true;
}
}
}
});
return blnIsValueExist;
}
示例13: BindRepeater
protected void BindRepeater()
{
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (var adminSite = new SPSite(CurrentWeb.Site.ID))
{
using (var adminWeb = adminSite.OpenWeb(CurrentWeb.ID))
{
try
{
adminWeb.AllowUnsafeUpdates = true;
SPList list = Utilities.GetCustomListByUrl(adminWeb, ListsName.InternalName.DocumentsList);
SPQuery query = new SPQuery();
query.Query="<OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy>";
query.RowLimit = 10;
SPListItemCollection items = list.GetItems(query);
if (items!=null&&items.Count>0)
{
rptDocument.DataSource = items.GetDataTable();
rptDocument.DataBind();
}
}
catch (Exception ex)
{
Utilities.LogToULS(ex);
}
}
}
});
}
示例14: btnSearch_Click
protected void btnSearch_Click(object sender, EventArgs e)
{
SPQuery qry = new SPQuery();
SPWeb rootWeb = Site.RootWeb;
SPList list = rootWeb.Lists["Articles"];
CamlQuery caml = new CamlQuery();
SPQuery articleQuery = new SPQuery();
articleQuery.Query = CAML.Where(
CAML.Contains(
CAML.FieldRef("Title"),
CAML.Value(txtTitleSearch.Text)));
//articleQuery.ViewFields = CAML.ViewFields(CAML.FieldRef("Title"), CAML.FieldRef("Modified By"));
//articleQuery.ViewFields = string.Concat(
// "<FieldRef Name='Title' />",
// "<FieldRef Name='Modified' />");
//articleQuery.ViewFieldsOnly = true;
//articleQuery.ViewFields = "<ViewFields><FieldRef Name=\"Title\"/></ViewFields>";
SPListItemCollection col;
if (txtTitleSearch.Text.Length == 0)
{
col = list.Items;
}
else
{
col = list.GetItems(articleQuery);
}
ViewState["AtricleSearchResults"] = col.GetDataTable();
gvResult.DataSource = col.GetDataTable();
gvResult.DataBind();
}
示例15: FillData
void FillData()
{
string curLoginName = SPContext.Current.Web.CurrentUser.LoginName;
string swhere = @"<Where><Eq><FieldRef Name='userLoginName'/><Value Type='Text'>{0}</Value></Eq></Where>";
SPQuery query = new SPQuery();
query.Query = String.Format(swhere, curLoginName);
SPListItemCollection coll = SPContext.Current.Site.RootWeb.Lists["QuickNavigator"].GetItems(query);
int count = coll.Count;
for (int i = 0; i < 5; i++)
{
TextBox txtTitle = (TextBox)psetup.FindControl("txtTitle" + i.ToString());
TextBox txtValue = (TextBox)psetup.FindControl("txtValue" + i.ToString());
Label lblNav = (Label)psetup.FindControl("nav" + i.ToString());
int num = i + 1;
var prefix = "<p>0" + num + "</p>";
if (i >= count)
{
txtTitle.Text = "";
txtValue.Text = "";
lblNav.Text = prefix;
}
else
{
txtTitle.Text = coll[i]["Title"] + "";
txtValue.Text = coll[i]["ValueCell"] + "";
lblNav.Text = "<a href=\"" + txtValue.Text + "\" target=\"_blank\">" + prefix + "<h1>" + txtTitle.Text + "</h1></a>";
}
}
}