Hot answers tagged

9

Using your SP.Web object, you can get the parent information (SP.WebInformation). Using its ID, you can then, via the site collection, get the parent web object. var context = new SP.ClientContext.get_current(); var web = context.get_web(); var parentInfo = web.get_parentWeb(); var parentWeb = ...


8

There is a property on the list for the default dispform, newform and editform url. Example: var clientContext = SP.ClientContext.get_current(); var list = clientContext.get_web().get_lists().getByTitle("ListTitle"); var caml = new SP.CamlQuery(); caml.set_viewXml("<View />"); var listItemCollection = list.getItems(caml); clientContext.load(list, ...


7

I wrote my own JSLink Manager (runs as a Browser Bookmarklet) To: add/delete JSlinks on WebParts/Views in order Immediate save/apply on any change Have to refactor it a bit to work it into the iCSR library Update #1 http://icsr.github.io/JSLinkManager.html is my current version of the JSLinkManager as Bookmarklet...


6

In the newest release of the "SharePoint Online Management Shell" (v16.0.4630.1200) the included Microsoft.SharePoint.Client.dll adds the property RequestAccessEmail to the Web class. Download: https://www.microsoft.com/en-us/download/details.aspx?id=35588 You may use this DLL until the NuGet-Package is released. EDIT: Since version 16.1.4727.1200 of the ...


5

/_api/web/lists/GetByTitle('ListName')/items?$top=1000


5

The method SaveAsTemplate is not exposed in CSOM API, there is a general suggestion opened: Expose List.SaveAsTemplate() for CSOM API Basically you can create lists using already existing custom templates, but programmatically you cannot create new ones. Site.GetCustomListTemplates(web); Web.ListTemplates What you can do is define the list schema xml and ...


5

As stated in the comments, you would need to structure your code in a way to get the result of the asynchronous operation, your code should be something like this: SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getUserName); var user ; //declare this as a variable related to your current namespace, only here for demonstration. function getUserName(){ ...


5

