Créer un site internet

Blog

Caml Query Issue

On 16/11/2018

Sharepoint caml query errors

The following exception occurred while trying to enumerate the collection: "Un ou plusieurs types de champs ne sont pas installés correctement. Accédez à la page des paramètres de liste pour supprimer ces champs.

i think my list was corrupted, but it was only my query who's got mistakes

if you see error above, try your query only with <Where></Where>, if she's working, your query contains errors

Powershell Paged Caml Query

On 16/11/2018

param(
[string]$siteCollUrl = "http://test/sites/site1/",[string]$listTitle="Stockage",
[boolean]$checkin=$false,[boolean]$publish=$false, [boolean]$deleteAllVersion=$true
)
$web = Get-SPWeb $siteCollUrl
$splList = $web.Lists[$listTitle]
$spqQuery = New-Object Microsoft.SharePoint.SPQuery
$spqQuery.Query = "<Where><Neq><FieldRef Name='_Level' /><Value Type='Number'>1</Value></Neq></Where><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>";
 
$spqQuery.ViewAttributes = "Scope=""RecursiveAll""";
$spqQuery.ViewFields = "<FieldRef Name='FileLeafRef' /><FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='owshiddenversion' /><FieldRef Name='_Level' /><FieldRef Name='_IsCurrentVersion' /><FieldRef Name='_UIVersion' />" #_UIVersionString
$spqQuery.ViewFieldsOnly = $true
 
$spqQuery.RowLimit = 1000;
 
# IsCheckedoutToLocal
$iNumber=1
do{
if($iNumber -eq 1)
{
$spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition;
}
$splListItems = $splList.GetItems($spqQuery)
writeInfo "page number : $($iNumber)"
foreach ($splListItem in $splListItems)
{
 
writeInfo "web $($web.ServerRelativeUrl) splList $($splList.RootFolder.ServerRelativeUrl) File id : $($splListItem.Id) # $($splListItem.Name) Title: $($splListItem["Title"]) Version: $($splListItem["owshiddenversion"]) _Level: $($splListItem["_Level"]) _IsCurrentVersion: $($splListItem["_IsCurrentVersion"]) _UIVersion: $($splListItem["_UIVersion"]) ver count : $($splListItem.File.Versions.Count)"
#check in file
try
{
if($checkin)
{
$splListItem.File.CheckIn("CheckIn as admin");
}
}
catch
{
WriteError "error CheckIn web $($web.ServerRelativeUrl) splList $($splList.RootFolder.ServerRelativeUrl) File id : $($splListItem.Id) "
}
#publish file
try
{
if($publish)
{
$splListItem.File.Publish("Publish as admin");
}
}
catch
{
WriteError "error Publish web $($web.ServerRelativeUrl) splList $($splList.RootFolder.ServerRelativeUrl) File id : $($splListItem.Id) "
}
#this is a folder
if($splListItem.ContentTypeId.ToString() -eq "0x00C2208B8CE6E1422CADC1C521EAB2A68B")
{
writeInfo "folder file $($splListItem.File.ServerRelativeUrl)"
continue
}
#delete old versions
if($deleteAllVersion -and $splListItem.File -ne $null -and $splListItem.File.Versions -ne $null -and $splListItem.File.Versions.Count -gt 1)
{
$splListItem.File.Versions.DeleteAll();
writeInfo "versions deleted for $($web.ServerRelativeUrl) splList $($splList.RootFolder.ServerRelativeUrl) File id : $($splListItem.Id)"
}
}
$iNumber+=1
$spqQuery.ListItemCollectionPosition = $splListItems.ListItemCollectionPosition;
}while($spqQuery.ListItemCollectionPosition -ne $null)
 
 
$web.Dispose()
 

get script

utils

Sharepoint ajax Without Jquery

On 16/11/2018

