private static void AddAppointmentEventToSpCalendar(Appointment a) { string siteUrl = "http://sp16.geek-ish.com", calendarName /*listName*/ = "Calendar1" /*"Customers"*/; string[] listFields = new string[] { "ID", "Title", "Start Time", "End Time" /*"FirstName", "LastName", "City", "State", "Body" */ }; string camlXml = "<View><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='Start Time'/><FieldRef Name='Title'/>'FirstName'/><FieldRef Name='LastName'/><FieldRef Name='City'/><FieldRef Name='State'/><FieldRef Name='Body'/>*/</ViewFields></View>"; camlXml = "<View><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='EventDate'/><FieldRef Name='EndDate'/></ViewFields></View>"; System.Net.NetworkCredential creds = new System.Net.NetworkCredential("*****@*****.**", "helloWorld55!"); Microsoft.SharePoint.Client.ClientContext ctx = new Microsoft.SharePoint.Client.ClientContext(siteUrl) { Credentials = creds }; Microsoft.SharePoint.Client.ListItemCollection lic = GetSpListItems(ctx, siteUrl, calendarName, camlXml); Microsoft.SharePoint.Client.ListItemCreationInformation lici = new Microsoft.SharePoint.Client.ListItemCreationInformation(); Microsoft.SharePoint.Client.List list = ctx.Web.Lists.GetByTitle(calendarName); Microsoft.SharePoint.Client.ListItem li = list.AddItem(lici); //string[] trainerName = a.Trainer.Split(new char[] { ',' }); //string trainer = string.Format("{0}. {1}", trainerName[1].Trim().Substring(0, 1), trainerName[0].Trim()); //string apptTime = a.StartDateTime.ToString("hh:mm tt"); li["Title"] = a.Title; /*string.Format("{0} {1}", trainer, apptTime);*/ //"Added " + DateTime.Now.ToString(); li["County"] = a.County; /*"New Castle";*/ li["CountyId"] = a.CountyId; /*1;*/ li["Trainer"] = a.Trainer; /*"Fish, Harry";*/ //li["TrainerId"] = 90; li["EventDate"] = a.StartDateTime; li["EndDate"] = a.EndDateTime; /*new DateTime(a.StartDateTime.Ticks + 3600000);*/ li.Update(); ctx.ExecuteQuery(); }
public async Task <DataTable> getAllJobs() { Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath); spJobsite = Convert.ToString(config.AppSettings.Settings["SharePointJobSite"].Value); O365UserName = Convert.ToString(config.AppSettings.Settings["O365UserName"].Value); joblistName = Convert.ToString(config.AppSettings.Settings["jobListName"].Value); string tempString = config.AppSettings.Settings["O365Password"].Value; O365Password = new SecureString(); foreach (char c in tempString) { O365Password.AppendChar(c); } using (Microsoft.SharePoint.Client.ClientContext context = new Microsoft.SharePoint.Client.ClientContext(spJobsite)) { try { context.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(O365UserName, O365Password); context.Load(context.Web, w => w.Title); context.ExecuteQuery(); Microsoft.SharePoint.Client.List list = context.Web.Lists.GetByTitle(joblistName); context.Load(list); Microsoft.SharePoint.Client.ListItemCollection listitems = list.GetItems(Microsoft.SharePoint.Client.CamlQuery.CreateAllItemsQuery()); context.Load(listitems); context.ExecuteQuery(); DataTable dt = new DataTable(); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("JobNumber", typeof(string)); dt.Columns.Add("SiteUrl", typeof(string)); dt.Columns.Add("ProjectType", typeof(string)); foreach (Microsoft.SharePoint.Client.ListItem item in listitems) { DataRow row = dt.NewRow(); row["Name"] = item["JobNumber"] + " - " + item["Title"]; row["JobNumber"] = item["JobNumber"]; Microsoft.SharePoint.Client.FieldUrlValue _url = (Microsoft.SharePoint.Client.FieldUrlValue)item["JobSiteUrl"]; row["SiteUrl"] = _url.Url; row["ProjectType"] = item["ProjectCategory"]; dt.Rows.Add(row); } dt.TableName = "JobSiteInfo"; await Task.Delay(1000); return(dt); } catch (Exception ex) { return(null); } } }
public static void Initialize(TestContext testContext) { fieldName = $"Field{Guid.NewGuid()}"; var listResults = TestScope.ExecuteCommand("Get-PnPList"); if (listResults.Count > 0) { list = listResults[0].BaseObject as Microsoft.SharePoint.Client.List; } }
static Microsoft.SharePoint.Client.ListItemCollection GetSpListItems(Microsoft.SharePoint.Client.ClientContext ctx, string siteUrl, string listName, string camlXml)//string[] listFields) { Microsoft.SharePoint.Client.List list = ctx.Web.Lists.GetByTitle(listName); Microsoft.SharePoint.Client.CamlQuery camlQuery = new Microsoft.SharePoint.Client.CamlQuery() { ViewXml = camlXml }; Microsoft.SharePoint.Client.ListItemCollection lic = list.GetItems(camlQuery); ctx.Load(lic); ctx.ExecuteQuery(); return(lic); }
public static void Initialize(TestContext testContext) { fieldName = $"Field{Guid.NewGuid()}"; var listResults = TestScope.ExecuteCommand("Get-PnPList"); if (listResults.Count > 0) { list = listResults[0].BaseObject as Microsoft.SharePoint.Client.List; } TestScope.ExecuteCommand("Add-PnPField", new CommandParameter("DisplayName", fieldName), new CommandParameter("InternalName", fieldName), new CommandParameter("Type", Microsoft.SharePoint.Client.FieldType.Text)); TestScope.ExecuteCommand("Add-PnPField", new CommandParameter("List", list.Title), new CommandParameter("DisplayName", $"{fieldName}2"), new CommandParameter("InternalName", $"{fieldName}2"), new CommandParameter("Type", Microsoft.SharePoint.Client.FieldType.Text)); }
/// <summary> /// Initializes the new instance of <see cref="SPClient.SPClientViewParentPipeBind"/> class. /// </summary> /// <param name="list">the list which contains views.</param> public SPClientViewParentPipeBind(Microsoft.SharePoint.Client.List list) { this.ClientObject = list; }
protected void CreateDocumentLink_Click(object sender, EventArgs e) { FileStream fs = null; try { // When the user has selected a library, they will be allowed to click the button // The first thing we'll do is get the target library and its root folder. targetLibrary = hostingWeb.Lists.GetByTitle(OutputLibrary.SelectedItem.Text); Microsoft.SharePoint.Client.Folder destintationFolder = targetLibrary.RootFolder; clientContext.Load(destintationFolder); clientContext.ExecuteQuery(); // Then we'll build a Word Document by using OOXML // Note that we'll first create it in a folder in this Web app. using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(Server.MapPath("~/SampleOOXML/LocalOOXMLDocument.docx"), WordprocessingDocumentType.Document)) { // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); // Create the document structure. mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); // Create a paragraph. Paragraph para = body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); run.AppendChild(new Text("Here's some text in a paragraph")); // Create a table. DocumentFormat.OpenXml.Wordprocessing.Table table = new DocumentFormat.OpenXml.Wordprocessing.Table(); // Create some table border settings. TableProperties borderProperties = new TableProperties( new TableBorders( new TopBorder { Val = new EnumValue <BorderValues>(BorderValues.DashDotStroked), Size = 12 }, new BottomBorder { Val = new EnumValue <BorderValues>(BorderValues.DashDotStroked), Size = 12 }, new LeftBorder { Val = new EnumValue <BorderValues>(BorderValues.DashDotStroked), Size = 12 }, new RightBorder { Val = new EnumValue <BorderValues>(BorderValues.DashDotStroked), Size = 12 }, new InsideHorizontalBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 12 }, new InsideVerticalBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 12 })); // Add the table border settings to the table. table.AppendChild <TableProperties>(borderProperties); // Create a table row and add two cells with some text var tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow(); var tc1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(); tc1.Append(new Paragraph(new Run(new Text("Here's some text in table cell #1")))); var tc2 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(); tc2.Append(new Paragraph(new Run(new Text("Here's some text in table cell #2")))); tr.Append(tc1); tr.Append(tc2); // Add the row to the table, and the table to the body of the document. table.Append(tr); body.Append(table); } // At this stage, the local file has been created in the folder of this Web project // so we'll now read it and create a new file in SharePoint, based on this local file. byte[] documentBytes; fs = File.OpenRead(Server.MapPath("~/SampleOOXML/LocalOOXMLDocument.docx")); documentBytes = new byte[fs.Length]; fs.Read(documentBytes, 0, Convert.ToInt32(fs.Length)); // At this stage, the file contents of the OOXML document has been read into the byte array // so we can use that as the content of a new file in SharePoint. Microsoft.SharePoint.Client.FileCreationInformation ooxmlFile = new Microsoft.SharePoint.Client.FileCreationInformation(); ooxmlFile.Overwrite = true; ooxmlFile.Url = hostingWeb.Url + destintationFolder.ServerRelativeUrl + "/SharePointOOXMLDocument.docx"; ooxmlFile.Content = documentBytes; Microsoft.SharePoint.Client.File newFile = targetLibrary.RootFolder.Files.Add(ooxmlFile); clientContext.Load(newFile); clientContext.ExecuteQuery(); // Let the user navigate to the document library where the file has been created string targetUrl = hostingWeb.Url + destintationFolder.ServerRelativeUrl; DocumentLink.Text = "Document has been created in SharePoint! Click here to view the library"; DocumentLink.Visible = true; DocumentLink.NavigateUrl = targetUrl; } catch (Exception ex) { // Tell the user what went wrong DocumentLink.Text = "An error has occurred: " + ex.Message; DocumentLink.Visible = true; DocumentLink.NavigateUrl = ""; } finally { // Clean up our filestream object fs.Close(); } }
protected void CreateDocumentLink_Click(object sender, EventArgs e) { FileStream fs = null; try { // When the user has selected a library, they will be allowed to click the button // The first thing we'll do is get the target library and its root folder. targetLibrary = hostingWeb.Lists.GetByTitle(OutputLibrary.SelectedItem.Text); Microsoft.SharePoint.Client.Folder destintationFolder = targetLibrary.RootFolder; clientContext.Load(destintationFolder); clientContext.ExecuteQuery(); // Then we'll build a Word Document by using OOXML // Note that we'll first create it in a folder in this Web app. using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(Server.MapPath("~/SampleOOXML/LocalOOXMLDocument.docx"), WordprocessingDocumentType.Document)) { // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); // Create the document structure. mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); // Create a paragraph. Paragraph para = body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); run.AppendChild(new Text("Here's some text in a paragraph")); // Create a table. DocumentFormat.OpenXml.Wordprocessing.Table table = new DocumentFormat.OpenXml.Wordprocessing.Table(); // Create some table border settings. TableProperties borderProperties = new TableProperties( new TableBorders( new TopBorder { Val = new EnumValue<BorderValues>(BorderValues.DashDotStroked), Size = 12 }, new BottomBorder { Val = new EnumValue<BorderValues>(BorderValues.DashDotStroked), Size = 12 }, new LeftBorder { Val = new EnumValue<BorderValues>(BorderValues.DashDotStroked), Size = 12 }, new RightBorder { Val = new EnumValue<BorderValues>(BorderValues.DashDotStroked), Size = 12 }, new InsideHorizontalBorder { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 }, new InsideVerticalBorder { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 })); // Add the table border settings to the table. table.AppendChild<TableProperties>(borderProperties); // Create a table row and add two cells with some text var tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow(); var tc1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(); tc1.Append(new Paragraph(new Run(new Text("Here's some text in table cell #1")))); var tc2 = new DocumentFormat.OpenXml.Wordprocessing.TableCell(); tc2.Append(new Paragraph(new Run(new Text("Here's some text in table cell #2")))); tr.Append(tc1); tr.Append(tc2); // Add the row to the table, and the table to the body of the document. table.Append(tr); body.Append(table); } // At this stage, the local file has been created in the folder of this Web project // so we'll now read it and create a new file in SharePoint, based on this local file. byte[] documentBytes; fs = File.OpenRead(Server.MapPath("~/SampleOOXML/LocalOOXMLDocument.docx")); documentBytes = new byte[fs.Length]; fs.Read(documentBytes, 0, Convert.ToInt32(fs.Length)); // At this stage, the file contents of the OOXML document has been read into the byte array // so we can use that as the content of a new file in SharePoint. Microsoft.SharePoint.Client.FileCreationInformation ooxmlFile = new Microsoft.SharePoint.Client.FileCreationInformation(); ooxmlFile.Overwrite = true; ooxmlFile.Url = hostingWeb.Url + destintationFolder.ServerRelativeUrl + "/SharePointOOXMLDocument.docx"; ooxmlFile.Content = documentBytes; Microsoft.SharePoint.Client.File newFile = targetLibrary.RootFolder.Files.Add(ooxmlFile); clientContext.Load(newFile); clientContext.ExecuteQuery(); // Let the user navigate to the document library where the file has been created string targetUrl = hostingWeb.Url + destintationFolder.ServerRelativeUrl; DocumentLink.Text = "Document has been created in SharePoint! Click here to view the library"; DocumentLink.Visible = true; DocumentLink.NavigateUrl = targetUrl; } catch (Exception ex) { // Tell the user what went wrong DocumentLink.Text = "An error has occurred: " + ex.Message; DocumentLink.Visible = true; DocumentLink.NavigateUrl = ""; } finally { // Clean up our filestream object fs.Close(); } }
private void ProcessListProperty(Microsoft.SharePoint.Client.List list, Definitions.PropertyDefinition property) { list.RootFolder.Properties[property.Key] = property.Value; }
public Login() { InitializeComponent(); logger = new LogWriter("Login Form Opened"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("es"); DSL obj = new DSL(); DataTable category = obj.getCategories(); DataRow cat_row = category.NewRow(); cat_row["CategoryID"] = -1; cat_row["CategoryName"] = "--Select--"; category.Rows.InsertAt(cat_row, 0); cmxCategory.DataSource = category; cmxCategory.DisplayMember = "CategoryName"; cmxCategory.ValueMember = "CategoryID"; DataTable categoryRC = obj.getCategories(); DataRow categoryRC_row = categoryRC.NewRow(); categoryRC_row["CategoryID"] = -1; categoryRC_row["CategoryName"] = "--Select--"; categoryRC.Rows.InsertAt(categoryRC_row, 0); cmbxPositionRC.DataSource = categoryRC; cmbxPositionRC.DisplayMember = "CategoryName"; cmbxPositionRC.ValueMember = "CategoryID"; worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += Worker_DoWork; worker.ProgressChanged += Worker_ProgressChanged; // worker.RunWorkerAsync(); qrcode = new QRCodeWinForm(); QRCode_Panel.Controls.Add(qrcode); Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath); spJobsite = Convert.ToString(config.AppSettings.Settings["SharePointJobSite"].Value); spCandidateSite = Convert.ToString(config.AppSettings.Settings["SharePointSafetySite"].Value); CandidateList = Convert.ToString(config.AppSettings.Settings["quizListName"].Value); O365UserName = Convert.ToString(config.AppSettings.Settings["O365UserName"].Value); string tempString = config.AppSettings.Settings["O365Password"].Value; O365Password = new SecureString(); candidates = new DataTable(); candidates.Columns.Add("CandidateID", typeof(string)); candidates.Columns.Add("First_name", typeof(string)); candidates.Columns.Add("Last_name", typeof(string)); candidates.Columns.Add("Job", typeof(string)); candidates.Columns.Add("Hire_Status", typeof(string)); candidates.Columns.Add("FolderURL", typeof(string)); candidates.Columns.Add("Remaining_Test", typeof(string)); candidates.Columns.Add("DisplayCombobox", typeof(string)); candidates.Columns.Add("Category", typeof(string)); candidates.Columns.Add("Date", typeof(string)); candidates.Columns.Add("DOB", typeof(string)); foreach (char c in tempString) { O365Password.AppendChar(c); } JobListName = Convert.ToString(config.AppSettings.Settings["jobListName"].Value); using (Microsoft.SharePoint.Client.ClientContext context = new Microsoft.SharePoint.Client.ClientContext(spJobsite)) { try { context.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(O365UserName, O365Password); context.Load(context.Web, w => w.Title); context.ExecuteQuery(); Microsoft.SharePoint.Client.List list = context.Web.Lists.GetByTitle(JobListName); context.Load(list); Microsoft.SharePoint.Client.ListItemCollection listitems = list.GetItems(Microsoft.SharePoint.Client.CamlQuery.CreateAllItemsQuery()); context.Load(listitems); context.ExecuteQuery(); foreach (Microsoft.SharePoint.Client.ListItem item in listitems) { cmxJobList.Items.Add(item["JobNumber"] + " - " + item["Title"]); } cmxJobList.Items.Insert(0, "--Select--"); logger.LogWrite("JobComboBox Populated"); } catch (Exception ex) { logger.LogWrite("JobComboBox Population Failed"); logger.LogWrite(ex.StackTrace); } } using (Microsoft.SharePoint.Client.ClientContext context = new Microsoft.SharePoint.Client.ClientContext(spCandidateSite)) { context.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(O365UserName, O365Password); context.Load(context.Web, w => w.Title); context.ExecuteQuery(); Microsoft.SharePoint.Client.List list = context.Web.Lists.GetByTitle(CandidateList); context.Load(list); Microsoft.SharePoint.Client.ListItemCollection listitems = list.GetItems(Microsoft.SharePoint.Client.CamlQuery.CreateAllItemsQuery()); context.Load(listitems); context.ExecuteQuery(); DataRow row_select = candidates.NewRow(); row_select["DisplayCombobox"] = "--Select--"; row_select["CandidateID"] = -1; candidates.Rows.Add(row_select); foreach (Microsoft.SharePoint.Client.ListItem item in listitems) { // cmbxCandidateList.Items.Add(item["CandidateID"] + " - " + item["First_name"]+"_"+item["Last_name"]); DataRow row = candidates.NewRow(); row["CandidateID"] = item["CandidateID"]; row["First_name"] = item["First_name"]; row["Last_name"] = item["Last_name"]; row["Job"] = item["Job"]; row["Hire_Status"] = item["Hire_Status"]; Microsoft.SharePoint.Client.FieldUrlValue _url = (Microsoft.SharePoint.Client.FieldUrlValue)item["FolderUrl"]; row["FolderUrl"] = _url.Url; row["Remaining_Test"] = item["Remaining_Test"]; row["DisplayCombobox"] = item["CandidateID"] + " - " + item["First_name"] + "_" + item["Last_name"]; row["Category"] = item["Category"]; row["Date"] = item["Modified"]; row["DOB"] = item["DOB"]; candidates.Rows.Add(row); } cmbxCandidateList.DataSource = candidates; //cmbxCandidateList.Items.Add(new { Text = "---Select---", Value = -1 }); cmbxCandidateList.DisplayMember = "DisplayCombobox"; cmbxCandidateList.ValueMember = "CandidateID"; cmxJobList.SelectedIndex = 0; } }