当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 禁用 SharePoint Online 列表和库中的“新建文件夹”

作者:精品下载站 日期:2024-12-14 21:08:48 浏览:13 分类:玩电脑

禁用 SharePoint Online 列表和库中的“新建文件夹”


要求:在 SharePoint Online 列表或文档库中禁用文件夹创建。

如何防止在 SharePoint Online 中创建文件夹?

您想要禁用 SharePoint Online 列表和库中的“新建文件夹”按钮吗?在这篇博文中,我将向您展示如何做到这一点。如果您想阻止用户轻松创建新文件夹,这会很有帮助。继续阅读分步说明。

可以在“新建文件夹”选项打开的任何 SharePoint 列表或库上创建文件夹。默认情况下,库和列表中启用文件夹。与 Windows 资源管理器中的文件夹类似,SharePoint 文件夹用于组织文件。要禁用 SharePoint 列表或库中的文件夹创建:

  1. 转到列表或库设置>>单击“高级设置”。
  2. 在“文件夹”部分下,将“使‘新文件夹’命令可用?”设置为“否”。

    [玩转系统] 禁用 SharePoint Online 列表和库中的“新建文件夹”

这将禁用 SharePoint Online 中的“新建文件夹”选项。

PowerShell 阻止在 SharePoint Online 中创建文件夹

要禁用 SharePoint Online 中的文件夹,请使用以下 PowerShell:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Disable-SPONewFolder($SiteURL,$ListName)
{
    Try
    {
        #Get Credentials to connect
        $Cred= Get-Credential

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Get the List
        $List=$Ctx.Web.Lists.GetByTitle($ListName)

        #Disable "New Folder" 
        $List.EnableFolderCreation=$False

        #Apply the settings to list
        $List.Update()
        $Ctx.ExecuteQuery()

        Write-host -f Green "New Folder Disabled for the List '$ListName'!"
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}

#Set Parameters
$SiteURL="https://Crescent.sharepoint.com"
$ListName="Team Projects"

Disable-SPONewFolder -SiteURL $SiteURL -ListName $ListName

使用 PnP PowerShell 在 SharePoint Online 中禁用文件夹创建:

让我们使用 PnP PowerShell 脚本限制 SharePoint Online 中的文件夹创建。


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Team Projects"

#Get Credentials to connect
$Cred = Get-Credential

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Credentials $Cred
    
    #Disable Folder Creation
    Set-PnPList -Identity $ListName -EnableFolderCreation $False
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

总之,通过执行以下步骤,您可以快速禁用用户在 SharePoint Online 中创建新文件夹的功能。如果您想保持一致的文件夹结构或防止用户弄乱您的文档库,这会很有用。请记住,此更改将影响访问此文档库的所有用户,因此如有必要,请务必将更改传达给您的团队。

经常问的问题:

SharePoint 中的库和文件夹有什么区别?

在 SharePoint 中,库是文档的容器,而文件夹是库中可以保存文档或其他文件夹的容器。本质上,库是可以包含多个文件夹的更高级别的组织结构,而文件夹是库内的子结构。此外,库通常具有版本控制、视图、元数据等功能,而文件夹则没有。一般来说,建议在 SharePoint 中使用库而不是文件夹,以获得更好的组织、可搜索性和安全性。

如何使用 PowerShell 删除 SharePoint Online 中的文件夹?

若要使用 PowerShell 删除 SharePoint Online 中的文件夹,请使用 Connect-PnPOnline cmdlet 连接到 SharePoint Online 网站,然后使用 Remove-PnPFolder cmdlet 删除该文件夹。例如,以下 PowerShell 脚本从 SharePoint Online 网站中删除名为“Folder1”的文件夹:
Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite -Credentials (Get-Credential)
Remove-PnPFolder -Name “Folder1” -Folder “Shared Documents”
请注意,您需要向该文件夹提供权限才能将其删除。此外,删除文件夹还将删除其中的所有文件和子文件夹!
详细信息:使用 PowerShell 删除 SharePoint Online 中的文件夹

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