写在前面

最近一直在搞通过Rest api的方式读取sharepoint文档库中的内容。有些地方需要注意,在此做下记录。

步骤

启动sharepoint服务器的服务

这里可以使用脚本的方式进行启动,脚本如下:

获得管理账户,比如你的账户为sp\administrator

$account = Get-SPManagedAccount "sp\administrator"

$subscriptionSettingsServices = Get-SPServiceInstance | where {$_.TypeName -like "Microsoft SharePoint Foundation Subscription Settings Service"} | ForEach-Object {
$subscriptionSettingsService = $_;
if($subscriptionSettingsService.Status -ne "Online") {
Write-Host "start Subscription Settings Service ,Id:" + $_.Id
Start-SPServiceInstance $subscriptionSettingsService | Out-Null
}
else{
Write-Host "Subscription Settings Service has started,Id:" + $_.Id
}
} Write-Host "starting Config Subscription Settings Service..."
$appPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account
$appSubSvc = New-SPSubscriptionSettingsServiceApplication –ApplicationPool $appPoolSubSvc –Name SettingsServiceApp –DatabaseName SettingsServiceDB_tmp
$proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $appSubSvc $AppManageServices = Get-SPServiceInstance | where {$_.TypeName -like "App Management service"} | ForEach-Object {
$AppManageService = $_;
if($AppManageService.Status -ne "Online") {
Write-Host "start run App Management service ,Id:" + $_.Id
Start-SPServiceInstance $AppManageService | Out-Null
}
else{
Write-Host "App Management service has started,Id:" + $_.Id
}
} Write-Host "App Management service..."
$appPoolSubSvc = New-SPServiceApplicationPool -Name AppManagementServiceAppPool -Account $account
$appSubSvc = New-SPAppManagementServiceApplication –ApplicationPool $appPoolSubSvc –Name AppManagementServiceApp –DatabaseName AppManagementServiceDB_tmp
$proxySubSvc = New-SPAppManagementServiceApplicationProxy –ServiceApplication $appSubSvc Write-Host "config success!"

运行成功后检查下列服务是否启动:

检查下列服务是否存在:

准备证书

创建并导出自签名的证书

导出公钥证书

注册APP并授权

注册app的脚本

$serviceConfig = Get-SPSecurityTokenServiceConfig
$serviceConfig.AllowOAuthOverHttp = $true
$serviceConfig.Update()
$appDisplayName = "Lenovo_Documents"
$clientID = "11c825ca-5b9c-4a02-857d-d0bc9690c327"
$targetSiteUrl = "http://sp2013/"
$targetSite = Get-SPSite $targetSiteUrl
$realm = Get-SPAuthenticationRealm -ServiceContext $targetSite
$fullAppPrincipalIdentifier = $clientID + "@" + $realm
Write-Host "Register new app principal"
$registeredAppPrincipal = Register-SPAppPrincipal -NameIdentifier $fullAppPrincipalIdentifier -Site $targetSite.RootWeb -DisplayName $AppDisplayName
Set-SPAppPrincipalPermission -site $targetSite.RootWeb -AppPrincipal $registeredAppPrincipal -Scope SiteCollection -Right FullControl -EnableAppOnlyPolicy

注册发布者

#Register a trusted security-token issuer

$targetSiteUrl = "http://sp2013/"
$publicCertificatePath = "C:\Certs\Lenovo_Documents.cer"
$issuerID = "7c444f28-03be-445f-8Dfc-0af2869b23cd"
$targetSite = Get-SPSite $targetSiteUrl
$realm = Get-SPAuthenticationRealm -ServiceContext $targetSite
$realm $registeredIssuerName = $issuerID + "@" + $realm
$publicCertificate = Get-PfxCertificate $publicCertificatePath
Write-Host "Create token issuer"
$secureTokenIssuer = New-SPTrustedSecurityTokenIssuer -Name $issuerID -RegisteredIssuerName $registeredIssuerName -Certificate $publicCertificate -IsTrustBroker iisreset

开发app,消费sharepoint数据

创建网站

添加引用

加入TokenHelper.cs

配置Web.Config
注意下列标记值,应与之前步骤配置的值一致。注意,在下面的对应的guid,应与注册时候使用的guid相同。

如预期,通过REST API 返回JSON数据

总结

如果在sharepoint的本地环境中调试通过,然后就是通过odata方式获取,或者筛选自己需要的数据了。

最新文章

  1. C++多线程の条件变量
  2. IOS 错误 [UIWebView cut:]: unrecognized selector sent to instance
  3. [No000044]你是否还傻到把最好的留在最后?
  4. Javascript添加事件的addEventListener()及attachEvent()区别分析,事件委托
  5. http的响应对象
  6. 013医疗项目-模块一:加入工具类ResultUtil
  7. HTML+css实现图片全屏
  8. 快书包CEO徐智明反思:我犯下哪些错误
  9. POJ 3045 Cow Acrobats (贪心)
  10. 机器学习笔记-1 Linear Regression(week 1)
  11. 把ipad作为电脑的第二显示器
  12. struts2 上传与下载
  13. 解决flutter的image_cropper组件引入报错问题
  14. JS----对象的合并与克隆
  15. Android为TV端助力 eclipse出现感叹号的解决办法
  16. java_注解
  17. spring4.0之八:Groovy DSL
  18. Trie树的数组实现原理
  19. JS之ClassName属性使用
  20. python---django中模板渲染(csrf令牌使用,自定义模板函数)

热门文章

  1. boost高质量随机数库 zhuan
  2. Electron "jQuery/$ is not defined" 解决方法
  3. leetcode 翻转二叉树
  4. AndroidStudio连不上Android设备真机
  5. html实现滚动播报(原生JS实现)
  6. css 文本超出范围显示省略号
  7. python3+requests+unittest:接口自动化测试(一)
  8. php字符串统计次数的各种方法(转)
  9. Atom选中多行操作
  10. Js强制转换