var xhr = new XMLHttpRequest();
var url = _spPageContextInfo.webAbsoluteUrl;
if (url === "undefined") {
console.log("_spPageContextInfo.webAbsoluteUrl undefined");
url = "http://siteUrl";
}
//xhr.open('GET', url +"/_api/web/Lists?$select=Id,Title,Hidden,ItemCount");
// /_api/web/lists/getbytitle('Projets')/items?$select=Title,ID,
xhr.open('GET', url + "/_api/web");
//prefer using odata=nometadata to get minimum values and upgrade performances
xhr.setRequestHeader("Accept", "application/json; odata=verbose");
 
xhr.onload = function () {
if (xhr.status === 200) {
var kk = JSON.parse(xhr.responseText);
console.dir(kk);
}
else {
console.dir(xhr);
alert('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
 

get script

In HTML

HTML templates

On 03/11/2018

my html clipboard tool

Sharepoint Rest Base

On 03/11/2018

//Copy file (copyTo) /_api/web/getFileByServerRelativeUrl('/sites/test/Template.xlsx')/copyTo(strNewUrl='/sites/test/Exports/Template_copy_5.xlsx',bOverWrite=true)
 
function getRequestData(req) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + req,
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data) {
console.dir(data);
},
error: function((data) {
console.dir(data);
}
});
}
getRequestData("/_api/web/Lists?$select=Id,Title,Hidden");
 
get script

Set Content Type Field Property

On 22/10/2018

param([string]$webUrl="http://spdev", [string]$contentTypeName="myContenttype", [string]$fieldName="myTitle", [boolean]$required=$true)
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
clear
$web = Get-SPWeb $webUrl
$ct = $web.ContentTypes[$contentTypeName];
$oldSealedValue = $ct.Sealed;
Write-Host "content type Sealed Property $($ct.Sealed)"
if($ct.Sealed)
{
$ct.Sealed = $false;
}
$field = $ct.FieldLinks[$fieldName];
$field.Required = $required;
Write-Host "set field $($fieldName) Required $($ct.Required)"
 
if($oldSealedValue)
{
$ct.Sealed = $true;
}
$ct.Update($true);
$web.Update();
$web.Dispose();
get script

Powershell Upgrade SPFeature

On 12/10/2018

param(
[string]$WebApplicationUrl = "http://fdi-sp2013-1",
$featureId = "6cfcd848-1f9f-4bf0-ac99-c6f2df0fc3fc"
)
##########################################################################
# DECLARATIONS
##########################################################################
#Retourne le chemin
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Get-ScriptDirectory | Push-Location
. .\Utils.ps1
$logFileName = "{0}updateFeature.log" -f (Get-Date -Format "yyyyMMdd_HHmm");
$logFilePath = "$($currentFolder)\Logs\UpgradeFeaturePublishing$($logFileName)"
EnsureLogDirectory $logFilePath
##########################################################################
# MAIN
##########################################################################
$currentUrl = "";
try{
if ($WebApplicationUrl -eq ""){
$WebApplicationUrl = AskForWebApplicationUrl
}
$webApp=Get-SPWebApplication $WebApplicationUrl
$webApp.Sites|Foreach-Object{
$spSite=$_
WriteInfo "Site: $($spSite.Url)"
$site=Get-SPSite $spSite.Url
if($site -ne $null)
{
$feature=Get-SPFeature $featureId
if($feature -ne $null){
$featuresForUpgrade = Get-SPSite $spSite.Url | %{$_.QueryFeatures($feature.Id)}
if($featuresForUpgrade -ne $null){
WriteInfo "Old Version..."
$featuresForUpgrade.Version
$featuresForUpgrade.Upgrade($false)
WriteInfo "New Version..."
$featuresForUpgrade.Version
}
}
}
}
Write-Host -NoNewLine 'Press any key to close...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}catch{
Write-Error -Message $_.Exception.Message
Write-Host -NoNewLine 'Press any key to close...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}finally{
Pop-Location
}

get script

In SQL

Shrink Sql ContentDataBase Log

On 12/10/2018

USE WSS_Content_FDI80;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE WSS_Content_FDI80
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (WSS_Content_FDI80_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE WSS_Content_FDI80
SET RECOVERY FULL;
GO