// GET irib/getItem/user/passwordaA1/Tasks/ public string Get(string user, string password, string id) { sharepoint shp = new sharepoint(); string str = ""; string siteUrl = shp.servername; //ClientContext clientContext = new ClientContext(siteUrl); //SP.List oList = clientContext.Web.Lists.GetByTitle(id); using (ClientContext context = new ClientContext(siteUrl)) { context.Credentials = new NetworkCredential(user, password, "mesbahsoft.local"); //SP.List oList = context.Web.Lists.GetByTitle(id); //context.ExecuteQuery(); SP.List oList = context.Web.Lists.GetByTitle(id); CamlQuery query = new CamlQuery(); query.ViewXml = @"<View> <Query> <Where> <IsNull><FieldRef Name='ParentID' /></IsNull> </Where> </Query> </View>"; ListItemCollection items = oList.GetItems(query); //ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); //ListItem oListItem = oList.AddItem(itemCreateInfo); //oListItem["Title"] = id1; //oListItem["Body"] = id2; context.Load(oList); context.ExecuteQuery(); //list.TemplateFeatureId.ToString().Equals("") && string baseType = oList.BaseType.ToString(); string listTitle = oList.Title.ToString(); if (oList.BaseType.ToString().Equals("GenericList", StringComparison.InvariantCultureIgnoreCase) && oList.Title.ToString().Equals(id, StringComparison.InvariantCultureIgnoreCase)) { foreach (Folder subFolder in oList.RootFolder.Folders) { foreach (File f in subFolder.Files) { str += f.Title.ToString(); } } } } return str; }
// GET irib/setNewItem/user/passwordaA1/Tasks/title/body/ public string Get(string user,string password,string id,string id1,string id2) { sharepoint shp = new sharepoint(); string siteUrl = shp.servername; //ClientContext clientContext = new ClientContext(siteUrl); //SP.List oList = clientContext.Web.Lists.GetByTitle(id); using (ClientContext context = new ClientContext(siteUrl)) { context.Credentials = new NetworkCredential(user, password, "mesbahsoft.local"); SP.List oList = context.Web.Lists.GetByTitle(id); //context.ExecuteQuery(); ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); ListItem oListItem = oList.AddItem(itemCreateInfo); oListItem["Title"] = id1; oListItem["Body"] = id2; oListItem.Update(); context.ExecuteQuery(); } return "task with name " + id1 + " with body " + id2 + " created"; }
// GET api/values/5 public string Get(string user, string password, string id) { sharepoint shp = new sharepoint(); string str = ""; string siteUrl = shp.servername; //ClientContext clientContext = new ClientContext(siteUrl); //SP.List oList = clientContext.Web.Lists.GetByTitle(id); using (ClientContext context = new ClientContext(siteUrl)) { context.Credentials = new NetworkCredential(user, password, "mesbahsoft.local"); SP.List oList = context.Web.Lists.GetByTitle(id); //context.ExecuteQuery(); //ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); //ListItem oListItem = oList.AddItem(itemCreateInfo); //oListItem["Title"] = id1; //oListItem["Body"] = id2; context.Load(oList); context.ExecuteQuery(); //list.TemplateFeatureId.ToString().Equals("") && string baseType = oList.BaseType.ToString(); string listTitle = oList.Title.ToString(); if (oList.BaseType.ToString().Equals("DocumentLibrary", StringComparison.InvariantCultureIgnoreCase) && oList.Title.ToString().Equals(id, StringComparison.InvariantCultureIgnoreCase)) { foreach (Folder subFolder in oList.RootFolder.Folders) { foreach (File f in subFolder.Files) { str += f.Title.ToString(); } } } } return str; }