Pulling items from Allitems view using caml query - sharepoint

I have two views. One is Dashboard view, and next one is AllItems View. Here, Dashboard is the Default View. But i have to pull items from Allitems view using CAML Query. Can anybody tell me how to achieve this.

That is pretty basic.
Assuming you have a SPList object, you just specify the View property:
SPList list = website.Lists["Listname"];
SPView queryView = list.View["AllItems"];
queryView.Query = " ... "
queryView.Update();
There are already a lot of resources available convering this:
https://sharepoint.stackexchange.com/questions/39474/filtering-items-in-a-view-using-a-caml-query
https://sharepoint.stackexchange.com/questions/42612/how-to-set-caml-query-for-special-view
https://msdn.microsoft.com/en-us/library/ms434064(v=office.14).aspx

Related

How to get all selectlist items in razor page?

I have a select list:
[BindProperty]
public List<SelectListItem> FooList { get; set; }
The list is then instantiated as an empty list and the razor page loads. The list is then populated by the user on the client side using jquery. The server doesn't know the items in the list until the form is posted. So far, so good.
In the page I'm using the select tag helpers like so...
<select asp-for="FooList" multiple="multiple" asp-items="FooList" class="form-control form">
I'm wondering how can I retrieve all items in a mulitple selectlist "list box" (whether they're selected or not) OnPost using model binding?
I'm using razor pages 2.2 and I'm really struggling to figure this out.
public IActionResult OnPost()
{
// not sure how to get the selectlist and all of its items?
foreach (var item in FooList)
{
// do stuff with the items
}
return Page();
}
I know it's got to be something simple, just need a fresh set of eyes to point me in the right direction. Thanks!
I'm wondering how can I retrieve all items in a mulitple selectlist
"list box" (whether they're selected or not) OnPost using model
binding?
You can't. Only the values of the selected items are posted and can take part in model binding. If you want to get the selected items in a multiple select list, you need to bind them to a collection. Your asp-for attribute should reference the name of the collection that you are binding the posted values to. You should not have [BindProprty] on the List<SelectListItem> type. They only represent the items that populate the select list.
You can find out more about the basics of Select Lists in Razor Pages here.

Get list of all ids in an xPage container control

I am using this code to copy some documents by a button click source. I would like to prevent the end user from having to select columns and would prefer simply get all the documents ids from the view panel. Not exactly sure how to do that, or if a dataview might be a better choice for me.
var viewPanel=getComponent("viewPanel1"); //get the componet of viewPanel
var docIDArray=viewPanel.getSelectedIds(); //get the array of document ids
for(i=0;i < docIDArray.length;i++){
var docId=docIDArray[i];
var doc=database.getDocumentByID(docId);
var db=session.getCurrentDatabase();
var newDoc:NotesDocument=doc.copyToDatabase(db);
newDoc.replaceItemValue("approved","No");
var id=newDoc.getUniversalID();
newDoc.save(true);
}
Leave the view panel out of the equation: a view panel is a component, and components are for users to interact with; if the user's interaction with the view panel (i.e. "selecting" documents) doesn't alter which documents you wish to duplicate, ignore the view panel (at least, for the purposes of this specific event).
If you simply want to duplicate all documents that display in the view to which the view panel is bound, talk to the same data source the view panel is associated with. So, assuming your data source declaration looks something like the following:
<xp:panel>
<xp:this.data>
<xp:dominoView var="allDocuments" viewName="($All)" />
</xp:this.data>
<xp:viewPanel value="#{allDocuments}">
...
...then just iterate through that same view:
allDocuments.setAutoUpdate(false);
var eachDoc = allDocuments.getFirstDocument();
while(eachDoc) {
var newDoc = eachDoc.copyToDatabase(database);
newDoc.replaceItemValue("approved", "No");
newDoc.save();
newDoc.recycle();
var nextDoc = allDocuments.getNextDocument(eachDoc);
eachDoc.recycle();
eachDoc = nextDoc;
}
allDocuments.setAutoUpdate(true);
Since you're duplicating the documents within the same database, when the event finishes, the view panel will simply show twice as many documents, since you duplicated all of them. Unless, of course, the item value you're replacing disqualifies them from the view you're displaying.
NOTE 1: The reason the code above toggles the autoUpdate property is because, unless you toggle that to false prior to the iteration, when you duplicate each document, if the new document does display in the view you're iterating, the indexer will become aware of it, and you might end up in an infinite loop, because each time you try to get the next document, it's actually returning a handle on the duplicate you just created... so you would essentially be infinitely duplicating the same document until some exception is thrown (i.e. stack overflow, out of memory, etc.). Disabling autoUpdate prevents that by only allowing iteration of entries the index was aware of when your routine began.
NOTE 2: If the data source is only defined inside the view panel, move it to a parent (panel, Custom Control, or XPage) that also contains whatever component will trigger the duplication (i.e. button, link) and reference the data source within the view panel. That way both the view panel and the button can talk to the same data; otherwise, only the view panel is aware that the data source exists.

Infopath SharePoint Document Libraries

I need to display a list of document libraries a user has permission to on an infopath form for a workflow. I can build my list of libraries just fine but I can not for the life of me figure out how to populate (in anyway) the infopath form with the list of libraries and allow the user to somehow say "yes" or "no" to each (checkbox is ideal but I'll take anything at this point).
Basically I just need to figure out how to add a list of items for yes/no to a user in the loading event so I can take that information and do something with it.
I tend to use a repeating table with two columns, one containing a checkbox and one a label. Group these together properly in a schema then you can pop some code behind in to iterate through your list of libraries and pop nodes onto the end of this repeating table pre populated.
Here is an example that sets a label inside a repeating table on an InfoPath form:
XPathNavigator xmlDoc = MainDataSource.CreateNavigator();
XPathNavigator xmlItem = xmlDoc.SelectSingleNode("/my:MyForm/my:MyRepeatingGrp", this.NamespaceManager);
foreach (XmlNode libraryNode in documentLibraries)
{
XPathNavigator newItem = xmlItem.Clone();
XPathNavigator navText = newItem.SelectSingleNode("/my:MyLabel", this.NamespaceManager);
navText.SetValue(libraryNode.Attributes["LibraryName"].Value);
xmlItem.InsertAfter(newItem);
}
xmlItem.DeleteSelf();

Weird SPListItem URL when adding a new announcement

When I add a new item in a default Announcement list using the GUI the new item looks just as I would expect, showing the title of the item in the breadcrumb. However when adding the new item through the object model:
SPList theList = web.Lists["announcement"];
SPListItem theitem = theList.Add();
theitem["Title"] = "this is the title";
theitem.Update();
then the breadcrumb will display something like
WebTitle.ListTitle.34_.000, which I believe to be the itemID and versionnumber of the item.
A search give this but I would like to know the root cause and possible how to avoid the issue.
The issue has been resolved. Actually the list in question was a discussion list, not a announcement list ( why it was then named "announcement" is a big mystery),
Since a discussion is actually a thread container and the threads within the container, I had to call SPUtility.CreateNewDiscussion rather then list.Add.

Sharepoint default list item detail view

I have a webpart that renders random list items (from any list and list type) in a specified format. I want the items that are being displayed in the webpart to link to their ListItem detail views. However, I don't see a property on the list itself that would tell me what view is the default DETAIL view for the list (ie. blog list detail is Post.aspx). Does this come from the list definition? How would I get that information programmatically? I'm trying to avoid hard-coding any list information based on list type.
Have a look at SPList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url.
I think this is what you're looking for. You'll need to append the the SPListItem.ID on the querystring so that it knows which list item to display.
using (SPWeb myWeb = GetMyWeb()) // GetMyWeb gets a reference to a SPWeb object
{
SPList myList = GetMyList(myWeb); // GetMyList gets a reference to a SPList object
SPListItem myItem = GetMyListItem(myList); // GetMyListItem gets a reference to a SPListItem object
string url = String.Format("{0}/{1}?ID={2}",
myWeb.Url,
myList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url,
myItem.ID);
}
It's also a good practice to append &Source=/url/to/current/page to the querystring so that users will be redirected back to the page they left when they click the Cancel/Close buttons on the Edit or Display forms.

Resources