15 янв. 2013 г.

SharePoint 2010 доступ к спискам.

Задача:
Рассылка писем из SharePoint 2010 который находиться в DMZ зоне.

Решение:
Обратиться с удаленной машины в определенный

список где находятся письма, прочитать, разослать и проставить статус об отправки.


            // Starting with ClientContext, the constructor requires a URL to the
            // server running SharePoint.
            ClientContext context = new ClientContext("http://your_dom");

            context.Credentials = new System.Net.NetworkCredential("login", "pasword");

            // Assume the web has a list named "Announcements".
            List announcementsList = context.Web.Lists.GetByTitle("name_list");

            // This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
            // so that it grabs all list items, regardless of the folder they are in.
            CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
            ListItemCollection items = announcementsList.GetItems(query);

            // Retrieve all items in the ListItemCollection from List.GetItems(Query).
            context.Load(items);
            context.ExecuteQuery();
            foreach (ListItem listItem in items)
            {
                if (listItem["status"].ToString() == "Не отправлено")
                {
                    SendMail(FromGlob, listItem["Title"].ToString(), listItem["tema"].ToString(), listItem["text"].ToString());
                    Console.WriteLine("Письмо для: " + listItem["Title"].ToString() + ", с темой: " + listItem["tema"].ToString() + " успешно отправлено.");
                    listItem["status"] = "Отправлено";
                    listItem.Update();
                    context.ExecuteQuery();
                }
            }

Комментариев нет:

Отправить комментарий