/// <summary> /// Insert a new list item to a specific list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnInsertItem_Click(object sender, RoutedEventArgs e) { try { SPClient.List announcementsList = ctx.SPContext.Web.Lists.GetByTitle("MyFirstList"); ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); ListItem newItem = announcementsList.AddItem(itemCreateInfo); newItem["Title"] = this.txtBoxTitle.Text; newItem["Description"] = this.txtBoxDescription.Text; newItem.Update(); ctx.SPContext.ExecuteQuery(); MessageBox.Show("Item inserted"); this.txtBoxTitle.Text = ""; this.txtBoxDescription.Text = ""; } catch (Exception ex) { RaiseException(ex); } }
public static SP.View GetViewFromList(SP.ClientContext context, SP.List list, string viewName) { SP.View view = list.Views.GetByTitle(viewName); context.Load(view); context.ExecuteQuery(); return(view); }
public spClient.ListItemCollection getSharePointData(string subProjectRiskUrl, string query) { spClient.ListItemCollection collectionList = null; try { string[] validUrlApi = subProjectRiskUrl.Split(new string[] { "/Lists/" }, StringSplitOptions.None); string newriskUrl = subProjectRiskUrl; if (validUrlApi.Length != 0) { newriskUrl = validUrlApi[0] + "/"; } using (spClient.ClientContext ctx = new spClient.ClientContext(newriskUrl)) { var passWord = new SecureString(); foreach (var c in "intel@123") { passWord.AppendChar(c); } ctx.Credentials = new spClient.SharePointOnlineCredentials("*****@*****.**", passWord); spClient.Web myWeb = ctx.Web; spClient.List proList = myWeb.Lists.GetByTitle("Risk List"); spClient.CamlQuery myQuery = new spClient.CamlQuery(); myQuery.ViewXml = query; collectionList = proList.GetItems(myQuery); ctx.Load(collectionList); ctx.ExecuteQuery(); } } catch (Exception e) { collectionList = null; } return(collectionList); }
/// <summary> /// 指定一个文档库的名称并将其删除 /// </summary> /// <param name="siteUrl">站点</param> /// <param name="DocumentLibraryName">文档库的名称</param> /// <returns>返回操作的信息</returns> public string DeleteDocumentLibrary(string folderName) { string result = string.Empty; try { if (clientContext != null) { //创建客户端对象模型 using (clientContext) { //设置默认凭据 //获取站点(site) Web site = clientContext.Web; //通过标题获取文档库 Microsoft.SharePoint.Client.List existList = site.Lists.GetByTitle(folderName); //删除文档库对象 existList.DeleteObject(); //执行操作 clientContext.ExecuteQuery(); result = "删除成功"; } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "DeleteDocumentLibrary", ex.ToString(), folderName); } finally { } return(result); }
public static SP.List GetListFromWeb(SP.ClientContext context, string listTitle) { SP.List list = context.Web.Lists.GetByTitle(listTitle); context.Load(list); context.ExecuteQuery(); return(list); }
public bool IsFolderValid(SPList list, string folderName, string currentDir) { folderName = folderName.Trim(); if (String.IsNullOrEmpty(folderName)) { return(false); } using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl))) { SP.List splist = clientContext.ToList(list.Id); SP.Folder parentFolder = clientContext.Web.GetFolderByServerRelativeUrl(currentDir); clientContext.Load(parentFolder); var subfolders = clientContext.LoadQuery(parentFolder.Folders.Where(folder => folder.Name == folderName)); try { clientContext.ExecuteQuery(); } catch (Exception ex) { EventLogs.Warn(String.Format("An exception of type {0} occurred while loading subfolders for a directory '{1}'. The exception message is: {2}", ex.GetType().Name, currentDir, ex.Message), "SharePointClient", 778, CSContext.Current.SettingsID); return(false); } // subfolders.Count()>0 means, that the folder already exists return(!subfolders.Any()); } }
// Method - Migrate <=2mb file - MigrateBtn.onClick() private void Migrate_Click(object sender, RoutedEventArgs e) { string filePath = "c:/tmp/test.txt"; string libraryName = "test"; string siteUrl = "https://toanan.sharepoint.com/sites/Demo/"; string fileName = filePath.Substring(filePath.LastIndexOf("/") + 1); using (ClientContext ctx = new ClientContext(siteUrl)) { ctx.Credentials = CredentialManager.GetSharePointOnlineCredential(CredManager); FileCreationInformation fileInfo = new FileCreationInformation(); fileInfo.Url = fileName; fileInfo.Overwrite = true; fileInfo.Content = System.IO.File.ReadAllBytes(filePath); Web web = ctx.Web; List lib = web.Lists.GetByTitle(libraryName); File file = lib.RootFolder.Files.Add(fileInfo); ctx.ExecuteQuery(); file.ListItemAllFields["Created"] = "2015-07-03"; //file.ListItemAllFields["Modified"] = "01/01/2018"; //file.ListItemAllFields["Author"] = "*****@*****.**"; //file.ListItemAllFields["Editor"] = "*****@*****.**"; //file.ListItemAllFields.Update(); ctx.ExecuteQuery(); } } // End Method
private void ProductEditorDialog_AddClosed(object sender, EventArgs e) { ProductEditor dialog = (ProductEditor)sender; // stop if they clicked cancel if (dialog.DialogResult == false) { return; } StatusBarPanel.BeginUpdateMessage("Creating new item..."); SP.List products = Globals.ClientContext.Web.Lists.GetByTitle("Products"); SP.ListItemCreationInformation newProductInfo = new SP.ListItemCreationInformation(); SP.ListItem newProduct = products.AddItem(newProductInfo); newProduct["Title"] = dialog.ProductNameTextBox.Text; newProduct["Product_x0020_Number"] = dialog.ProductNumberTextBox.Text; newProduct["Price"] = dialog.ProductPriceTextBox.Text; SP.FieldLookupValue fieldValue = new SP.FieldLookupValue(); foreach (SP.ListItem item in Globals.ProductCategories) { if (item["Title"].ToString() == ((SP.ListItem)dialog.ProductCategoryComboBox.SelectedItem)["Title"].ToString()) { fieldValue.LookupId = item.Id; } } newProduct["Category"] = fieldValue; newProduct.Update(); Globals.ClientContext.ExecuteQuery(); this.Dispatcher.BeginInvoke(new Action(OnProducteditorAddUIUpdater), DispatcherPriority.Normal); }
public SP.Folder NewFolder(SPList list, string folderName, string currentDir) { if (!IsFolderValid(list, folderName, currentDir)) { return(null); } using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl))) { SP.List splist = clientContext.ToList(list.Id); SP.Folder parentFolder = clientContext.Web.GetFolderByServerRelativeUrl(currentDir); clientContext.Load(parentFolder); // add a new folder SP.Folder newFolder = parentFolder.Folders.Add(folderName); parentFolder.Update(); clientContext.Load(newFolder); try { clientContext.ExecuteQuery(); } catch (Exception ex) { EventLogs.Warn(String.Format("An exception of type {0} occurred while creating a new folder with a name '{1}' for a directory '{2}'. The exception message is: {3}", ex.GetType().Name, folderName, currentDir, ex.Message), "SharePointClient", 778, CSContext.Current.SettingsID); return(null); } cacheService.RemoveByTags(new[] { GetTag(list.Id) }, CacheScope.Context | CacheScope.Process); return(newFolder); } }
private async Task Update_List_failed(string candidateID) { try { Microsoft.SharePoint.Client.List list = ctx.Web.Lists.GetByTitle(quizListName); ctx.Load(list); //CamlQuery camlQuery = new CamlQuery(); //camlQuery.ViewXml= "<View><Query><Where><Geq><FieldRef Name='CandidateID'/>" + //"<Value Type='Text'>"+candidateID+"</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>"; Microsoft.SharePoint.Client.ListItemCollection listitems = list.GetItems(CreateCandidateQuery(CandID, CandName.Split('_')[0])); ctx.Load(listitems); ctx.ExecuteQuery(); foreach (ListItem oListItem in listitems) { oListItem["Hire_Status"] = "Failed"; oListItem["Remaining_Test"] = ""; //newItem["FolderUrl"] = folder.ServerRelativeUrl; oListItem.Update(); } await Task.Delay(1000); } catch (Exception ex) { throw ex; } }
private void LoadFields(SP.List list) { cmbFilterField.Enabled = false; cmbFilterField.Items.Clear(); if (cmbLists.SelectedIndex >= 0) { string webUrl = txtUrl.Text; List <string> fields = new List <string>(); fields.Add(""); using (SP.ClientContext ctx = GetClientContext(webUrl)) { StringBuilder sb = new StringBuilder(); sb.Append("<Fields>"); progressBar1.Value++; foreach (var item in list.Fields) { fields.Add(item.InternalName + " ( " + item.Title + " )"); sb.Append(item.SchemaXml); } sb.Append("</Fields>"); allFields = sb.ToString(); txtFields.Text = FormatXml(allFields); fields.Sort(); cmbFilterField.Items.AddRange(fields.ToArray()); } cmbFilterField.Enabled = true; } }
private BaseNode DoSPList(Microsoft.SharePoint.Client.List list, BaseNode parentNode, BaseNode rootNode) { list.EnsureProperties(l => l.RootFolder, l => l.BaseType, l => l.ContentTypes, l => l.Fields); ListNode listNode = parentNode as ListNode; // Add Content Type Container node BaseNode listContentTypeContainerNode = new ContentTypeContainerNode(list.ContentTypes); listNode.Children.Add(listContentTypeContainerNode); listContentTypeContainerNode.ParentNode = listNode; listContentTypeContainerNode.RootNode = rootNode; listContentTypeContainerNode.NodeConnector = this; // Add Field Container node BaseNode fieldContainerNode = new FieldContainerNode(list.Fields); listNode.Children.Add(fieldContainerNode); fieldContainerNode.ParentNode = listNode; fieldContainerNode.RootNode = rootNode; fieldContainerNode.NodeConnector = this; // Add immediate children of the root folder BaseNode rootFolder = this.DoSPFolder(list.RootFolder, listNode, rootNode, true); foreach (var subFolder in rootFolder.Children) { listNode.Children.Add(subFolder); } return(listNode); }
/// <summary> /// Initializes Site Combo box /// </summary> private void InitializeDynamicSiteComboBox() { using (var clientContext = new ClientContext(System.Configuration.ConfigurationManager.AppSettings["SiteURL"])) { SecureString securePassWd = new SecureString(); foreach (var c in this.OUser.Password.ToCharArray()) { securePassWd.AppendChar(c); } clientContext.Credentials = new SharePointOnlineCredentials(this.OUser.UserName, securePassWd); Microsoft.SharePoint.Client.List siteList = clientContext.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["SiteListName"]); clientContext.Load(siteList, list => list.DefaultViewUrl); CamlQuery query = CamlQuery.CreateAllItemsQuery(100); Microsoft.SharePoint.Client.ListItemCollection items = siteList.GetItems(query); clientContext.Load(items); clientContext.ExecuteQuery(); foreach (Microsoft.SharePoint.Client.ListItem listItem in items) { cbx_Site.Items.Add(listItem["Name"].ToString()); } this.cbx_Site.SelectedIndex = -1; this.cbx_Site.Text = "Select Site"; } }
protected void btnAddTask_Click(object sender, EventArgs e) { string SiteCollectionURL = txtSiteCollection.Text; CLOM.ClientContext context = new CLOM.ClientContext(SiteCollectionURL); CLOM.List taskList = context.Web.Lists.GetByTitle("Tasks"); CLOM.CamlQuery query = new CamlQuery(); CLOM.ListItemCollection myTaskList = taskList.GetItems(query); context.Load(myTaskList, itms => itms.ListItemCollectionPosition, itms => itms.Include( itm => itm["Title"], itm => itm["Body"], itm => itm["DueDate"])); context.ExecuteQuery(); ListItemCreationInformation newTask = new ListItemCreationInformation(); CLOM.ListItem newTaskItem = taskList.AddItem(newTask); newTaskItem["Title"] = txtTitle.Text; newTaskItem["Body"] = txtDesc.Text; newTaskItem["DueDate"] = Calendar1.SelectedDate; newTaskItem.Update(); context.ExecuteQuery(); lblResult.Text = "Added Task " + txtTitle.Text; }
public void addColumns(string listTitle) { Web web = mClientContext.Web; SP.List projList = mClientContext.Web.Lists.GetByTitle(listTitle); // Adding the Custom field to the List. Here the OOB SPFieldText has been selected as the “FieldType” SP.FieldCollection collFields = projList.Fields; collFields.AddFieldAsXml("<Field DisplayName='Estimated Start Time' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Estimated Start Date' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Estimated End Time' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Estimated End Date' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Actual Start Time' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Actual End Time' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Actual Start Date' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Actual End Date' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Milestone Number' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Milestone Comment' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Time Spent' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Resources' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Current Status' Type='Choice' />", true, AddFieldOptions.DefaultValue); collFields.AddFieldAsXml("<Field DisplayName='Current Status Reason' Type='Choice' />", true, AddFieldOptions.DefaultValue); //test field //collFields.AddFieldAsXml("<Field DisplayName='test' Type='Choice' />", true, AddFieldOptions.DefaultValue); //SP.Field oField = collFields.GetByTitle("MyNewField"); Console.WriteLine("Executing end of adding columns"); projList.Update(); mClientContext.ExecuteQuery(); }
/// <summary> /// Initializes Analyst Combo box /// </summary> private void InitializeDynamicUserComboBox() { using (var clientContext = new ClientContext(System.Configuration.ConfigurationManager.AppSettings["G23SiteURL"])) { SecureString securePassWd = new SecureString(); foreach (var c in this.OUser.Password.ToCharArray()) { securePassWd.AppendChar(c); } clientContext.Credentials = new SharePointOnlineCredentials(this.OUser.UserName, securePassWd); Microsoft.SharePoint.Client.List siteList = clientContext.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["G23UserListName"]); clientContext.Load(siteList, list => list.DefaultViewUrl); CamlQuery query = CamlQuery.CreateAllItemsQuery(100); Microsoft.SharePoint.Client.ListItemCollection items = siteList.GetItems(query); clientContext.Load(items); clientContext.ExecuteQuery(); usersRadDropDownList.Items.Add("Select User"); foreach (Microsoft.SharePoint.Client.ListItem listItem in items) { //Yes = True, No = False if (listItem["Active"].ToString() == "True") { usersRadDropDownList.Items.Add(listItem["Name"].ToString()); } } //Set default item usersRadDropDownList.SelectedIndex = 0; } }
internal RestSPList(SP.List splist) { Id = splist.Id; Title = splist.Title; Description = splist.Description; Url = String.Concat(splist.Context.Url.TrimEnd('/'), "/", splist.DefaultViewUrl.TrimStart('/')); }
private void CreateNovoContacto(ClientContext siteContexto, List listaTelefonica, ItemListaTelefonicaProperties itemListaTelefonicaProperties) { try { ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); ListItem addItem = listaTelefonica.AddItem(itemCreateInfo); addItem["Title"] = itemListaTelefonicaProperties.PreferredName; addItem["FirstName"] = itemListaTelefonicaProperties.FirstName; addItem["LastName"] = itemListaTelefonicaProperties.LastName; addItem["Email"] = itemListaTelefonicaProperties.Email; addItem["PagerNumber"] = itemListaTelefonicaProperties.Pager; addItem["Department"] = itemListaTelefonicaProperties.Department; addItem["CellPhone"] = itemListaTelefonicaProperties.CellPhone; addItem["PictureURL"] = itemListaTelefonicaProperties.PictureURL; addItem["Office"] = itemListaTelefonicaProperties.Office; addItem["WorkFax"] = itemListaTelefonicaProperties.WorkFax; addItem["WorkPhone"] = itemListaTelefonicaProperties.WorkPhone; addItem["WorkState"] = itemListaTelefonicaProperties.WorkState; addItem["WorkCity"] = itemListaTelefonicaProperties.WorkCity; addItem["WorkCountry"] = itemListaTelefonicaProperties.WorkCountry; addItem["WorkZip"] = itemListaTelefonicaProperties.WorkZip; addItem["IpPhone"] = itemListaTelefonicaProperties.IpPhone; addItem["WorkAddress"] = itemListaTelefonicaProperties.WorkAddress; addItem["AboutMe"] = itemListaTelefonicaProperties.AboutMe; addItem["JobTitle"] = itemListaTelefonicaProperties.JobTitle; addItem["Company"] = itemListaTelefonicaProperties.Company; addItem.Update(); siteContexto.ExecuteQuery(); } catch (Exception ex) { _log.Error($"-> CreateNovoContacto no processo: SharepointSyncJob: {ex}", ex); } }
public void Tree_ItemsAdd(Microsoft.SharePoint.Client.List list) { TbgTreeItem item = new TbgTreeItem(list.Title, client, list); item.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(item_MouseLeftButtonDown); this.treeView.Items.Add(item); }
private bool VerifySiteAndLibriary(string siteURL, string libriaryName, out string returnMsg) { returnMsg = string.Empty; if (string.IsNullOrEmpty(siteURL) || !(siteURL.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) || siteURL.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)) || !Uri.TryCreate(siteURL, UriKind.Absolute, out siteURI)) { returnMsg = "Please input a valid URL for the site (start with http:// or https://)."; return(false); } if (string.IsNullOrEmpty(libriaryName)) { returnMsg = "Please input a Name for the library."; return(false); } try { spContext = new ClientContext(siteURL); spLibrary = spContext.Web.Lists.GetByTitle(libriaryName); spContext.Load(spLibrary); spContext.ExecuteQuery(); } catch (Exception ex) { returnMsg = ex.Message; return(false); } return(true); }
static string GetDepartment(ClientContext clientContext, int id) { Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("People"); clientContext.Load(spList); clientContext.ExecuteQuery(); if (spList != null && spList.ItemCount > 0) { Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = @"<View> <Query> <Where><Eq><FieldRef Name='Employee' LookupId='True' /><Value Type='Integer'>23</Value></Eq></Where> </Query> </View>"; ListItemCollection listItems = spList.GetItems(camlQuery); clientContext.Load(listItems); clientContext.ExecuteQuery(); var dep = (FieldLookupValue)listItems[0]["Department_x0020_name"]; return(dep.LookupValue); } return("DepNotFound"); }
public EmployeeModel CheckNewEntry(string EMPCode, string siteUrl) { int returnVal = 0; EmployeeModel employeeModels = new EmployeeModel(); using (MSC.ClientContext context = GetContext(siteUrl)) { var dataDateValue = DateTime.Today; MSC.List list = context.Web.Lists.GetByTitle("TIM_DailyAttendance"); MSC.ListItemCollectionPosition itemPosition = null; var q = new CamlQuery() { ViewXml = "<View><Query><Where><And><Eq><FieldRef Name='EmpNo' /><Value Type='Text'>" + EMPCode + "</Value></Eq><Eq><FieldRef Name='AttendanceDate' /><Value Type='Text'>" + dataDateValue.ToString("dd-MM-yyyy") + "</Value></Eq></And></Where></Query></View>" }; MSC.ListItemCollection Items = list.GetItems(q); context.Load(Items); context.ExecuteQuery(); itemPosition = Items.ListItemCollectionPosition; returnVal = Items.Count; if (returnVal > 0) { employeeModels.ID = Items[0]["ID"].ToString(); employeeModels.count = Items.Count; } else { employeeModels.count = Items.Count; } } return(employeeModels); }
public SP.FileCollection Attachments(SPListItem listItem, SPList list, object value) { if (value == null || !(bool)value) { return(null); } using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl))) { SP.Web web = clientContext.Web; clientContext.Load(web); SP.List splist = clientContext.ToList(list.Id); clientContext.Load(splist); SP.ListItem splistItem = splist.GetItemById(listItem.Id); clientContext.Load(splistItem); clientContext.ExecuteQuery(); SP.Folder listFolder = splistItem.ParentList.RootFolder; clientContext.Load(listFolder, f => f.ServerRelativeUrl); clientContext.ExecuteQuery(); SP.Folder attachmentsFolder = web.GetFolderByServerRelativeUrl(listFolder.ServerRelativeUrl + "/attachments/" + splistItem.Id.ToString()); clientContext.Load(attachmentsFolder); var attachments = attachmentsFolder.Files; clientContext.Load(attachments); clientContext.ExecuteQuery(); return(attachments); } }
private void AddViews(frm_Data_View viewForm, string listId, string siteAddress, string siteName) { Guid g = new Guid(listId); SP.ClientContext clientContext = SharePoint.GetClient(siteAddress, frm_Main_Menu.username, frm_Main_Menu.password); SP.List oList = clientContext.Web.Lists.GetById(g); // Load in the Views clientContext.Load(oList.Views); clientContext.ExecuteQuery(); int i = 0; foreach (SP.View oView in oList.Views) { i++; clientContext.Load(oView.ViewFields); clientContext.ExecuteQuery(); string viewName = oView.Title; string viewId = oView.Id.ToString(); string fieldCount = oView.ViewFields.Count.ToString(); string rowLimit = oView.RowLimit.ToString(); string viewQuery = oView.ViewQuery; string url = frm_Main_Menu.siteUrl + oView.ServerRelativeUrl; viewForm.AddRow(i, viewName, siteName, siteAddress, fieldCount, rowLimit, viewId, viewQuery, url); lbl_Row_Count.Text = i.ToString() + " record(s) found"; lbl_Row_Count.Refresh(); } }
private string UploadToSharePoint(byte[] convertedByteArray, Stream reqData, string baseFileName, string watermarkedLibrary) { string siteUrl = ""; //reqData.SiteAbsoluteUrl; //Insert Credentials ClientContext context = new ClientContext(siteUrl); //SecureString passWord = new SecureString(); //foreach (var c in "mypassword") passWord.AppendChar(c); //context.Credentials = new SharePointOnlineCredentials("myUserName", passWord); Web site = context.Web; string newFileName = baseFileName.Split('.')[0] + DateTime.Now.ToString("yyyyMMdd") + "." + baseFileName.Split('.')[1]; //System.IO.File.WriteAllBytes("Foo.txt", convertedByteArray); FileCreationInformation newFile = new FileCreationInformation(); newFile.ContentStream = new MemoryStream(convertedByteArray); //convertedByteArray;// System.IO.File.WriteAllBytes("", convertedByteArray); newFile.Url = System.IO.Path.GetFileName(newFileName); newFile.Overwrite = true; Microsoft.SharePoint.Client.List docs = site.Lists.GetByTitle(watermarkedLibrary); Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile); context.Load(uploadFile); context.ExecuteQuery(); //Return the URL of the new uploaded file string convertedFileLocation = ""; // reqData.WebServerRelativeUrl + "/" + watermarkedLibrary + "/" + newFileName; return(convertedFileLocation); }
private void createButton_Click(object sender, RoutedEventArgs e) { string UserName = "******", Password = "******"; ClientContext ctx = new ClientContext("https://omisayeduiu.sharepoint.com/sites/sayeddev"); SecureString passWord = new SecureString(); foreach (char c in Password.ToCharArray()) { passWord.AppendChar(c); } ctx.Credentials = new SharePointOnlineCredentials(UserName, passWord); Web myWeb = ctx.Web; Microsoft.SharePoint.Client.List sectionsList = myWeb.Lists.GetByTitle("sectionInfo"); ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); Microsoft.SharePoint.Client.ListItem newItem = sectionsList.AddItem(itemCreateInfo); newItem["sectionName"] = sectionBox.Text.Trim().ToString(); newItem["sectionWeight"] = Convert.ToInt32(weightBox.Text.Trim()); newItem.Update(); ctx.ExecuteQuery(); this.show(); }
public static byte[] ConvertHtmltoPdf(ClientContext context, Microsoft.SharePoint.Client.List documentLibrary, string result, string nameOfTheFile) { using (var msOutput = new MemoryStream()) { using (var stringReader = new StringReader(result)) { using (Document document = new Document()) { var pdfWriter = PdfWriter.GetInstance(document, msOutput); pdfWriter.InitialLeading = 12.5f; document.Open(); var xmlWorkerHelper = XMLWorkerHelper.GetInstance(); var cssResolver = new StyleAttrCSSResolver(); var xmlWorkerFontProvider = new XMLWorkerFontProvider(); //foreach (string font in fonts) //{ // xmlWorkerFontProvider.Register(font); //} var cssAppliers = new CssAppliersImpl(xmlWorkerFontProvider); var htmlContext = new HtmlPipelineContext(cssAppliers); htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory()); PdfWriterPipeline pdfWriterPipeline = new PdfWriterPipeline(document, pdfWriter); HtmlPipeline htmlPipeline = new HtmlPipeline(htmlContext, pdfWriterPipeline); CssResolverPipeline cssResolverPipeline = new CssResolverPipeline(cssResolver, htmlPipeline); XMLWorker xmlWorker = new XMLWorker(cssResolverPipeline, true); XMLParser xmlParser = new XMLParser(xmlWorker); xmlParser.Parse(stringReader); } } return(msOutput.ToArray()); } }
private SP.ListItemCollection GetItemsFromSharepointList(string listName, string viewName) { try { // get the list from context SP.List readList = SharepointMethods.GetListFromWeb( _context, listName); // get view from list by view name SP.View readView = SharepointMethods.GetViewFromList( _context, readList, viewName); // get items from list by view SP.ListItemCollection readListItems = SharepointMethods.GetViewItemsFromList( _context, readList, readView); return(readListItems); } catch (Exception e) { MessageBox.Show(e.ToString()); return(null); } }
public static string GetSettingsUrl(this SPClient.ContentType ct, TreeNode selectedNode) { // Link: <sitecollection|web>/_layouts/ManageContentType.aspx?ctype=0x0101009148F5A04DDD49CBA7127AADA5FB792B006973ACD696DC4858A76371B2FB2F439A // Link: <sitecollection|web>/_layouts/ManageContentType.aspx?List=%7BF798C4D9%2DEF29%2D4F8D%2DA1F1%2D4C70CFBAECE4%7D&ctype=0x010100A204AFB24228A94AB2D6195EB1705291 if (selectedNode.Parent.Parent.Tag is SPClient.Site) { SPClient.Site site = selectedNode.Parent.Parent.Tag as SPClient.Site; return(string.Format("{0}/_layouts/ManageContentType.aspx?ctype={1}", site.RootWeb.GetUrl(), ct.Id)); } else if (selectedNode.Parent.Parent.Tag is SPClient.Web) { // <sitecollection>/<web>/_layouts/15/ManageContentType.aspx?ctype=0x00A7470EADF4194E2E9ED1031B61DA088403000BE6CEFFF1ACA6429D14B2B7E0A03FE2 // <sitecollection>/<web>/_layouts/15/start.aspx#/_layouts/15/ManageContentType.aspx?ctype=0x00A7470EADF4194E2E9ED1031B61DA088403000BE6CEFFF1ACA6429D14B2B7E0A03FE2&Source=https%3A%2F%2Fbramdejager%2Esharepoint%2Ecom%2Fsub%2F%5Flayouts%2F15%2Fmngctype%2Easpx SPClient.Web web = selectedNode.Parent.Parent.Tag as SPClient.Web; return(string.Format("{0}/_layouts/ManageContentType.aspx?ctype={1}", web.GetUrl(), ct.Id)); } else if (selectedNode.Parent.Parent.Tag is SPClient.List) { SPClient.List list = selectedNode.Parent.Parent.Tag as SPClient.List; return(string.Format("{0}/_layouts/ManageContentType.aspx?list={1}&ctype={2}", list.ParentWeb.GetUrl(), list.Id, ct.Id)); } else { return(string.Empty); } }
public int UpdateEntry(EmployeeModel emp, string siteUrl, string ID) { try { using (MSC.ClientContext context = GetContext(siteUrl)) { MSC.List list = context.Web.Lists.GetByTitle("TIM_DailyAttendance"); MSC.ListItem listItem = null; MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation(); listItem = list.GetItemById(Convert.ToInt32(ID)); listItem["AttendanceDate"] = Convert.ToDateTime(emp.attendance_date).ToString("dd-MM-yyyy"); listItem["CheckinTime"] = emp.checkin_time; listItem["CheckoutTime"] = emp.checkout_time; listItem["Comment"] = emp.comment; listItem["EmpNo"] = emp.empno; listItem["Hours"] = emp.hours; listItem["EmpName"] = emp.name; listItem["EmpMail"] = emp.office_email; listItem.Update(); context.ExecuteQuery(); } } catch (Exception ex) { } return(0); }
public ItemPathProvider(List list, Web web) { var fields = list.Fields; m_listServerRelativeUrl = list.RootFolder.ServerRelativeUrl; this.List = list; this.Web = web; }
public ListItemsProvider(List list, Web web, ProvisioningTemplate template) { this.List = list; this.Web = web; }