id
stringlengths
14
16
text
stringlengths
2
3.14k
source
stringlengths
45
175
b1c0e38c8a2c-3
When you create a SharePoint-hosted add-in, you can add a reference to the object model by using HTML <script> tags. The add-in web in a SharePoint-hosted add-in allows you to use relative paths to reference the required files to use the JavaScript object model. The following markup performs these tasks to add a re...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-4
// Continue your program flow here. </script> SharePoint website tasks To work with websites using JavaScript, start by using the ClientContext(serverRelativeUrl) constructor and pass a URL or URI to return a specific request context. Retrieve the properties of a website Use the web property of the C...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-5
function onQuerySucceeded(sender, args) { alert('Title: ' + this.oWebsite.get_title() + ' Description: ' + this.oWebsite.get_description()); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } Retrieve only selecte...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-6
function onQuerySucceeded(sender, args) { alert('Title: ' + this.oWebsite.get_title() + ' Created: ' + this.oWebsite.get_created()); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } Note If you try to access o...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-7
function onQuerySucceeded(sender, args) { alert('Title: ' + this.oWebsite.get_title() + ' Description: ' + this.oWebsite.get_description()); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } SharePoint list t...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-8
function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } Retrieve only specified properties of lists The previous example returns all properties of the lists in a website. To reduce unnecessary data transference between client and server...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-9
Store retrieved lists in a collection As the following example shows, you can use the loadQuery(clientObjectCollection, exp) method instead of the load(clientObject) method to store the return value in another collection instead of storing it in the lists property. function retrieveSpecificListPropertiesToColle...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-10
this.listInfoArray = clientContext.loadQuery(collList, 'Include(Title,Fields.Include(Title,InternalName))'); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this._onQueryFailed) ); } function onQuerySucceeded() { ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-11
Create, update, and delete lists Creating, updating, and deleting lists through the client object model works similarly to how you perform these tasks using the .NET client object model, although client operations do not complete until you call the executeQueryAsync(succeededCallback, failedCallback) function. Cr...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-12
oList.set_description('New Announcements List'); oList.update(); clientContext.load(oList); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); Add a field to a list Use the add(field) or addFieldAsXml(schemaXml,...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-13
function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } Delete a list To delete a list, call the deleteObject() function of the list object, as shown in the following example. function deleteList(siteUrl) { var clientContext = n...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-14
clientContext = new SP.ClientContext.get_current(); oWebsite = clientContext.get_web(); oList = oWebsite.get_lists().getByTitle("Shared Documents"); itemCreateInfo = new SP.ListItemCreationInformation(); itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder); itemCreateInfo.set_lea...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-15
function successHandler() { resultpanel.innerHTML = "Go to the " + "<a href='../Lists/Shared Documents'>document library</a> " + "to see your updated folder."; } function errorHandler() { resultpanel.innerHTML = "Request failed: " + arguments[1].get_message(); } } ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-16
function errorHandler() { resultpanel.innerHTML = "Request failed: " + arguments[1].get_message(); } } Create, read, update, and delete files You can manipulate files by using the JavaScript object model. The following sections show you how to perform basic operations on files. Note You can...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-17
function successHandler() { resultpanel.innerHTML = "Go to the " + "<a href='../Lists/Shared Documents'>document library</a> " + "to see your new file."; } function errorHandler() { resultpanel.innerHTML = "Request failed: " + arguments[1].get_message(); ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-18
clientContext = new SP.ClientContext.get_current(); oWebsite = clientContext.get_web(); oList = oWebsite.get_lists().getByTitle("Shared Documents"); fileCreateInfo = new SP.FileCreationInformation(); fileCreateInfo.set_url("TextFile1.txt"); fileCreateInfo.set_content(new SP.Base64EncodedByteArray()...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-19
clientContext.load(oWebsite); clientContext.executeQueryAsync(function () { fileUrl = oWebsite.get_serverRelativeUrl() + "/Lists/Shared Documents/TextFile1.txt"; this.fileToDelete = oWebsite.getFileByServerRelativeUrl(fileUrl); this.fileToDelete.deleteObject(); clientCon...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-20
function errorHandler() { resultpanel.innerHTML = "Request failed: " + arguments[1].get_message(); } } SharePoint list item tasks To return items from a list by using JavaScript, use the getItemById(id) function to return a single item, or use the getItems(query) function to return multiple i...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-21
function onQuerySucceeded(sender, args) { var listItemInfo = ''; var listItemEnumerator = collListItem.getEnumerator(); while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); listItemInfo += '\nID: ' + oListItem.get_id() + '\nTitle: ' ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-22
clientContext.load( collListItem, 'Include(Id, DisplayName, HasUniqueRoleAssignments)' ); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); } function onQuerySucceeded(sender, args) {...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-23
Because this example uses an Include , only the specified properties are available after query execution. Therefore, you receive a PropertyOrFieldNotInitializedException if you try to access other properties beyond those that have been specified. In addition, you receive this error if you try to use functions such a...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-24
var clientContext = new SP.ClientContext(siteUrl); var oList = clientContext.get_web().get_lists().getByTitle('Announcements'); var itemCreateInfo = new SP.ListItemCreationInformation(); this.oListItem = oList.addItem(itemCreateInfo); oListItem.set_item('Title', 'My New Item!'); oListItem.s...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-25
clientContext.load(oListItem); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); } function onQuerySucceeded() { alert('Item created: ' + oListItem.get_id()); } function onQueryFailed(sender, args) {...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-26
function onQuerySucceeded() { alert('Item updated!'); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } Delete a list item To delete a list item, call the deleteObject() function on the object. The following example uses ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-27
function onQuerySucceeded() { alert('Item deleted: ' + itemId); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } If you want to retrieve, for example, the new item count that results from a delete operation, include a call t...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-28
function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } Access objects in the host web While developing your add-in, you might need to access the host web to interact with items in it. Use the AppContextSite object to reference th...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
b1c0e38c8a2c-29
// Function to handle the error event. // Prints the error message to the page. function errorHandler(data, errorCode, errorMessage) { alert("Could not complete cross-domain call: " + errorMessage); } } The previous example uses the cross-domain library in SharePoint to access the host web. For...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint
8dc46f73e3ab-0
You can use the SharePoint client object model (CSOM) to retrieve, update, and manage data in SharePoint. SharePoint makes the CSOM available in several forms: .NET Framework redistributable assemblies .NET Standard redistributable assemblies JavaScript library (JSOM) REST/OData endpoints In this article,...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
8dc46f73e3ab-1
Yes No See the Using modern authentication with CSOM for .NET Standard chapter. Using Azure AD applications to configure authentication for SharePoint Online is the recommended approach SaveBinaryDirect / OpenBinaryDirect APIs (webdav based) Yes No Use the regular file APIs in CSOM as it's not reco...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
8dc46f73e3ab-2
In this chapter, we'll use an OAuth resource owner password credential flow resulting in an OAuth access token that then is used by CSOM for authenticating requests against SharePoint Online as that mimics the behavior of the SharePointOnlineCredentials class. Configuring an application in Azure AD Below steps wi...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
8dc46f73e3ab-3
// Insert the access token in the request e.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + accessToken; }; } The ClientContext obtained via the GetContext method can be used like any other ClientContext and will work with all your existing code. Below code snippets show a helper c...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
8dc46f73e3ab-4
// Note: The PnP Sites Core AuthenticationManager class also supports this using (var authenticationManager = new AuthenticationManager()) using (var context = authenticationManager.GetContext(site, user, password)) { context.Load(context.Web, p => p.Title); await context.ExecuteQueryAsync()...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
8dc46f73e3ab-5
context.ExecutingWebRequest += (sender, e) => { string accessToken = EnsureAccessTokenAsync(new Uri($"{web.Scheme}://{web.DnsSafeHost}"), userPrincipalName, new System.Net.NetworkCredential(string.Empty, userPassword).Password).GetAwaiter().GetResult(); e.WebRequestExecutor.R...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
8dc46f73e3ab-6
// Register a thread to invalidate the access token once's it's expired tokenResetEvent = new AutoResetEvent(false); TokenWaitInfo wi = new TokenWaitInfo(); wi.Handle = ThreadPool.RegisterWaitForSingleObject( tokenResetEvent, ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
8dc46f73e3ab-7
var clientId = defaultAADAppId; var body = $"resource={resource}&client_id={clientId}&grant_type=password&username={HttpUtility.UrlEncode(username)}&password={HttpUtility.UrlEncode(password)}"; using (var stringContent = new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded")...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
8dc46f73e3ab-8
private static TimeSpan CalculateThreadSleep(string accessToken) { var token = new System.IdentityModel.Tokens.Jwt.JwtSecurityToken(accessToken); var lease = GetAccessTokenLease(token.ValidTo); lease = TimeSpan.FromSeconds(lease.TotalSeconds - TimeSpan.FromMinutes(5).TotalSec...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard
d39f3b037bd8-0
You can use the SharePoint client object model (CSOM) to retrieve, update, and manage data in SharePoint. SharePoint makes the CSOM available in several forms: .NET Framework redistributable assemblies JavaScript library (JSOM) REST/OData endpoints Windows Phone assemblies ( deprecated ) Silverlight redistr...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-1
using Microsoft.SharePoint.Client; Except where specified otherwise, you can assume that each of these examples is in a parameterless method that is defined in the page's class. Also, label1 , label2 , and so on, are the names of Label objects on the page. Note When you are making a provider-hosted SharePo...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-2
// The SharePoint web at the URL. Web web = context.Web; // We want to retrieve the web's properties. context.Load(web); // Execute the query to the server. context.ExecuteQuery(); // Now, the web's properties are available and we could display // web properties, such as title. label1.Text = web.Title; Retrieve o...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-3
// Execute the query to server. context.ExecuteQuery(); // Now, only the web's title and description are available. If you // try to print out other properties, the code will throw // an exception because other properties aren't available. label1.Text = web.Title; label1.Text = web.Description; Note If you try ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-4
label1.Text = newWeb.Title; SharePoint list tasks These examples show how to use the .NET Framework CSOM to complete list-related tasks. Retrieve all SharePoint lists in a website This example retrieves all SharePoint lists in a SharePoint website. To compile this code, you need to add a using statement for ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-5
// The SharePoint web at the URL. Web web = context.Web; // Retrieve all lists from the server, and put the return value in another // collection instead of the web.Lists. IEnumerable<SP.List> result = context.LoadQuery( web.Lists.Include( // For each list, retrieve Title and Id. list => list.Title, ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-6
List list = web.Lists.GetByTitle("My List"); list.DeleteObject(); context.ExecuteQuery(); Add a field to a SharePoint list This example adds a field to a SharePoint list. Add an alias to the using statement for the Microsoft.SharePoint.Client namespace so you can refer to its classes unambiguously. For example,...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-7
context.ExecuteQuery(); SharePoint list item tasks These examples demonstrate how to use the .NET Framework CSOM to complete tasks that are related to list items. Retrieve items from a SharePoint list This example retrieves the items in a SharePoint list. You also need to add a using statement for Microsoft...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-8
// We are just creating a regular list item, so we don't need to // set any properties. If we wanted to create a new folder, for // example, we would have to set properties such as // UnderlyingObjectType to FileSystemObjectType.Folder. ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); Lis...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-9
context.ExecuteQuery(); } SharePoint field tasks These examples show how to use the SharePoint .NET Framework CSOM to complete field-related tasks. Retrieve all of the fields in a list This example retrieves all of the fields in a SharePoint list. You also need to add an alias to the using statement for the ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-10
// We must call ExecuteQuery before enumerate list.Fields. context.ExecuteQuery(); foreach (SP.Field field in list.Fields) { label1.Text = label1.Text + ", " + field.InternalName; } Retrieve a specific field from the list If you want to retrieve information about a specific field, use the Fields.GetByInternalN...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-11
// Now, we can access the specific text field properties. label1.Text = textField.MaxLength; SharePoint user tasks You can use the SharePoint .NET Framework CSOM to manage SharePoint users, groups, and user security. Add a user to a SharePoint group This example adds a user and some user information to a Share...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-12
foreach (User member in membersGroup.Users) { // We have all the user info. For example, Title. label1.Text = label1.Text + ", " + member.Title; } Create a role This example creates a role that has create and manage alerts permissions. // Starting with ClientContext, the constructor requires a URL to the // ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-13
context.ExecuteQuery(); Rules and best practices for using the SharePoint .NET client object model These examples illustrate some important best practices and requirements you should conform to when using the SharePoint .NET Framework CSOM. Call ClientContext.ExecuteQuery before accessing any value properties ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-14
context.Load(web, w => w.Title); context.ExecuteQuery(); label1.Text = web.Title; The differences are the addition of these lines; the first line creates a query for the web's Title property. The second line executes the query. context.Load(web, w => w.Title); context.ExecuteQuery(); Don't use value objects...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-15
Web web = context.Web; context.Load(web, w => w.Title, w => w.Description); context.ExecuteQuery(); ListCreationInformation creationInfo = new ListCreationInformation(); creationInfo.TemplateType = (int)ListTemplateType.Announcements; creationInfo.Description = web.Description; creationInfo.Title = web.Title; SP.Lis...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-16
context.ExecuteQuery(); The difference is the following three lines: context.Load(web, w => w.Title, w => w.Description); context.ExecuteQuery(); // ... context.ExecuteQuery(); Using methods or properties that return client objects in another method call in the same query Unlike a value object, a client objec...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-17
getting the Lists property from the above result invoking the GetByTitle method with the Announcements parameter from the above result When the SharePoint .NET Framework CSOM passes this information to the server, you can recreate the object on the server. In the client library, you can keep track of the O...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-18
static void Method2() { ClientContext context = new ClientContext("https://{site_url}"); Web web = context.Web; SP.List list = web.Lists.GetByTitle("Announcements"); context.Load(web, w => w.Title); context.Load(list, l => l.Description); context.Load(web, w => w.Description); context.ExecuteQuery(); } ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-19
// Method2: SELECT Title FROM Webs WHERE … SELECT Description FROM Lists WHERE … SELECT Title, Description FROM Webs WHERE … Specify which properties of objects you want to return In the SharePoint server object model, if you get an SPWeb object, you can inspect all of its properties. In SQL, to get all of the c...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-20
Console.WriteLine(web.Title); Console.WriteLine(web.HasUniqueRoleAssignments); Use conditional scope to test for preconditions before loading data To conditionally execute code, set a conditional scope by using a ConditionalScope object. For example, retrieve the list property when the list isn't null. You also ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
d39f3b037bd8-21
label1.Text = scope.TestResult.Value; if (scope.TestResult.Value) { label1.Text = list.Title; } Use an exception handling scope to catch exceptions This example shows how to create and use an exception handling scope with an ExceptionHandlingScope object. The scenario is to update the description of a list an...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code
dc73b5b6dc41-0
Use the API index to look up many of the most frequently used types and objects that are implemented in the .NET server object model and at least one client programming model: .NET client-side object model (CSOM), JavaScript object model (JSOM), and/or REST. This table lists the most frequently used core APIs, which ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index
dc73b5b6dc41-1
…/_api/web/contenttypes('<content type id>') ContentTypeCollection SPContentTypeCollection SP.ContentTypeCollection object …/_api/web/contenttypes SPContext SP.RequestContext object N/A EventReceiverDefinition SPEventReceiverDefinition SP.EventReceiverDefinition object …/_api/web/event...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index
dc73b5b6dc41-2
FieldComputed SPFieldComputed SP.FieldComputed object …/_api/web/fields('<field id>') FieldCurrency SPFieldCurrency SP.FieldCurrency object …/_api/web/fields('<field id>') FieldLink SPFieldLink SP.FieldLink object …/_api/web/contenttypes('<content type id>')/fieldlinks('<field link id>') ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index
dc73b5b6dc41-3
FileCollection SPFileCollection SP.FieldCollection object …/_api/web/getfolderbyserverrelativeurl('/<folder name>')/files Folder SPFolder SP.Folder object …/_api/web/getfolderbyserverrelativeurl('/<folder name>') Form SPForm SP.Form object …/_api/web/lists(guid'<list id>')/forms('<form id>...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index
dc73b5b6dc41-4
SP.NavigationNode object N/A Principal SPPrincipal SP.Principal object N/A SPQuery N/A RecycleBinItem SPRecycleBinItem SP.RecycleBinItem object …/_api/web/RecycleBin(recyclebinitemid) RecycleBinItemCollection SPRecycleBinItemCollection SP.RecycleBinItemCollection object …...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index
dc73b5b6dc41-5
TimeZoneCollection SPTimeZoneCollection SP.TimeZoneCollection object …/_api/web/RegionalSettings/TimeZones User SPUser SP.User object …/_api/web/siteusers(@v)? @v= '<login name>' UserCollection SPUserCollection SP.UserCollection object …/_api/web/sitegroups(<group id>)/users Utility ...
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index
dc73b5b6dc41-6
See also Develop SharePoint Add-ins Complete basic operations using SharePoint client library code Complete basic operations using JavaScript library code in SharePoint
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/sharepoint-net-server-csom-jsom-and-rest-api-index
8c738267365c-0
With Office 365, if you’re running and utilizing the SharePoint Online service, you must rethink the way that you run what used to be timer jobs in your traditional farm solutions. In traditional SharePoint development, you use timer jobs to perform scheduled tasks in SharePoint farms. A commonly used technique is ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-1
Install the package called AppForSharePointOnlineWebToolkit . The toolkit installs the required helper classes for working with the SharePoint client-side object model (CSOM). Ensure that the NuGet package worked by making sure that the following two new classes appear in your console application project...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-2
// TODO: Add your logic here! } } private static SecureString GetSPOSecureStringPassword() { try { Console.WriteLine(" - > Entered GetSPOSecureStringPassword()"); var secureString = new SecureString(); foreach (char c in ConfigurationManager.AppSettings["SPOPass...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-3
Create a new service account in Office 365 For this to work, you should create a specific account that acts as a service account for either this specific application or a generic service application account that all your jobs and services can use. For the sake of this demo, we created a new account called SP WebJo...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-4
You can see the two settings in the app.config file: SPOAccount SPOPassword If you review the first code snippet, these settings are from the app.config file. Just keep in mind that this means storing the account name and password in clear text in your app.config. You need to make a decision in your own proje...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-5
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 SharePointOnlineCredential...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-6
context.ExecuteQuery(); Console.WriteLine("Updated all the list items you found. Carry on..."); } } } catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); Console.WriteLine("ERROR: " + ex.Source); Console.WriteLine("ERROR: " + ex.StackTrace); ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-7
The TranslatorHelper class is a helper class that calls a custom translation API, but it will not be discussed in detail in this post because it's out of the scope of this article. Note As seen from the code, this is a demo and definitely not for production use. Please revise it and adjust according to your cod...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-8
If you scroll down in the settings pane for your website, you’ll find a tile called WebJobs under the Operations header. Click the area where the arrow is pointing. Upload your WebJob Upload your WebJob by choosing the [+ Add] sign. Choose a name and how the job should run, and then upload t...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-9
Make sure the WebJob name is web friendly. Select your WebJob run mode . If you want to have it occur on a specific time every day, choose Run on a Schedule . Should the job be a recurring job or a one-time job? Because you want to simulate a timer job, it needs to be recurring, and if it will run every n...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-10
In your Azure portal, choose Import and specify the publishing profile file that you downloaded from your Azure website. Publish With that done, all you need to do is choose Publish . The Web Publish Activity dialog then displays the progress of your WebJob deployment. When it’s done, you should see th...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
8c738267365c-11
Develop and deploy WebJobs using Visual Studio - Azure App Service Simple remote timer job that interacts with SharePoint Online video by Andrew Connell on Channel9 Use Microsoft Azure WebJobs with Office 365 PnP remote timer job framework
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/getting-started-with-building-azure-webjobs-for-your-office365-sites
71ada6b7527a-0
Create remote timer jobs to manage SharePoint by monitoring and taking action on SharePoint data. Remote timer jobs do not run on your SharePoint server. Instead, remote timer jobs are scheduled tasks that run on another server. Examples of how timer jobs are used include: Performing governance tasks, such as dis...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-1
Using the Core.TimerJobs.Samples.SimpleJob add-in In Core.TimerJobs.Samples.SimpleJob , Main in Program.cs performs the following steps: Creates a SimpleJob object, which inherits from the OfficeDevPnP.Core.Framework.TimerJobs.TimerJob base class. Sets the Office 365 user credentials to use when runnin...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-2
// The user credentials must have access to the site collections you supply. simpleJob.UseOffice365Authentication(User, Password); // Use the following code if you are using SharePoint Server on-premises. //simpleJob.UseNetworkCredentialsAuthentication(User, Password, Domain); ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-3
// Prints timer job information and then calls Run(). PrintJobSettingsAndRunJob(simpleJob); } When the SimpleJob object is instantiated, the SimpleJob constructor: Calls the TimerJob base class constructor. Assigns the SimpleJob_TimerJobRun event handler to handle the Tim...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-4
// Run job. job.Run(); } TimerJob.Run raises TimerJobRun events. TimerJob.Run calls SimpleJob_TimerJobRun in SimpleJob.cs, which you set as the event handler to handle TimerJobRun events in the constructor of SimpleJob . In SimpleJob_TimerJobRun , you can add your custom code that ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-5
<ContentTypeRetentionPolicyPeriod> <!-- Key is the content type ID, and value is the retention period in days --> <!-- Specifies an audio content type should be kept for 183 days --> <add key="0x0101009148F5A04DDD49cbA7127AADA5FB792B006973ACD696DC4858A76371B2FB2F439A" value="183" /> <!-- Specifies a doc...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-6
// Get all document libraries. Lists are excluded. var documentLibraries = GetAllDocumentLibrariesInWeb(e.WebClientContext, e.WebClientContext.Web); // Iterate through all document libraries. foreach (var documentLibrary in documentLibraries) { ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-7
// Iterate through configured content type retention policies specified in app.config. foreach (var contentTypeName in configContentTypeRetentionPolicyPeriods.Keys) { var retentionPeriods = configContentTypeRetentionPolicyPeriods.GetValues(contentTypeName ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-8
// Get old documents in the library that match the content type. if (documentLibrary.ItemCount > 0) { var camlQuery = new CamlQuery(); camlQuery.ViewXml = String.Format( @"<View> <Query> ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-9
clientContext.ExecuteQueryRetry(); foreach (var listItem in listItems) { Log.Info("ContentTypeRetentionEnforcementJob", "Document '{0}' has been modified earlier than {1}. Retention policy will be applied.", listItem.DisplayName, validationDate); ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-10
// Get the number of administrators. var admins = e.WebClientContext.Web.GetAdministrators(); Log.Info("SiteGovernanceJob", "ThreadID = {2} | Site {0} has {1} administrators.", e.Url, admins.Count, Thread.CurrentThread.ManagedThreadId); // Get a reference to the list. ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
71ada6b7527a-11
e.CurrentRunSuccessful = true; e.DeleteProperty("LastError"); } catch(Exception ex) { Log.Error("SiteGovernanceJob", "Error while processing site {0}. Error = {1}", e.Url, ex.Message); e.CurrentRunSuccessful = false; e.S...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-remote-timer-jobs-in-sharepoint
8e8e5a5c906f-0
The PnP timer job framework is a set of classes designed to ease the creation of background processes that operate against SharePoint sites. The timer job framework is similar to on-premises full trust code timer jobs ( SPJobDefinition ). The primary difference between the timer job framework and the full trust code ti...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-1
Add the Office 365 Developer Patterns and Practices Core NuGet package to your project. There's a NuGet package for v15 (on-premises) and for v16 (Office 365) . This is the preferred option. Add the existing PnP Core source project to your project. This allows you to step into the PnP core code when debugging. ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-2
namespace Core.TimerJobs.Samples.SimpleJob { public class SimpleJob: TimerJob { public SimpleJob() : base("SimpleJob") { TimerJobRun += SimpleJob_TimerJobRun; } void SimpleJob_TimerJobRun(object sender, TimerJobRunEventArgs e) { e.WebClientContext...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-3
// Run the job simpleJob.Run(); } Timer job deployment options The previous step demonstrates a simple timer job. The next step is to deploy the timer job. A timer job is an .exe file that must be scheduled on a hosting platform. Depending on the chosen hosting platform, the deployment differs. The following...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-4
Right-click the project in Visual Studio and choose Publish as Azure WebJob . Provide a schedule for the timer job, and then choose OK . Choose Microsoft Azure Websites as a publish target. You'll be asked to sign in to Azure and select the Azure website that will host the timer job (you can also create a n...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-5
Open the Task Scheduler ( Control Panel > Task Scheduler ). Choose Create Task and specify a name and an account that will execute the task. Choose Triggers and add a new trigger. Specify the schedule you want for the timer job. Choose Actions and choose the action Start a program , select the timer job ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-6
Provide a scope , which is a list of sites. Optionally set timer job properties . From an execution perspective, the following overall steps are taken when a timer job run is started: Resolve sites : Wild card site URLs (for example, https://tenant.sharepoint.com/sites/d* ) are resolved into an actual list...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-7
There are similar methods for running against SharePoint on-premises : public void UseNetworkCredentialsAuthentication(string samAccountName, string password, string domain) public void UseNetworkCredentialsAuthentication(string credentialName) App only App-only authentication is the preferred method because ...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-8
A wild card URL is a URL that ends with an asterisk ( * ). Only one single * is allowed and it must be the last character of the URL. A sample wild card URL is https://tenant.sharepoint.com/sites/* , which returns all the site collections under the managed path of that site. For another example, https://tenant.sh...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-9
// Manually adding a new wildcard Url, without an added URL the timer job will do...nothing addedSites.Add("https://bertonline.sharepoint.com/sites/d*");
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework
8e8e5a5c906f-10
// Return the updated list of sites return addedSites; } Specify enumeration credentials After adding a wild card URL and setting authentication to app-only, specify the enumeration credentials. Enumeration credentials are used to fetch a list of site collections that are used in the site matching algorithm to...
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/timerjob-framework