I have a problem when I need to retrieve data via REST from SharePoint 2010 list. In the returned data Attachments and user / group column is not contains data. I do not know if it's because it's collections. I have written a very simple code example and hope that there is someone who can help.
Edit 26/9-2016 since no one has answered this question, Is there someone who knows if it is possible is to get data into C# code, I can see the information I need in a Browser, but with what do I call this with (return object) , so I get data out in some kind of the structure/object?
DataServiceContext( new Uri(http://SPSite.net/sites/testsite/_vti_bin/listdata.svc/Lycklist(1)/Attachments/)
enter code here
public static class REST
{
public static LyckDataContext GetContext()
{
LyckDataContext ctx = new LyckDataContext(new Uri("http://SPSite.net/sites/testsite/_vti_bin/listdata.svc"))
{Credentials = CredentialCache.DefaultNetworkCredentials};
return ctx;
}
public static List<MyItems> GetMyList()
{
LyckDataContext ctx = GetContext();
List<MyItems> ItemList = new List<MyItems>();
var myList = (from item in ctx.Lycklist select item) as DataServiceQuery<LyckData.LycklistItem>;
// This depends on the client, if callback is needed.
// IAsyncResult res = myList.BeginExecute(GetResult, myList);
try
{
foreach (var item in myList)
{
MyItems newItem = new MyItems();
string allUsers = "";
if (item.Usersandgroups.Count > 0) // There is never any users??
{
foreach (var user in item.Usersandgroups)
{
allUsers += user.Name;
}
newItem.Users = allUsers;
}
if (item.Attachments.Count > 0) //There is also no attachment
{
foreach (var att in item.Attachments)
{
string temp = att.Name;
}
}
//There are no problems with strings
newItem.Title = item.Title;
newItem.Name = item.Mybodytekst;
ItemList.Add(newItem);
}
}
catch (Exception ex)
{ string message = ex.Message; }
return ItemList;
}
private static void GetResult(IAsyncResult result)
{
DataServiceQuery<LycklistItem> query = (DataServiceQuery<LycklistItem>)result.AsyncState;
foreach (LycklistItem Item in query.EndExecute(result))
{
//code
}
}
}
public class MyItems
{
//Democlass
public string Users { get;set; }
public string Title { get; set; }
public string Name { get; set; }
public string AttachmentsPath { get; set; }
}