Created
January 9, 2015 14:40
-
-
Save Zimmergren/40ab41e4fe84ed583505 to your computer and use it in GitHub Desktop.
Program.cs sample for Azure WebJob targeting Office 365 SharePoint sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
try | |
{ | |
Console.WriteLine("Initiating Main()"); | |
using (ClientContext context = new ClientContext("https://redacted.sharepoint.com")) | |
{ | |
Console.WriteLine("New ClientContext('https://redacted.sharepoint.com') opened. "); | |
context.AuthenticationMode = ClientAuthenticationMode.Default; | |
context.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword()); | |
Console.WriteLine("Authentication Mode and Credentials set"); | |
List translationlist = context.Web.Lists.GetByTitle("Automatic Translations"); | |
context.Load(translationlist); | |
context.ExecuteQuery(); | |
Console.WriteLine("TranslationList fetched, loaded and ExecuteQuery'ed"); | |
if (translationlist != null && translationlist.ItemCount > 0) | |
{ | |
Console.WriteLine("The list exist, let's do some magic"); | |
CamlQuery camlQuery = new CamlQuery(); | |
camlQuery.ViewXml = | |
@"<View> | |
<Query> | |
<Where><Eq><FieldRef Name='IsTranslated' /><Value Type='Boolean'>0</Value></Eq></Where> | |
</Query> | |
</View>"; | |
ListItemCollection listItems = translationlist.GetItems(camlQuery); | |
context.Load(listItems); | |
context.ExecuteQuery(); | |
Console.WriteLine("Query for listItems executed."); | |
foreach (ListItem item in listItems) | |
{ | |
item["Output"] = TranslatorHelper.GetTranslation(item["Title"], item["Target Language"], item["Original Language"]); | |
item["IsTranslated"] = true; | |
item.Update(); | |
} | |
context.ExecuteQuery(); | |
Console.WriteLine("Updated all the list items we found. Carry on..."); | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("ERROR: " + ex.Message); | |
Console.WriteLine("ERROR: " + ex.Source); | |
Console.WriteLine("ERROR: " + ex.StackTrace); | |
Console.WriteLine("ERROR: " + ex.InnerException); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment