ShareFactoryNewShareToGroup Method (IContext, String, Int32, IGroup, NullableInt32, NullableGuid) |
Namespace: AskiaPortalCmn
public static IShare NewShareToGroup( IContext context, string objectType, int objectId, IGroup group, Nullable<int> surveyId = null, Nullable<Guid> moduleGuid = null )
Create a new share for current the module `template` object and save it
var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D")); var contextValidation = context.Validate(); if (!contextValidation.Success) { throw contextValidation.Exception; } // Sharing information int templateId = 12; IGroup targetGroup = GroupFactory.FindById(context, 4); if (targetGroup == null) { Console.Error.WriteLine("Could not find the specified group"); return; } var share = ShareFactory.NewShareToGroup(context, "template", templateId, targetGroup); if (share == null) { Console.Error.WriteLine("Could not create this share"); return; } share.Permission = AccessLevel.ReadOnly; share.CanReshare = false; var saveResult = share.Save(); if (saveResult.Success) { Console.WriteLine("The share (Id={0}) was successfully saved", share.Id); } else { Console.Error.Write(saveResult.Exception.Message); }