An alternative to using the get_parentWeb is using the _spPageContextInfo object for urls and only needs one execute: if(_spPageContextInfo.siteServerRelativeUrl != _spPageContextInfo.webServerRelativeUrl) { var parentWebUrl = _spPageContextInfo.webServerRelativeUrl.split("/").slice(0,-1).join("/"); var ctx = new SP.ClientContext(parentWebUrl); var ...


5

Using REST API, it is very much easier to get parent web information. Just make a GET request to the following URL. _api/Web/ParentWeb In response, you will get all information about parent as like following. { "d": { "__metadata": { "id": "http://xxx.sharepoint.com/_api/Web/ParentWeb", "uri": ...


4

Not sure, whether you already found the answer. But you have to put in ownersGroup.update() before your context.load


4

I have corrected your code and here you go $(document).ready(function() { ExecuteOrDelayUntilScriptLoaded(GetDesc, "sp.js"); }); function GetDesc() { context = new SP.ClientContext.get_current(); web = context.get_web(); siteURL=$(location).attr('href'); var titleName=document.title; var mListName= "TestList"; ...


4

Here is how to do it in JS var clientContext = SP.ClientContext.get_current(); var web = clientContext.get_web(); var webGroupsCollection = web.get_roleAssignments().get_groups(); //gets a web specificc groups var siteGroupsCollection = web.get_siteGroups(); //gets all site collections groups similarly there would be something like ...


4

Yes, you can add webparts using the client side object model. Summary: Use the LimitedWebPartManager defined for C# or JavaScript. Adding webparts is generally considered part of a provisioning solution and the OfficeDev Patterns and Practices (PnP) repository on GitHub has many examples that demonstrate different provisioning techniques. One specific ...


4

When connecting to SharePoint Online, you should use SharePointOnlineCredentials instead of FormsAuthenticationLoginInfo. using (var context = new ClientContext("https://contoso.sharepoint.com")) { var password = new SecureString(); foreach (var c in "Password") { secureString.AppendChar(c); } context.Credentials = new ...


3

Here is how you can use the Microsoft Fakes Framework for mocking the SharePoint ClientContext class. using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.QualityTools.Testing.Fakes; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Fakes; namespace MyNamespace { [TestClass] public class MyTestClass ...


3

You can check the Template type of a web object. If it is APP#0 you don't need to add it to List. The example here shows how to get the web template. http://stackoverflow.com/questions/19382310/using-client-object-model-how-to-fetch-the-web-template-name-and-web-templat


3

JavaScript Object Model code which you have used, is asynchronous. Which means the execution is passed on to next statement and HTML is rendered without waiting for the result you get in your variable appendingCssStyle. I doubt you will be able to achieve it with your existing code. Possible solutions Instead of assigning appendingCssStyle in HTML, You ...


2

yes you can try below rest call url: http://site url/_api/web/GetFileByServerRelativeUrl('/Shared Documents/a.pdf') method: POST headers: Authorization: "Bearer " + accessToken X-RequestDigest: form digest value IF-MATCH: etag or "*" X-HTTP-Method:"DELETE" Hope this will work for you :)


2

SPQuery query = new SPQuery(); query.Query = @"<Where><Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='Integer'>" + _id + @"</Value></Eq></Where><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>"; where _id is user's ID.


2

The option of querying items with $top is not advisable for performance reasons and impact on the network traffic. The best option is recursion. Note: Normally you have a callback on success and you may have to work on all items: in that case you need to concat all results before executing the callback. Also you may need a check on complete callback. The ...


2

You can easily create a list item with managed meta data field as : function createaListItem() { var clientContext = new SP.ClientContext.get_current(); var oList = clientContext.get_web().get_lists().getByTitle('Listname'); var itemCreateInfo = new SP.ListItemCreationInformation(); this.oListItem = oList.addItem(itemCreateInfo); ...


2

I had the same problem as yours. I was passing username in format "domain\username" but it was returning all permissions as false. Finally I realized that I was using Claims based authentication for SharePoint. I changed username to claims format "i:0#.w|domain\username" and it started working perfectly after that. Hope this helps.


2

I had a chunk of code that was working, then moved things around to tidy it up, and suddenly I faced this same error when trying to add a webpart. It took me forever, but eventually it appears that I had to check my page out BEFORE I created the LimitedWebPartManager, or I'd get that error after running adding the Webpart and then calling ExecuteQuery(). ...


2

Use below code to create/update item using CSOM C# string webUri = "http://servername/sites/demo"; using (ClientContext context = new ClientContext(webUri)) { //By Default it will use windows credentials //If want to specify credentials use below line context.Credentials = new NetworkCredential( ...


2

In AppManifest.xml file add Permission for your app. If you are performing CRUD operations on List Or Library then provide necessary Permission based on scope. eg: We are using Manage Permission for developer on Site Collection Scope.


2

Here is an example for you and it is the combo of REST and AngularJS. Let me know if you have any questions.


2

Updating a list item in JSOM should be as simple as this: function updateListItem(itemId) { var clientContext = new SP.ClientContext(siteUrl); var oList = clientContext.get_web().get_lists().getByTitle('My List'); this.oListItem = oList.getItemById(itemId); oListItem.set_item('MyField', 'My Updated Field Value'); oListItem.update(); ...


2

Finally i found my answer after lots of research. It was the problem related to Authorization, the SharePoint server which i wanted to refer, had a Form based Authentication. So i updated my code according to that and it worked fine. Please find my below updated code using (ClientContext spcontext = new ClientContext("siteURL")) { ...


2

There is all sorts of ways to skin this cat. Add a Custom Action which can only be used once Use CSR to render a button for each item This all requires some coding. For quick prototyping I stuff HTML+JavaScript in a Calculated Column (and then instruct the 5 US$ an hour programmers in India to replicate the behaviour in more solid code, although to be ...


2

Get a list of fields first, then iterate them, if needed check for conditions (read only, visible etc.) and then display the values: var clientContext = new SP.ClientContext.get_current(); var web = clientContext.get_web(); var list = web.get_lists().getByTitle("ListName"); this.listFields = list.get_fields(); clientContext.load(this.listFields); ...



Only top voted, non community-wiki answers of a minimum length are eligible