code samples
8 Topicshow to implement audience using CSOM?
I am trying to target content based on audience feature of sharepoint. Requirements demands to customize the UI which includes attachment. Conent Query Web Part (CQWP) supports the audience but attachment link is not supported. Only option left is to write an CSOM code to pull the data and target content to audience. But I could not find any links related to this implementation. Is it possible to implement audience using CSOM or JSOM or REST API?2.1KViews0likes2CommentsSPFx Webpart and MSGraphClient
Hello, I need to write a webpart, which shows data from the MS Graph. I wrote this example code import { Version } from '@microsoft/sp-core-library'; import { BaseClientSideWebPart, IPropertyPaneConfiguration, PropertyPaneTextField } from '@microsoft/sp-webpart-base'; import { escape } from '@microsoft/sp-lodash-subset'; import styles from './HelloWorldWebPart.module.scss'; import * as strings from 'HelloWorldWebPartStrings'; export interface IHelloWorldWebPartProps { description: string; } export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> { public render(): void { const client: MSGraphClient = this.context.serviceScope.consume(MSGraphClient.serviceKey); // get information about the current user from the Microsoft Graph client .api('/me/?$select=displayName,department') .get((error, user: MicrosoftGraph.User, rawResponse?: any) => { // Resulat like // { // "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(displayName,department)/$entity", // "department": "Finance", // "displayName": "Megan Bowen" // } }); } this.domElement.innerHTML = ` <div class="${ styles.helloWorld }" <span class="${ styles.title }">Welcome to SharePoint!</span> <span> Name</span> <span> Deartment</span> </div>`; } protected get dataVersion(): Version { return Version.parse('1.0'); } protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { return { pages: [ { header: { description: strings.PropertyPaneDescription }, groups: [ { groupName: strings.BasicGroupName, groupFields: [ PropertyPaneTextField('description', { label: strings.DescriptionFieldLabel }) ] } ] } ] }; } } But wow I can bring the Department and Name (result form the MS Graph) into the HTML rendering? When I really understand the MSGraphClient works asynchron. How can I get save, that first the MSGraphClient gets the result and the build the HTLM rendering part? Thanks for your help Stefan1.3KViews0likes0CommentsOutlook appointment add-in
Hi all, I am developing an outlook add-in that can be used to order a sandwich when creating an calendar entry in outlook. By default, outlook web add-ins are available when reading a mail. I want this add-in to be available when creating/updating a calendar entry. In the documentation I found that the manifest file should include rule with type appointment: https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/activation-rules But this does not seem to work for me. Mail add-in Adding the addin to a mail works perfectly: Procedure: open any mail > 3 dots > get addins > my addins > add custom addin > select xml file result: - Helloworldaddin is available in every mail opened for reading. - Helloworldaddin is not available for calendar events. Calendar entry If I use the same procedure in a calendar entry, nothing happens. I don't even get a popup to add a custom add-in. Procedure: open calendar event > 3 dots > get add-ins > Result: no pup-up to add my add-in.. Has anyone any idea? Big thanks1.4KViews0likes1CommentCopying files across site collections NOT working with app credentials, Any Idea?
Below code is working with user credentials for moving files across site collections. But when the user credentials are replaced with app credentials (ClientID,ClientSecret), it is throwing unauthorized 401 access. Tried giving FullControl access at sitecollection and site level. No luck. Please provide your input, if anybody has solved this issue. public static void CopyDocuments() { var login = "<user@tenant>.onmicrosoft.com"; var password = "<password>"; string srcUrl="https://xxx.sharepoint.com/sites/site1"; string destUrl="https://xxx.sharepoint.com/sites/site2"; string srcLibrary="library1"; string destLibrary="library1"; var securePassword = new SecureString(); foreach (char c in password) { securePassword.AppendChar(c); } var onlineCredentials = new SharePointOnlineCredentials(login, securePassword); // set up the src client SP.ClientContext srcContext = new SP.ClientContext(srcUrl); srcContext.Credentials = onlineCredentials; // set up the destination context (in your case there is no needs to create a new context, because it would be the same library!!!!) SP.ClientContext destContext = new SP.ClientContext(destUrl); destContext.Credentials = onlineCredentials; // get the list and items SP.Web srcWeb = srcContext.Web; SP.List srcList = srcWeb.Lists.GetByTitle(srcLibrary); SP.ListItemCollection col = srcList.GetItems(new SP.CamlQuery()); srcContext.Load(col); srcContext.ExecuteQuery(); // get the new list SP.Web destWeb = destContext.Web; destContext.Load(destWeb); destContext.ExecuteQuery(); foreach (var doc in col) { try { if (doc.FileSystemObjectType == SP.FileSystemObjectType.File) { // get the file SP.File f = doc.File; srcContext.Load(f); srcContext.ExecuteQuery(); // build new location url string nLocation = destWeb.ServerRelativeUrl.TrimEnd('/') + "/" + destLibrary.Replace(" ", "") + "/" + f.Name; // read the file, copy the content to new file at new location SP.FileInformation fileInfo = SP.File.OpenBinaryDirect(srcContext, f.ServerRelativeUrl); SP.File.SaveBinaryDirect(destContext, nLocation, fileInfo.Stream, true); } if (doc.FileSystemObjectType == SP.FileSystemObjectType.Folder) { // load the folder srcContext.Load(doc); srcContext.ExecuteQuery(); // get the folder data, get the file collection in the folder SP.Folder folder = srcWeb.GetFolderByServerRelativeUrl(doc.FieldValues["FileRef"].ToString()); SP.FileCollection fileCol = folder.Files; // load everyting so we can access it srcContext.Load(folder); srcContext.Load(fileCol); srcContext.ExecuteQuery(); foreach (SP.File f in fileCol) { // load the file srcContext.Load(f); srcContext.ExecuteQuery(); string[] parts = null; string id = null; if (srcLibrary == "My Files") { // these are doc sets parts = f.ServerRelativeUrl.Split('/'); id = parts[parts.Length - 2]; } else { id = folder.Name; } // build new location url string nLocation = destWeb.ServerRelativeUrl.TrimEnd('/') + "/" + destLibrary.Replace(" ", "") + "/" + id + "/" + f.Name; // read the file, copy the content to new file at new location SP.FileInformation fileInfo = SP.File.OpenBinaryDirect(srcContext, f.ServerRelativeUrl); SP.File.SaveBinaryDirect(destContext, nLocation, fileInfo.Stream, true); } } } catch (Exception ex) { Log("File Error = " + ex.ToString()); } } }1.9KViews0likes2CommentsHow to: Create your own Family Video Room using Azure Communication Services
If we learnt one thing in 2020, it’s how to use video conferencing to replace in-person meetings. Nowhere has this been more obvious (to me) than family meetups. Sure, I’m doing more conference calls for work, but I’ve always done conference calls for work. I’ve never done them for catching up with my extended family, though. Skype, Teams, Zoom, HouseParty – I don’t know about you, but we’ve tried them all. They all have their advantages and disadvantages. As a developer, I was left thinking “I wonder if I could do something different: something that’s just right for our family, with just the stuff we need, and easy enough for everyone to use”. Post continues at: How to: Create your own Family Video Room using Azure Communication Services without writing any code (if you don’t want to) | The thoughtstuff Blog where I talk about how I used the Azure Communication Services sample code, with some modifications, to create a family video room, secured with a PIN. The blog contains links to a GitHub repository you can use as a template to create your own family video room, powered by Azure Communication Services!767Views2likes0CommentsTeam client source
We want to be able to have a Team chat client embedded as a component in one of our in-house Angular applications. What would be the best way to approach this? Is the source available to use anywhere or would we have to develop our own and mimic the client? Thanks Ian1.1KViews0likes1CommentRest API to get recently modified documents
I am trying to use the delve/rest API to get the recently modified documents for a logged in user. This has worked in the past, but now the results seem to be off. For my user account, it will only return 1 result no matter what I do. This is what I have used in the past: var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext=%27(*)+AND+(FileExtension:doc+OR+FileExtension:docx+OR+FileExtension:ppt+OR+FileExtension:pptx+OR+FileExtension:xls+OR+FileExtension:xlsx+OR+FileExtension:xlsm+OR+FileExtension:pdf)%27"+ "&SelectProperties='Title,FileExtension,Path,ParentLink,LastModifiedTime,ServerRedirectedURL,SPWebUrl,SiteTitle'"+ "&clienttype='ContentSearchRegular'"+ "&properties=%27GraphQuery:ACTOR(ME\\,action\\:1003),GraphRankingModel:{%22features%22\\:[{%22function%22\\:%22EdgeTime%22}]}%27"+ "&rankingmodelid='0c77ded8-c3ef-466d-929d-905670ea1d72'"+ "&rowlimit=10"; Did something change? Is this endpoint not correct?2.5KViews1like1CommentHow do I make the web part content area transparent?
I've used a background image on one of my sites and when add web parts it makes the area behind the web parts translucent white as you can see in the screen snip below. Does anyone have a code snippet I can use to make it completely transparent?1.3KViews0likes0Comments