I'm trying to access all documents of the same collection that have a specific field value.
var docs = await CrossCloudFirestore.Current
.Instance
.Collection("myCollcetion")
.WhereEqualsTo("field", variable)
.GetAsync();
I tried to run foreach for the docs but it doesn't work. How do I access each document in order to get the values of other fileds in them?
Based on Jason's suggestion foreach should be run for docs.Documents.
Related
i followed this tutorial for setting up an upload/download to/from sql database.
http://dotnetawesome.blogspot.co.uk/2013/11/how-to-upload-and-download-files-tofrom.html
It works just fine. But i want to modify the populate method so that it will only populate files where the fileid exists within a list that i've stored in session state.
The problem is i've looked around and i can't make any sense of the lambda expressions or work out how to do this.
Basically, i keep a list of the fileIDs in the session, (which is renewed on first page load) so it will only show the files uploaded for that form submission. (it's a claim form)
using (Portal_Entities dc = new Portal_Entities()) {
List<WEBSITE_ATTACHMENTS> allFiles = dc.WEBSITE_ATTACHMENTS.ToList()
rptAttachments.DataSource = allFiles;
rptAttachments.DataBind();
}
I'm guessing i need to put a .Where or .Select on the .ToList here, but i'm not sure.
Like i need a sql type statement where field in ('value','value') where there values come from the list in the session.
Can anyone help?
You could try this one:
// Get the list of ints called fileIDs that you have stored in session.
List<int> ids = (List<int>)Session["fileIDs"];
// Declare an enumeration in which only the WEBSITE_ATTACHMENTS
// with an in contained in ids, will be contained.
List<WEBSITE_ATTACHMENTS> allFiles = dc.WEBSITE_ATTACHMENTS
.Where(x=>ids.Contains(x.fileId));
I'm trying to search for some values in my Azure SQL Database. As i understand, the data returns in a object of type List, but i dont know how to read this query and pass the values to variables.
This is my code:
List<TodoItem> items = await todoTable
.Where(todoItem => todoItem.Text != null)
.ToListAsync();
MessageBox.Show(items.ToString());
This way, it will run a query for data that contains the "Text" field different then null.
But how can i read this list with the query data to store these values?
Running this code, i got the following:
Microsoft.WindowsAzure.MobileServices.TotalCountList'1[Project.TodoItem]
So, how is the easiest way to read this values, and store them into variables so i can work with this data?
Thanks a lot, friends.
You are calling .ToString() on your list. This won't give the results you expect.
Try the following, which should tell you haw many results you get back from your query.
MessageBox.Show(items.Count.ToString());
You should find this matches the number of records, then you can loop through the list contents to get at the results you want.
I would like to know how can I check the existence of two objects with mongoDB and C#.
I know how to do it for 1 object:
foreach (BsonDocument item in collection.Find(Query.Exists("Boiling point")))
But i have no idea how to check on two objects.
Thanks!
You can use Query.And to search more than one condition.
foreach (BsonDocument item in collection.Find(
Query.And(
Query.Exists("Boiling point"),
Query.Exists("Freezing Point")))
A complete list is available in the online documentation here.
I have a few generic questions about what are the best practices for SharePoint(2010).
I am currently implementing a feature that requires me to fetch information from a list. I am not quite sure on how to manage these information. I created a class that helps me manage theses information (User.cs). I have a getter in the class that currently searches for a value in a specific list. How should i handle the value ? Should i keep it in a member and refresh only when its subject to changes or should i refresh the value from the list each time i get it ?
private void doesUserHasActivities(){
using(SPSite site = new SPSite("http://vmsharepoint2010/")){
using(SPWeb web = site.openWeb("http://vmsharepoint2010/")){
SPList list = web.list["Users"];
SPListItem user;
/*Information values is refresh each time its accessed, is this bad ?*/
for(int i=0; i < list.items.length; i++){
user = list.item[i];
string accName = user["Acc_Name"];
if(accName == this.providedAccountname){//providedAccountname from a TextBox
//found the user i wanted into the list
//look if the list has data
bool hasActivities = user["Activities"] != null;
}
}
}
}
}
Also, is there other ways to access specific data, in this case the activities list without looping through each rows trying to match the correct user and then looking up the values in the activities list ?
Can i store the row itself as a member for my meta data ? Will my reference still point to the row of the user list i want to if another user is added ?
You'll need to learn CAML and perform a CAML query.
Create an SPQuery object. Set it's Query property to be what you need it to be, then use list.getItems(SPQuery query) to get just the items that match your query.
You can figure out the CAML for it yourself; you'll need to learn it if you want to deal with SharePoint code at all. There is lots of information on basic syntax, and tools for helping auto-generate it based on more user friendly syntax.
The items won't update dynamically when items are added to the list or updated in the list; you will need to re-run the query.
can anyone show me how to get the users within a certain group using sharepoint?
so i have a list that contains users and or groups. i want to retrieve all users in that list. is there a way to differentiate between whether the list item is a group or user. if its a group, i need to get all the users within that group.
im using c#, and im trying to do thins by making it a console application.
im new to sharepoint and im really jumping into the deep end of the pool here, any help would be highly appreciated.
cheers..
The first thing you need to know is that when you have a list with a User / Group field you must be aware of its type. When you have one user or group within the item value, the field type is SPFieldUserValue. However, if the field has multiple user / group selection the field type is SPFieldUserValueCollection.
I'll assume that your field allows a single user / group selection and you already has the following objects:
SPSite site;
SPWeb web;
SPListItem item;
Now, we'll check the field value for a user / group and retrieve a list of users, independant of which kind it is (the field's name is "Users").
SPFieldUserValue usersField = new SPFieldUserValue(mainWeb, item["Users"].ToString());
bool isUser = SPUtility.IsLoginValid(site, usersField.User.LoginName);
List<SPUser> users = new List<SPUser>();
if (isUser)
{
// add a single user to the list
users.Add(usersField.User);
}
else
{
SPGroup group = web.Groups.GetByID(usersField.LookupId);
foreach (SPUser user in group.Users)
{
// add all the group users to the list
users.Add(user.User);
}
}
I hope it helps you.
Tks,
Pedro José Batista
note: an SPUser object can also be an AD Group (that is to say, an SPUser object might exist for "DOMAIN\Domain Users"... which is why the SPUser object also contains the property IsDomainGroup.
From this information you can start to traverse through AD groups using the SPPrincipalInfo objects... however it's not always pleasant.
One thing worth keeping in mind is that the SPGroup object includes the ContainsCurrentUser property which can traverse AD groups... this assumes you've got an SPGroup object to work from, however.
Enjoy.
-Scott
private bool IsMember()
{
bool isMember;
SPSite site = new SPSite(SiteURL);
SPWeb web = site.OpenWeb();
isMember = web.IsCurrentUserMemberOfGroup(web.Groups["GroupName"].ID);
web.Close();
site.Close();
return isMember;
}
This is better to use web.SiteGroups instead of web.Groups as a group might be inherited by that site.