寻找如何将许多Powerpoint共享点PnP转换为C#
例子: Connect-PnPOnline
一些Powershell
$PasswordAsSecure = ConvertTo-SecureString $Password -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential ($UserName , $PasswordAsSecure)
Connect-PnPOnline -Url $SiteUrl -Credentials $Credentials
$RootSiteContext = Get-PnPContext
# Determine the SharePoint version
$ServerVersion = (Get-PnPContext).ServerLibraryVersion.Major
为此要在C#应用程序中?
这是一些可以“运行”的更特定的powershell,但是github示例库并没有那么大的帮助。
Connect-PnPOnline -Url $hubUrl -Credentials $O365Credentials
$sc = Get-PnPSite
$w = Get-PnPWeb
$baseRelUrl=$w.ServerRelativeUrl
if (-not $baseRelUrl ) {
throw "hub site isn't created"
}
PnP PowerShell将很多内容隐藏起来,以使你轻松使用。
要将代码修改为C#,需要按如下所述编写:
var siteUrl = "https://your-sitecollection-url";
var userName = "userName";
var password = "password";
using (ClientContext clientContext = new ClientContext(siteUrl))
{
SecureString securePassword = new SecureString();
foreach (char c in password.ToCharArray())
{
securePassword.AppendChar(c);
}
clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
clientContext.ExecuteQuery();
var ServerVersion = clientContext.ServerLibraryVersion.Major;
var site = clientContext.Site;
var web = clientContext.Site.RootWeb;
clientContext.Load(web, w => w.ServerRelativeUrl);
clientContext.ExecuteQuery();
var serverRelativeUrl = clientContext.Site.RootWeb.ServerRelativeUrl;
}
要执行此代码,你的项目中将需要Microsoft.SharePointOnline.CSOM nuget包。