ユーザーがフォルダーを作成しますが、フォルダーを削除しないようにするにはどうすればよいですか?
-
16-10-2019 - |
質問
ユーザーがフォルダーを作成できるようにするにはどうすればよいですが、SharePoint 2007のフォルダーを削除しませんか?
解決
次のコードを使用してイベント受信者を作成し、ドキュメントライブラリにイベント受信者を添付します。
private bool CanDeleteFolder(SPWeb web)
{
// check to see if the user is in the owners group
SPUser user = web.CurrentUser;
if (!user.IsSiteAdmin)
{
return false;
}
else
{
//admins can delete folder
return true;
}
}
public override void ItemDeleting(SPItemEventProperties properties)
{
try
{
if (properties.AfterProperties["ContentType"].ToString() == "Folder")
{
using (SPWeb web = properties.OpenWeb())
{
if (!CanDeleteFolder(web))
{
properties.Cancel = true;
properties.ErrorMessage = "Cannot add folder at this location. Please select a sub folder";
properties.Status = SPEventReceiverStatus.CancelWithError;
}
}
}
}
catch { }
}
他のヒント
または、削除オプションを許可しないカスタム許可レベルを作成し、目的のユーザーのライブラリにその許可レベルを適用します。アイテムを追加/編集することはできますが、削除できません。イベントレシーバーは、単純な権限の変更のために過剰になりそうです。
カスタムイベントレシーバーを使用してオンデレットをトラップして、現在のアイテムが削除されているかどうかを確認し、その場合はキャンセルして、そうしている間にエラーメッセージを提示します。
所属していません sharepoint.stackexchange