CSOM
7 TopicsRetrieve custom properties of Office files through API call in OneDrive
In SharePoint, we are able to retrieve custom properties of the Office files through API call using Microsoft's CSOM library. This information is usually available in the "Properties" field. However, when uploading the same file to OneDrive and doing the same request, "Properties" field does not contain this information. As an example, please find the attached "Test DOCX file with custom properties.docx" file. https://files.axiomint.com/external/folder/afvh9b9bd8d011e2540d68c5992b1a7cd07b1?layout=list It contains 2 custom properties - "TestCustom1" and "TestCustom2". When uploading to SharePoint, this information is becoming available through API. SharePoint also changes the file size, so we assume it stores this data somewhere to make it available later for API requests. When uploading to OneDrive the file size does not grow and custom properties are not available during the request. So, our questions are 1. Why it works for SharePoint and does not work for OneDrive? 2. Is there a setting or some feature in OneDrive which will make it available there? Thanks, Vahe.1.3KViews0likes2CommentsCopy All Files and Folder from One Library to Another Library Subfolder on Diff Site Col Not Working
I'm trying to copy all files and folder from one library to another library subfolder between different site collections using the script from https://www.sharepointdiary.com/2017/02/sharepoint-online-copy-files-between-site-collections-using-powershell.html?unapproved=6740&moderation-hash=225816fd92c7259a540ec89c5072256c#comment-6740. It works for files after I modified $TargetFileURL = $TargetFolder.ServerRelativeUrl+”/”+$SourceLibraryName+”/”+$SourceFile.Name but struggling with subfolders from the source. They copy to the root without files in them. How can I make them copy to the same subfolder in the target library? #Load SharePoint CSOM Assemblies Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" Function Copy-Files { param ( [Parameter(Mandatory=$true)] [Microsoft.SharePoint.Client.Folder] $SourceFolder, [Parameter(Mandatory=$true)] [Microsoft.SharePoint.Client.Folder] $TargetFolder ) Try { #Get all Files from the source folder $SourceFilesColl = $SourceFolder.Files $SourceFolder.Context.Load($SourceFilesColl) $SourceFolder.Context.ExecuteQuery() #Iterate through each file and copy Foreach($SourceFile in $SourceFilesColl) { #Get the source file $FileInfo = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($SourceFolder.Context, $SourceFile.ServerRelativeUrl) #Copy File to the Target location $TargetFileURL = $TargetFolder.ServerRelativeUrl+"/"+$SourceFile.Name [Microsoft.SharePoint.Client.File]::SaveBinaryDirect($TargetFolder.Context, $TargetFileURL, $FileInfo.Stream,$True) Write-host -f Green "Copied File '$($SourceFile.ServerRelativeUrl)' to '$TargetFileURL'" } #Process Sub Folders $SubFolders = $SourceFolder.Folders $SourceFolder.Context.Load($SubFolders) $SourceFolder.Context.ExecuteQuery() Foreach($SubFolder in $SubFolders) { If($SubFolder.Name -ne "Forms") { #Prepare Target Folder $TargetFolderURL = $SubFolder.ServerRelativeUrl -replace $SourceLibrary.RootFolder.ServerRelativeUrl, $TargetLibrary.RootFolder.ServerRelativeUrl Try { $Folder=$TargetFolder.Context.web.GetFolderByServerRelativeUrl($TargetFolderURL) $TargetFolder.Context.load($Folder) $TargetFolder.Context.ExecuteQuery() } catch { #Create Folder if(!$Folder.Exists) { $TargetFolderURL $Folder=$TargetFolder.Context.web.Folders.Add($TargetFolderURL) $TargetFolder.Context.Load($Folder) $TargetFolder.Context.ExecuteQuery() Write-host "Folder Added:"$SubFolder.Name -f Yellow } } #Call the function recursively Copy-Files -SourceFolder $SubFolder -TargetFolder $Folder } } } Catch { write-host -f Red "Error Copying File!" $_.Exception.Message } } #Set Parameter values $SourceSiteURL="https://crescent.sharePoint.com/sites/sales" $TargetSiteURL="https://crescent.sharepoint.com/sites/ops" $SourceLibraryName="Project Documents" $TargetLibraryName="Documents" #Setup Credentials to connect $Cred= Get-Credential $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Setup the contexts $SourceCtx = New-Object Microsoft.SharePoint.Client.ClientContext($SourceSiteURL) $SourceCtx.Credentials = $Credentials $TargetCtx = New-Object Microsoft.SharePoint.Client.ClientContext($TargetSiteURL) $TargetCtx.Credentials = $Credentials #Get the source library and Target Libraries $SourceLibrary = $SourceCtx.Web.Lists.GetByTitle($SourceLibraryName) $SourceCtx.Load($SourceLibrary) $SourceCtx.Load($SourceLibrary.RootFolder) $TargetLibrary = $TargetCtx.Web.Lists.GetByTitle($TargetLibraryName) $TargetCtx.Load($TargetLibrary) $TargetCtx.Load($TargetLibrary.RootFolder) $TargetCtx.ExecuteQuery() #Call the function Copy-Files -SourceFolder $SourceLibrary.RootFolder -TargetFolder $TargetLibrary.RootFolder1.1KViews0likes0CommentsCopying Content Type and Fields from one Hub Site to another crashes Document Library
Hi, I have 2 Hub Sites on SharePoint Online (Site A and Site B). Site A has a Content Type called "Finance Document" with some fields. I follow the instruction on this page to create new Content Type, Fields and link the Fields to my Content Type using the field definition from Site A. https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/create-sharepoint-content-types-by-using-csom After that, my document library becomes inaccessible (screenshot), however I can still access its setting page or access it via CSOM code. Any idea why it happens ?850Views0likes0CommentsSearch Issue After Installing KB4461549 (Dec 2018 CU)
My question: What is the best way to get support for this? SP2013 has moved out of mainstream support, and so I am not quite sure the right way to report this issue other than paying $500 to open a ticket. Background: We installed the patches for December 2018 as while most of our search web parts still seem to work fine, there is one that crashes with the message "Sorry, something went wrong" with the network trace showing a call to the Client.svc ProcessQuery endpoint. It only crashes when the user is still anonymous. Once they login they do not get the error - and it is really only on this one page. The other pages will load their search results web parts without issue. I created a test page to reproduce the error: https://www.wecc.org/Lists/WECCMeetings/DispForm2.aspx?ID=14031 - note we do geoblock so I apologize to those outside the U.S. that might have trouble accessing our site. Also note, I have a workaround in place that uses the Search REST API to replace the crashed query on the main DispForm.aspx (remove the 2) with the proper results. Notes: KB4461549 - https://support.microsoft.com/en-us/help/4461549/Security-Update-for-SharePoint-Enterprise-Server-2013-December-11-2018 More detailed information available on the TechNet post I also created: https://social.technet.microsoft.com/Forums/en-US/ac9a250b-8739-42a4-b457-347893765b2f/clientsvc-processquery-fails-with-invalid-url-argument?forum=sharepointsearchSolved1.7KViews0likes1CommentHow to Restore Alerts for a Site collection? [SOS]
Hi there, We are using SharePoint Online. One of our site admins accidentally deleted all the alerts set up by different users on different libraries, folders and documents. We don't have any information on the deleted alerts or what type they were (immediate, weekly, daily etc). We really want all these alerts back. Is there any way that I could get these alerts back or at least the information about these alerts so that I can create the same alerts again? I can work with CSOM, PowerShell or anything that solves the problem. I just want these alerts back! if it is possible.2KViews1like3CommentsJSOM/REST Set List Item Property Bag Value
Hi all! Is there a way to set List Item Property Bag value using JavaScript Object Model or REST API? I've tried to use the approach that works fine for Web and List (Root folder) property bags: var ctx = SP.ClientContext.get_current(); var web = ctx.get_web(); var list = web.get_lists().getByTitle('import test'); var item = list.getItemById(1); ctx.load(item); ctx.executeQueryAsync(function() { var props = item.get_properties(); props.set_item('test', 'test'); item.update(); ctx.executeQueryAsync(); }); But if you then refresh the page and get list item's properties again, the new key-value won't be there. There are no errors in the response of executeQueryAsync...3.4KViews0likes0CommentsCSOM : Server Unauthorized Access Exception: Access Denied.
i created window agent for the end user. where the data will send to the Data list Sharepoint. The problem is, when i try to use to the window agent to the local company user account, it shown the problem that i state on the title. But when i try to use my local company user account, it succcessfully sent. My theory: you need to have permission at sharepoint site using your local account and also in window current user, you need to use the same account at the sharepoint. Means, your local user account in windows and sharepoint is needed to send to datalist, and you cannot use other window account to send to datalist. any solution of this ? string username = "USERNAME"; string password = "PASSWORD"; string domain = "DOMAIN; System.Net.NetworkCredential _myCredentials = new System.Net.NetworkCredential(username, password, domain); string siteUrl = "MYSITE"; ClientContext clientContext = new ClientContext(siteUrl); SP.List oList = clientContext.Web.Lists.GetByTitle("Test_List"); ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); ListItem oListItem = oList.AddItem(itemCreateInfo); //CUSTODIAN DETAIL oListItem["Title"] = "Test"; oListItem.Update(); clientContext.ExecuteQuery(); Console.WriteLine("Send Sucessfully!"); Console.ReadLine();Solved30KViews0likes11Comments