How to add default associated groups when creating new site

Hi All,
I am trying to create a new subsite in sharepoint 2013 using CSOM (code is mentioned below). But no default groups (MEMBER, VISITOR, OWNER) are getting created in that site. When we try through UI we will got through a page "Set Up Groups
for this Site" where we can specify these details.. Is it possible to do the same (creating default groups together with the site creation) through CSOM or powershell.
CSOM code:
WebCreationInformation creation = new WebCreationInformation();
            creation.Url = "NewSubSite6";
            creation.Title = "NewSubSite6";
            creation.UseSamePermissionsAsParentSite = false;
            Web newWeb = clientContext.Web.Webs.Add(creation);
            //clientContext.Load(newWeb);
            clientContext.ExecuteQuery();
Regards,
Shahabas

Shahbas, here is the code:
private static void SetSecurityOnSubSite(ClientContext clientContext, ListItem item, bool confidential, Web newWeb)
            try
                if (confidential)
                    newWeb.BreakRoleInheritance(false, false);
                    clientContext.ExecuteQuery();
                    Group ownerGroup = default(Group); Group memberGroup = default(Group); Group visitorGroup = default(Group);
                    // web has unique permissions, so create default assosiated groups (owners, members, visitors)
                    if (!newWeb.GroupExists(newWeb.Title + " Owners"))
                        ownerGroup = newWeb.AddGroup(newWeb.Title + " Owners", "", true);
                        clientContext.Load(ownerGroup);
                    if (!newWeb.GroupExists(newWeb.Title + " Members"))
                        memberGroup = newWeb.AddGroup(newWeb.Title + " Members", "", false);
                        clientContext.Load(memberGroup);
                    if (!newWeb.GroupExists(newWeb.Title + " Visitors"))
                        visitorGroup = newWeb.AddGroup(newWeb.Title + " Visitors", "", false);
                        clientContext.Load(visitorGroup);
                    // executequery in order to load the groups if not null
                    clientContext.ExecuteQuery();
                    newWeb.AssociateDefaultGroups(ownerGroup, memberGroup, visitorGroup);
                    newWeb.AddPermissionLevelToGroup(newWeb.Title + " Owners", RoleType.Administrator);
                    newWeb.AddPermissionLevelToGroup(newWeb.Title + " Members", RoleType.Contributor);
                    newWeb.AddPermissionLevelToGroup(newWeb.Title + " Visitors", RoleType.Reader);
                    FieldUserValue userValueCreatedBy = item[Constants.Projects.CreatedBy] as FieldUserValue;
                    User createdByUser = clientContext.Web.EnsureUser(userValueCreatedBy.LookupValue);
                    clientContext.Load(createdByUser);
                    clientContext.ExecuteQuery();
                    UserCreationInformation createdByUserCI = new UserCreationInformation();
                    createdByUserCI.LoginName = createdByUser.LoginName;
                    ownerGroup.Users.Add(createdByUserCI);
                    clientContext.ExecuteQuery();
                    foreach (FieldUserValue userValue in item[Constants.Projects.ProjectTeam] as FieldUserValue[])
                        User user = clientContext.Web.EnsureUser(userValue.LookupValue);
                        clientContext.Load(user);
                        clientContext.ExecuteQuery();
                        UserCreationInformation userCI = new UserCreationInformation();
                        userCI.LoginName = user.LoginName;
                        memberGroup.Users.Add(userCI);
                    clientContext.ExecuteQuery();
            catch (Exception)
                throw;
Reference link: 
http://sharepoint.stackexchange.com/questions/116682/how-to-create-a-group-in-a-subweb-using-csom
Thanks, Pratik Shah

