Пример #1
0
        public IEnumerable <BusinessDocumentViewModel> MyBusinessDocuments()
        {
            using (var clientContext = WebAPIHelper.GetClientContext(this.ControllerContext))
            {
                // Get the documents from the Business Documents library
                List businessDocsLib = clientContext.Web.GetListByUrl("/BusinessDocs");
                var  camlQuery       = new CamlQuery
                {
                    ViewXml = $@"<View><Query><Where>
    <Eq>
        <FieldRef Name='{InChargeField}' LookupId='TRUE' />
        <Value Type = 'Integer'><UserID /></Value>
     </Eq>
 </Where></Query></View>"
                };
                ListItemCollection businessDocItems = businessDocsLib.GetItems(camlQuery);

                clientContext.Load(businessDocItems, items => items.Include(
                                       item => item.Id,
                                       item => item[FileLeafRefField],
                                       item => item[InChargeField],
                                       item => item[DocumentPurposeField]));
                clientContext.ExecuteQuery();

                // Create collection of view models from list item collection
                List <BusinessDocumentViewModel> viewModels = businessDocItems.Select(ListItemToViewModel).ToList();

                return(viewModels);
            }
        }
Пример #2
0
        public JsonResult GetMyEmployeesVacationRequests()
        {
            List <VacationRequest> vacationRequests = null;

            var      spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
            Employee employee  = GetEmployee(spContext);

            using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
            {
                if (clientContext != null)
                {
                    List      vacationRequestList = clientContext.Web.Lists.GetByTitle("Vacation Requests");
                    CamlQuery query = new CamlQuery();
                    query.ViewXml = String.Format(
                        "<View>" +
                        "<Query>" +
                        "<Where>" +
                        "<Eq>" +
                        "<FieldRef Name=\"Approver\" />" +
                        "<Value Type=\"Text\">{0}</Value>" +
                        "</Eq>" +
                        "</Where>" +
                        "</Query>" +
                        "<ViewFields>" +

                        "<FieldRef Name=\"StartDate\" />" +
                        "<FieldRef Name=\"_EndDate\" />" +
                        "<FieldRef Name=\"RequestBy\" />" +
                        "<FieldRef Name=\"Approver\" />" +
                        "<FieldRef Name=\"_Status\" />" +
                        "</ViewFields>" +
                        "<RowLimit>100</RowLimit>" +
                        "</View>",
                        employee.Name);

                    ListItemCollection vacationRequestItems = vacationRequestList.GetItems(query);
                    clientContext.Load(vacationRequestItems);
                    clientContext.ExecuteQuery();

                    vacationRequests = vacationRequestItems
                                       .Select(vacationRequest => new VacationRequest()
                    {
                        ID        = ((int)vacationRequest["ID"]),
                        StartDate = ((DateTime)vacationRequest["StartDate"]),
                        EndDate   = (DateTime)vacationRequest["_EndDate"],
                        RequestBy = vacationRequest["RequestBy"].ToString(),
                        Approver  = vacationRequest["Approver"].ToString(),
                        Status    = vacationRequest["_Status"].ToString()
                    }).ToList();
                }
            }

            return(Json(vacationRequests, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        private List <ProgressResult> ProcessDevelopmentData(ListItemCollection data)
        {
            List <ProgressResult> result = new List <ProgressResult>();

            if (data != null)
            {
                result = data.Select(s => new ProgressResult()
                {
                    Title = ((string)s.FieldValues["Title"]), Priority = ((string)s.FieldValues["Priority"]), Error = ((string)s.FieldValues["Error"])
                }).ToList();
            }
            return(result);
        }
Пример #4
0
        private List <ProgressResult> ProcessMarketingData(ListItemCollection data)
        {
            List <ProgressResult> result = new List <ProgressResult>();

            if (data != null)
            {
                result = data.Select(s => new ProgressResult()
                {
                    Title = ((string)s.FieldValues["Title"]), Priority = ((string)s.FieldValues["Priority"]), Request = ((string)s.FieldValues["Request"])
                }).ToList();
            }
            return(result);
        }
Пример #5
0
        //gavdcodeend 26

        //gavdcodebegin 27
        static void SpCsCsomReadAllFolders(ClientContext spCtx)
        {
            List myList = spCtx.Web.Lists.GetByTitle("TestList");
            ListItemCollection allItems = myList.GetItems(CamlQuery.CreateAllFoldersQuery());

            spCtx.Load(allItems, itms => itms.Include(itm => itm.Folder));

            spCtx.ExecuteQuery();

            List <Folder> allFolders = allItems.Select(itm => itm.Folder).ToList();

            foreach (Folder oneFolder in allFolders)
            {
                Console.WriteLine(oneFolder.Name + " - " + oneFolder.ServerRelativeUrl);
            }
        }
Пример #6
0
        public string FindUsersByName(string searchTermName)
        {
            string users = string.Empty;

            Token token = new Mongo().Get <Token>("ContextTokens", "UserName", this._userName);

            using (ClientContext context = TokenHelper.GetClientContextWithContextToken(_siteUri, token.ContextToken, "localhost:44331"))
            {
                CamlQuery query = new CamlQuery();
                query.ViewXml = $"<View><Query><Where><Contains><FieldRef Name='Title' /><Value Type='Text'>{searchTermName}</Value></Contains></Where></Query></View>";
                ListItemCollection peopleDetails = context.Web.Lists.GetByTitle("PeopleDetails").GetItems(query);
                context.Load(peopleDetails);
                context.ExecuteQuery();

                users = string.Join("<br>", peopleDetails.Select(x => x["Title"] + "(" + x["ContactNumber"] + "),"));
            }
            return(users);
        }
Пример #7
0
        public List <Microsoft.SharePoint.Client.File> ListFiles(string libraryName, string folderName)
        {
            var docLib    = ClientContext.Web.Lists.GetByTitle(libraryName);
            var camlQuery = new CamlQuery();

            camlQuery.ViewXml = @"<View Scope='Recursive'>
                                    <Query>
                                    </Query>
                                </View>";
            string folderUrl = string.Format("/{0}/{1}", libraryName, folderName);

            camlQuery.FolderServerRelativeUrl = folderUrl;
            ListItemCollection listItems = docLib.GetItems(camlQuery);

            ClientContext.Load(listItems);
            ClientContext.ExecuteQuery();
            return(listItems.Select(a => a.File).ToList());
        }
Пример #8
0
        public async Task <IEnumerable <Announcement> > GetAnnouncements()
        {
            ClientContext context = await GetClientContext(ConfigurationManager.AppSettings["OperationsWebsite"]);

            context.Load(context.Web);
            context.Load(context.Web.Lists);
            context.ExecuteQuery();

            List list = context.Web.Lists.Where(l => l.Title == "Announcements").FirstOrDefault();
            ListItemCollection listItems = list.GetItems(CamlQuery.CreateAllItemsQuery());

            context.Load(listItems);
            context.ExecuteQuery();

            return(listItems.Select(l => new Announcement()
            {
                Title = l["Title"].ToString(), Timestamp = DateTime.Parse(l["Created"].ToString())
            }));
        }
Пример #9
0
        // GET: api/BusinessDocuments
        public IEnumerable <BusinessDocumentViewModel> Get()
        {
            using (var clientContext = WebAPIHelper.GetClientContext(this.ControllerContext))
            {
                // Get the documents from the Business Documents library
                List businessDocsLib = clientContext.Web.GetListByUrl("/BusinessDocs");
                ListItemCollection businessDocItems = businessDocsLib.GetItems(CamlQuery.CreateAllItemsQuery());

                clientContext.Load(businessDocItems, items => items.Include(
                                       item => item.Id,
                                       item => item[FileLeafRefField],
                                       item => item[InChargeField],
                                       item => item[DocumentPurposeField]));
                clientContext.ExecuteQuery();

                // Create collection of view models from list item collection
                List <BusinessDocumentViewModel> viewModels = businessDocItems.Select(ListItemToViewModel).ToList();

                return(viewModels);
            }
        }
Пример #10
0
        public IEnumerable <string> GetFilmsBySuperhero(int superheroId)
        {
            CamlQuery camlQuery = new CamlQuery();

            camlQuery.ViewXml = $@"<View>
                                    <Query>
                                        <Where>
                                            <Eq>
                                                <FieldRef Name='SuperheroId'/>
                                                <Value Type='Number'>{superheroId}</Value>
                                            </Eq>
                                        </Where>
                                    </Query>
                                    </View>";

            ListItemCollection filmsuperheroes = website.Lists.GetByTitle("FilmSuperheroes").GetItems(camlQuery);

            clientContext.Load(filmsuperheroes);
            clientContext.ExecuteQuery();

            List <int> filmIds = filmsuperheroes
                                 //.Where(f => Convert.ToInt32(f["SuperheroId"]) == superheroId)
                                 .Select(fs => Convert.ToInt32(fs["Title"]))
                                 .ToList();

            ListItemCollection films = website.Lists.GetByTitle("Films").GetItems(CamlQuery.CreateAllItemsQuery());

            clientContext.Load(films);
            clientContext.ExecuteQuery();

            List <string> result = films.Where(f => filmIds.Any(id => Convert.ToInt32(f.Id) == id))
                                   .Select(a => a["Title"].ToString())
                                   .ToList();

            return(result);
        }
Пример #11
0
        // This function will be triggered based on the schedule you have set for this WebJob
        public static void VerifyDocLib()
        {
            var url  = ConfigurationManager.AppSettings["SpUrl"].ToString();
            var user = ConfigurationManager.AppSettings["SpUserName"].ToString();
            var pw   = ConfigurationManager.AppSettings["SpPassword"].ToString();

            using (PnPMonitoredScope p = new PnPMonitoredScope())
            {
                p.LogInfo("Gathering connect info from web.config");
                p.LogInfo("SharePoint url is " + url);
                p.LogInfo("SharePoint user is " + user);
                try
                {
                    ClientContext cc = new ClientContext(url);
                    cc.AuthenticationMode = ClientAuthenticationMode.Default;
                    cc.Credentials        = new SharePointOnlineCredentials(user, GetPassword(pw));
                    using (cc)
                    {
                        if (cc != null)
                        {
                            string listName = "Site Pages";
                            p.LogInfo("This is what a Monitored Scope log entry looks like in PNP, more to come as we try to validate a lists existence.");
                            p.LogInfo("Connect to Sharepoint");
                            ListCollection     lists   = cc.Web.Lists;
                            IEnumerable <List> results = cc.LoadQuery <List>(lists.Where(lst => lst.Title == listName));
                            p.LogInfo("Executing query to find the Site Pages library");
                            cc.ExecuteQuery();
                            p.LogInfo("Query Executed successfully.");
                            List list = results.FirstOrDefault();
                            if (list == null)
                            {
                                p.LogError("Site Pages library not found.");
                            }
                            else
                            {
                                p.LogInfo("Site Pages library found.");

                                ListItemCollection items = list.GetItems(new CamlQuery());
                                cc.Load(items, itms => itms.Include(item => item.DisplayName));
                                cc.ExecuteQueryRetry();
                                string pgs = "These pages were found, " + string.Join(", ", items.Select(x => x.DisplayName));
                                p.LogInfo(pgs);
                            }
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    p.LogInfo("We had a problem: " + ex.Message);
                }
            }
        }
Пример #12
0
        public FileResult Index(Guid?Id)
        {
            if (Id == null)
            {
                return(AccessDenied());
            }

            RemoteCalendarAccessManager manager = new RemoteCalendarAccessManager();

            BLM.RemoteCalendarAccess remoteCalendarAccess = manager.GetRemoteCalendarAccess(Id.Value);

            if (remoteCalendarAccess == null)
            {
                return(AccessDenied());
            }

            AzureActiveDirectory azureAD = new AzureActiveDirectory();

            IUser user = null;

            try
            {
                user = azureAD.GetUser(remoteCalendarAccess.UserId).Result;
            }
            catch (AggregateException e)
            {
                if (!e.InnerExceptions.Any(i => i.Message == "User " + remoteCalendarAccess.UserId + " not found."))
                {
                    throw;
                }
            }

            if (user == null || user.AccountEnabled == false)
            {
                return(AccessDenied());
            }

            manager.UpdateLastAccessTime(remoteCalendarAccess);

            Uri           uri           = new Uri(remoteCalendarAccess.SiteAddress);
            string        realm         = TokenHelper.GetRealmFromTargetUrl(uri);
            var           token         = TokenHelper.GetAppOnlyAccessToken("00000003-0000-0ff1-ce00-000000000000", uri.Authority, realm);
            ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(uri.ToString(), token.AccessToken);

            clientContext.Load(clientContext.Web.Lists);
            clientContext.ExecuteQuery();

            List list = clientContext.Web.Lists.Where(l => l.Id == remoteCalendarAccess.CalendarId).First();

            if (list == null)
            {
                return(AccessDenied());
            }

            ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());

            clientContext.Load(items);

            clientContext.Load(clientContext.Web);
            clientContext.Load(clientContext.Web.RegionalSettings);
            clientContext.Load(clientContext.Web.RegionalSettings.TimeZone);
            clientContext.Load(clientContext.Web, w => w.Title);

            clientContext.ExecuteQuery();

            Calendar calendar = new Calendar();

            calendar.Title    = clientContext.Web.Title + " - " + list.Title;
            calendar.Timezone = Timezone.Parse(clientContext.Web.RegionalSettings.TimeZone.Description);
            calendar.Events   = items.Select(i => Event.Parse(i)).ToList <Event>();

            FileContentResult result = File(System.Text.Encoding.Default.GetBytes(calendar.ToString()), "text/calendar", "calendar.ics");

            return(result);
        }
 public IList <SharepointFileTransfer.SharePoint.Importer.Domain.User> GetUsers()
 {
     using (ClientContext clientContext = new ClientContext(this.m_url))
     {
         ListItemCollection items = clientContext.Web.SiteUserInfoList.GetItems(new CamlQuery()
         {
             ViewXml = "<View/>"
         });
         clientContext.Load <ListItemCollection>(items, new Expression <Func <ListItemCollection, object> > [0]);
         clientContext.ExecuteQuery();
         return((IList <SharepointFileTransfer.SharePoint.Importer.Domain.User>)items.Select <ListItem, SharepointFileTransfer.SharePoint.Importer.Domain.User>((Expression <Func <ListItem, SharepointFileTransfer.SharePoint.Importer.Domain.User> >)(user => new SharepointFileTransfer.SharePoint.Importer.Domain.User()
         {
             Id = Convert.ToInt32(user["ID"]),
             Name = user["Name"].ToString()
         })).ToList <SharepointFileTransfer.SharePoint.Importer.Domain.User>());
     }
 }