/// <summary> /// submit an async job to translate folder(s) /// </summary> /// <param name="culture">target langauge</param> /// <param name="inputFolder">Full URL of the input folder on SharePoint</param> /// <param name="outputFolder">Full URL of the output folder on SharePoint</param> static void AddAsyncFolder(string culture, string inputFolder, string outputFolder) { SPServiceContext sc = SPServiceContext.GetContext(new SPSite(site)); TranslationJob job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture)); using (SPSite siteIn = new SPSite(inputFolder)) { Console.WriteLine("In site: {0}", siteIn); using (SPWeb webIn = siteIn.OpenWeb()) { Console.WriteLine("In web: {0}", webIn); using (SPSite siteOut = new SPSite(outputFolder)) { Console.WriteLine("Out site: {0}", siteOut); using (SPWeb webOut = siteOut.OpenWeb()) { Console.WriteLine("Out web: {0}", webOut); SPFolder folderIn = webIn.GetFolder(inputFolder); SPFolder folderOut = webOut.GetFolder(outputFolder); Console.WriteLine("Input: " + folderIn); Console.WriteLine("Output: " + folderOut); //true means to recursive all the sub folders job.AddFolder(folderIn, folderOut, true); Console.WriteLine("Submitting the job"); job.Start(); ListJobItemInfo(job); } } } } }
private void asyncFolder_Click(object sender, RoutedEventArgs e) { CreateClientContext(); Folder folderIn = cc.Web.GetFolderByServerRelativeUrl(this.inputFile.Text); Folder folderOut = cc.Web.GetFolderByServerRelativeUrl(this.outputFile.Text); TranslationJob job = new TranslationJob(cc, this.culture.Text); job.AddFolder(folderIn, folderOut, true); job.Start(); cc.Load(job); ThreadPool.QueueUserWorkItem(new WaitCallback(CreateThreadForAsync), job); }
static void AsyncFolder(string culture, string inFolder, string outFolder, string name) { Folder folderIn = cc.Web.GetFolderByServerRelativeUrl(inFolder); Folder folderOut = cc.Web.GetFolderByServerRelativeUrl(outFolder); TranslationJob job = new TranslationJob(cc, culture); job.AddFolder(folderIn, folderOut, true); job.Name = name; job.Start(); cc.Load(job); cc.ExecuteQuery(); Console.WriteLine("JobId: " + job.JobId); Console.WriteLine("JobName: " + job.Name); Console.WriteLine("Done"); }
public ActionResult Library() { try { Uri hostWebUri = new Uri(Request.QueryString["SPHostUrl"]); Uri appWebUri = new Uri(Request.QueryString["SPAppWebUrl"]); string listId = Request.QueryString["SPListId"]; string listItemId = Request.QueryString["SPListItemId"]; string culture = string.Empty; string destination = string.Empty; List <Setting> settings = new List <Setting>(); //Get the settings using (ClientContext ctx = TokenHelper.GetS2SClientContextWithWindowsIdentity(appWebUri, Request.LogonUserIdentity)) { List settingsList = ctx.Web.Lists.GetByTitle("Settings"); ctx.Load(settingsList); ListItemCollection settingItems = settingsList.GetItems(CamlQuery.CreateAllItemsQuery()); ctx.Load(settingItems); ctx.ExecuteQuery(); foreach (ListItem settingItem in settingItems) { settings.Add(new Setting() { Title = settingItem["Title"].ToString(), Value = settingItem["Value"].ToString(), }); } } culture = settings.Where <Setting>(s => s.Title == "Culture").FirstOrDefault().Value; destination = settings.Where <Setting>(s => s.Title == "Destination").FirstOrDefault().Value; //Translate library asynchronously using (ClientContext ctx = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWebUri, Request.LogonUserIdentity)) { //Get library to translate Folder rootFolder = ctx.Web.Lists.GetById(new Guid(listId)).RootFolder; ctx.Load(rootFolder, f => f.ServerRelativeUrl); //Get destination library Folder destinationFolder = ctx.Web.Lists.GetByTitle(destination).RootFolder; ctx.Load(destinationFolder, f => f.ServerRelativeUrl); ctx.ExecuteQuery(); TranslationJob job = new TranslationJob(ctx, culture); job.AddFolder(rootFolder, destinationFolder, true); job.Name = "LibraryTranslation"; job.Start(); ctx.Load(job); ctx.ExecuteQuery(); string returnPath = hostWebUri.Scheme + "://" + hostWebUri.Authority + ":" + hostWebUri.Port + destinationFolder.ServerRelativeUrl; ViewBag.ReturnPath = returnPath; ViewBag.Message = "The translation job has been scheduled."; } } catch (Exception x) { ViewBag.Message = x.Message; } return(View()); }