Similar Messages

  • How to add an existing content database to new Site collection

    Hi All,
    Can anyone help to figure out how can I add existing content database to a new site collection in SharePoint 2013 foundation.
    We have more than 40 site collections under one web application, and only one site collection is returning 404 error. When checked in the central admin to view all site collections, the details on the right side of the site is not visible, and unable
    to delete it. The database is not corrupt, as I tried to add the same content database to a new web application, and it works perfectly in a new web app.
    As we couldn't find any solution, the only option we thought of was to blow the site collection and create a new one and add the exisiting database, but I am unaware as to how can I add existing database to new create site collection. Can anyone help
    me with this please?
    Regards,
    DJ

    It's working....
    The current database was corrupt I guess, (not sure though). Took old backup file and tested to see if it's working. After the test was successful...
    Removed the current database in CA
    Delete the current database in SQL server
    Restored the working backup file in SQL server
    Added the content db in CA
    That's it... the site collection is working now...
    Regards,
    DJ

  • Changing default Target Group when creating transports.

    Hi All,
    We have 4 different target groups for the transports created in development systems. I would like to make one transport group default which is mainly used by majority of consultants.
    How to make one transport group default during creation of transport.
    Regards,
    Krishna

    And to just make it more clear :
    and here is the SAP help on the subject:
    Transport Layer in ABAP Workbench
    The Change and Transport System supports the distribution of development work on large projects across multiple SAP Systems.
    The packages in each development system are grouped into one transport layer.
    The transport layer determines whether objects are assigned to a local or transportable change request.
    Use
    Each of your SAP development systems is assigned a transport layer as its standard transport layer. If you use Extended Transport Control, you can assign different standard transport layers to certain clients.
    You can define at the most one consolidation target for each SAP System and transport layer.
    When you create a package, it is assigned the standard transport layer of the SAP System.
    If you want to assign a different transport layer to a package, you require the administration authorization for the Change and Transport System.
    The objects in a package automatically have the transport attributes defined for the corresponding transport layer.
    If a consolidation route originating in their SAP System is defined, then the objects are assigned to a transportable request, and transported into the consolidation target when it is released.
    If a consolidation route is not defined, the objects are assigned to a local request, and are not transported.
    Customizing settings are not assigned to a package. They have the transport attributes of the standard transport layer of the system or client.
    It is best to assign a package a standard transport layer for which a consolidation route originating in the development system is defined.
    To display and maintain the transport layers and routes, use the Transport Management System (transaction STMS).
    Only the system adminstrator can make changes.
    Caution:
    The tables TSYST, DEVL, TWSYS, TASYS are no longer productive as of Release 4.0A and cannot be maintained.
    Best regards,
    Menelaos

  • DW crashes when creating new site

    I have tried to build a new site---it was done in Front Page
    2003 originally. The "Updating the site cache" stops at 1252 every
    time. I have deleted the file that it stopped at; and it stopped at
    update 1252 again but with a different file name.
    The error is ModName: msvcr80.dll

    Knight240 posted in macromedia.dreamweaver
    > I have tried to build a new site---it was done in Front
    Page 2003
    > originally. The "Updating the site cache" stops at the
    same file
    > each time. It is an html file with some javascript in
    it. What
    > about the html file would cause Dreamweaver to crash?
    The error
    > is ModName: msvcr80.dll
    Any chance that file is exactly 8,192 bytes or a multiple
    thereof?
    http://groups.google.com/group/macromedia.dreamweaver/tree/browse_frm/thread/d6924ae6108de fa1/3660f45fc25a5f28?rnum=1&q=powers+known+%22file+size%22+group%3Amacromedia.dreamweaver& _done=%2Fgroup%2Fmacromedia.dreamweaver%2Fbrowse_frm%2Fthread%2Fd6924ae6108defa1%2F3660f45 fc25a5f28%3Ftvc%3D1%26q%3Dpowers%2Bknown%2B%2522file%2Bsize%2522%2Bgroup%253Amacromedia.dr eamweaver%26#doc_94021c0aad36d511
    [Tiny URL]
    http://preview.tinyurl.com/6rkpgh
    Mark A. Boyd
    Keep-On-Learnin' :)

  • How to set country field automatically when creating new customer??

    Hi Gurus,
    when customer number is entered in account identification, if there is no matching account, a new one is created. While creating , in the screen there is an country field and I want to set this field to a fixed value of our country. How can I do this??

    Hi everybody,
    I got a simple question. Can I use BADI: BADI_CRM_BP_UIU_DEFAULTS of Enhancement Spot CRM_UIU_BP_ENHANCEMENT
    to make the country 'US' as a default value for component: ICCMP_BP_DETAIL  (NOT: BP_HEAD)?
    Component ICCMP_BP_DETAIL is Interaction Center.
    If not which Badi or way I can use to make country 'US' as default value?
    Best Regards
    Oliver
    Edited by: Oliver Schultze on Dec 9, 2010 4:33 PM

  • Testing site when creating new site

    I am trying to setup a new site for DW8. Looks easy enough
    but I keep getting this one error message.
    Dreamweaver cannot use the prefix you entered to display live
    data. (error 12029)
    this is the data that I have entered to setup the site on the
    basics tab:
    what would you like to name your site?
    1purposebethel
    What is the HTTP adress (URL) of your site?
    http://www.1purposebethel.org/
    Yes I want to use a server technology
    PHP MySQL
    Edit and test locally (my testing server is on this computer)
    C:\inetpub\wwwroot\1purposebethel\
    What URL would you use to browse to the root of your site?
    http://localhost/1purposebethel/
    test URL message:
    Dreamweaver cannot use the prefix you entered to display live
    data. (error 12029)
    can you advise?
    Kevin

    Resolved
    Thank You
    Kevin
    "kevin raleigh" <[email protected]> wrote in
    message
    news:f42e75$kc$[email protected]..
    > I am trying to setup a new site for DW8. Looks easy
    enough but I keep
    getting
    > this one error message.
    > Dreamweaver cannot use the prefix you entered to display
    live data.
    (error
    > 12029)
    >
    > this is the data that I have entered to setup the site
    on the basics tab:
    >
    > what would you like to name your site?
    > 1purposebethel
    >
    > What is the HTTP adress (URL) of your site?
    >
    http://www.1purposebethel.org/
    >
    > Yes I want to use a server technology
    > PHP MySQL
    >
    > Edit and test locally (my testing server is on this
    computer)
    > C:\inetpub\wwwroot\1purposebethel\
    >
    > What URL would you use to browse to the root of your
    site?
    >
    http://localhost/1purposebethel/
    >
    > test URL message:
    >
    > Dreamweaver cannot use the prefix you entered to display
    live data.
    (error
    > 12029)
    >
    > can you advise?
    > Kevin
    >

  • Project Server 2010: PWA Removing Default Project Site Security Groups When Creating a New Project

    I looked for this specific issue with Project Server 2010/PWA/SharePoint and could not find an exact answer... hopefully someone can help.
    We are currently using Project Server 2010 and have a number of project site templates that are used dependent upon the enterprise project type selected. Each of these project site templates have unique permissions which should create the default security
    groups on the project site upon publishing/syncing:
    <Project Name> Members
    <Project Name> Owners
    <Project Name> Visitors
    <Project Name> Project Managers (Project Web App Synchronized)
    <Project Name> Team Members (Project Web App Synchronized)
    Web Administrators (Project Web App Synchronized)
    Whether a user creates a project through PWA or Project Pro 2010 and imports the project into PWA, we get a weird result in the Site Permissions of the newly created project site. PWA will remove all default security groups from the project site template
    and add a whole list of users in the Site Permissions list without groups. 
    Once the project is published and the project site is created, we can then go back and add those default security groups back in the project Site Permissions and even add a couple of custom groups without them being removed on all subsequent project syncs
    or publishing. 
    How do we get PWA to not overwrite the project site templates' security groups and place each user in the proper default security groups? At the same time, how is PWA adding a number of users into the Project Site Permissions?
    Thanks in advance.

    Paul,
    Thanks for that information. Right now we are using the Test environment to turn the Auto-sync feature back on. I suspect that the reason this is happening is due to PWA groups/categories/security templates. There may be more than one PWA group that is "overwriting"
    the default project site groups upon initial creation of the project. We will look further into the security settings to tighten up the policies. 

  • How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?

    How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?
    Hi,
    I do generate XML-Files by using DBMS_XMLGEN with output by UTL_FILE
    but it seems, the xml-Datafile I get on end is not really UTF-8 encoding
    ( f.ex. cannot verifying it correct in xmlspy )
    my dbms is
    NLS_CHARACTERSET          = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET     = AL16UTF16
    NLS_RDBMS_VERSION     = 10.2.0.1.0
    I do generate it in this matter :
    declare
    xmldoc CLOB;
    ctx number ;
    utl_file.file_type;
    begin
    -- generate fom xml-view :
    ctx := DBMS_XMLGEN.newContext('select xml from xml_View');
    DBMS_XMLGEN.setRowSetTag(ctx, null);
    DBMS_XMLGEN.setRowTag(ctx, null );
    DBMS_XMLGEN.SETCONVERTSPECIALCHARS(ctx,TRUE);
    -- create xml-file:
    xmldoc := DBMS_XMLGEN.getXML(ctx);
    -- put data to host-file:
    vblob_len := DBMS_LOB.getlength(xmldoc);
    DBMS_LOB.READ (xmldoc, vblob_len, 1, vBuffer);
    bHandle := utl_file.fopen(vPATH,vFileName,'W',32767);
    UTL_FILE.put_line(bHandle, vbuffer, FALSE);
    UTL_FILE.fclose(bHandle);
    end ;
    maybe while work UTL_FILE there is a change the encoding ?
    How can this solved ?
    Thank you
    Norbert
    Edited by: astramare on Feb 11, 2009 12:39 PM with database charsets

    Marco,
    I tryed to work with dbms_xslprocessor.clob2file,
    that works good,
    but what is in this matter with encoding UTF-8 ?
    in my understandig, the xmltyp created should be UTF8 (16),
    but when open the xml-file in xmlSpy as UTF-8,
    it is not well ( german caracter like Ä, Ö .. ):
    my dbms is
    NLS_CHARACTERSET = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET = AL16UTF16
    NLS_RDBMS_VERSION = 10.2.0.1.0
    -- test:
    create table nh_test ( s0 number, s1 varchar2(20) ) ;
    insert into nh_test (select 1,'hallo' from dual );
    insert into nh_test (select 2,'straße' from dual );
    insert into nh_test (select 3,'mäckie' from dual );
    insert into nh_test (select 4,'euro_€' from dual );
    commit;
    select * from nh_test ;
    S0     S1
    1     hallo
    1     hallo
    2     straße
    3     mäckie
    4     euro_€
    declare
    rc sys_refcursor;
    begin
    open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
    dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
    end;
    ( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
    open in xmlSpy is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <S0>1</S0>
    <S1>hallo</S1>
    </ROW>
    <ROW>
    <S0>2</S0>
    <S1>straޥ</S1>
    </ROW>
    <ROW>
    <S0>3</S0>
    <S1>m㢫ie</S1>
    </ROW>
    <ROW>
    <S0>4</S0>
    <S1>euro_€</S1>
    </ROW>
    </ROWSET>
    regards
    Norbert

  • How to add a dba group in Unix after Installation

    I need help in figuring out how to add a dba group, which one would do prior to installation, but how can one do it after installation?
    I need to have a group that will have people allowed to start and stop oracle. Is this possible to modify to do after installation?
    Please help... Thank you.

    Thanks for the advice. I am looking in my config.s file and this is what i see..
         .section     ".text",#alloc,#execinstr
    /* 0x0000     7 */          .file     "x.c"
         .section     ".data",#alloc,#write
    /* 0x0000     9 */          .global     ss_dba_grp
    /* 0x0000     10 */          .align     8
         .global ss_dba_grp
    ss_dba_grp:
    /* 0x0000     17 */          .align     8
    /* 0x0000     18 */          .xword     (.L12+0)
    /* 0x0004     24 */          .align     8
    /* 0x0004     25 */          .xword     (.L13+0)
    /* 0x0008     26 */          .type     ss_dba_grp,#object
    /* 0x0008     27 */          .size     ss_dba_grp,16
         .section     ".rodata1",#alloc
    /* 0x0008     13 */          .align     8
    .L12:
    /* 0x0008     15 */          .ascii     "dba\0"
    /* 0x0014     20 */          .align     8
    .L13:
    /* 0x0014     22 */          .ascii     "dba\0"
    What should i change?

  • How to inactive checking available budget when creating reservation

    Dear SAP Guru,
    Need your advice in how to inactive checking available budget when creating reservation under Project system and Investment management module
    Many thanks in advance.
    Nies

    ok

  • How to install certifcate to tmg when create web listener

    how to install certifcate to tmg when create web listener

    Short comment that may help, if you've added the cert while the TMG MMC is open you need to refresh the MMC on the node second to the top (right-click on server/array name and select refresh) or simply restart the MMC.
    Then create the web listener as desired.
    As always you need a cert with the EKU of server authentication (regular web server cert will do) with the corresponding private key and the cert needs to be trusted on the computer where TMG is installed.
    Hth, Anders Janson Enfo Zipper

  • Since the upgrade to IOS7, the default phone label when adding new contacts on my iPhone 5 is "Radio".  Previously the default was "Mobile" how can this be changed back to "Mobile"?

    Since the upgrade to IOS7, the default phone label when adding new contacts in my iPhone 5 is "Radio". Previously the default was "Mobile". It is a hassle as when my iPhone contacts are synched with Outlook via Exchange, the phone number I've entered on the iPhone doesn't show on the default Outlook view as it is a "Radio" number rather than a "Mobile", "Work", "Home", etc number. It is still stored both on the iPhone & in Outlook & I can still use the number to phone or SMS, it is just incorrectly labelled & hence the source of frustration.
    Apple please return the default to "Mobile" or alternatively find a way we can alter the default ourselves to "Mobile" or "Home" etc.

    The following previous discussion may help: https://discussions.apple.com/message/23846793#23846793

  • Use a Custom Page Layout When Creating [[new pages]] in Enterprise Wiki

    I have followed a few different blogs and I've been able to create a custom wiki content type and create a new page layout based off of that content type. I've also set my site so that my new layout is the default page layout. This works when creating
    new pages on the site but when i try to create a new wiki page --> [[new page]], I'm still getting the typical blank wiki template. How on earth do i get my page layout to sync with creating a new wiki page?

    Hi,
    For your issue, go to Site Actions > Site Settings > Page layouts and site templates (Under Look and Feel).
    Pages in this site can only use the following layouts: add custom wiki template.
    Select default page layout: choose custom wiki template.
    Besides, here is a blog, you can use as a reference:
    http://blog.henryong.com/2010/06/08/how-to-create-custom-sharepoint-2010-page-layouts-using-sharepoint-designer-2010/
    Best Regards,
    Lisa Chen

  • How & where to use Java script to create new button in object detail page

    Hi All,
    I want to create "New/Add button" in object detail page. If i am not wrong i need to use java script for that but could you please let me know how & where to use Java script to create new button in object detail page in CRMOD.
    Thanks in advance.
    Regards,
    Manish

    Any related object on the detail page should have an "Add" or "New" or both buttons by default - This is vanilla functionality and will do the required action.
    If you want to modify this behaviour and do something tricky you will potentially have to go for javascript. You should add the javascript on a custom web tab on that Object.
    Admin --> Application Customization --> Contact -->Contact Web Applet
    Now, add your javascript in the code area, after you select the type = HTML for this web applet, expose this web applet on the Contact detail layout and your javascript will be invoked whenever this page is loaded.
    Check this online document to see how javascript can be embedded in CRM on Demand http://helponmyproject.com/TTOCOD/
    Cheers!
    Royston

  • When a new site is created can a user name and password be generated for it automatically?

    I have a work request  from a manager that is asking, when a new site is created (via workflow), that a generic user name and password be created just for that site?
    If it is possible I would like for it to be created at the same time as the site be being created or do I need to wait until after the site is created and then trigger a workflow to create the generic  user  account?
    this account is only needed to do one thing.. upload documents to a folder.
    of course there can be multiple  sites being built at one time and would like for this to be auto generated....  and possible be in a  hidden list so I can include the info in a workflow email letting the receiver of the email know that
    they need to use this specific user name and password just for this site.

    Hi SPSAdminTC,
    According to your description, my understanding is that you want to create sites and grant users permissions on the sites via workflow in SharePoint 2013.
    Users are stored in AD, before you grant site permissions to them, the name and password have existed in AD users and groups. So, you need to add the users into AD before you grant permissions to them.
    In SharePoint 2013 Designer, you can use REST API to create site and assign permissions to users. You can use Send Email action to send email to users and customize the body of the email.
    More information, please take a look at:
    http://rogereriksen.wordpress.com/2013/05/24/create-a-sharepoint-site-using-rest-in-workflow-with-sharepoint-designer/
    http://www.sharepointbay.com/assign-permission-rest-api/
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

Maybe you are looking for

  • My camera on my iPhone 4S is not working properly.  Can you help?

    It will work for brief seconds but then closes and freezes

  • How to save each section report into different excel sheet?

    Hi all How to save each section report into different excel sheet? I have a report in which there are 4 sections north south west east now i need to save north in excel sheet 1 , south in sheet2, west in sheet3, and east in sheet4. under each section

  • PS Touch Tutorial

    Good evening peeps, happy hump day :) I was researching and came across that PS Touch Tutorials are only for iPads and Tablets. Would this feature be available anytime soon? I use a Galaxy Note 3 which is somewhat like a tablet with Pen. Ps - love th

  • Report error when using combo box and one text field is empty

    I'm building an interactive pdf in adobe pro 9. My problem is the following: I have one text field where you can enter a numeric code and that is used to populate another text field when I choose an option on one combo box.For example: suppose I writ

  • TLS/SSL in Contribute CS 5?

    There seems to be a disconnect between the FTP protocols used by Dreamweaver and Contribute. I just downloaded the DM CS5.5 to see if it would work with FTP over SSL/TLS and it does. However when you try to connect using Contribute, all you get is an