0

I need to show all content types in a drop-down or as hyperlinks along with description on custom .aspx page. When user selects any type, respective New Form should open to create a new document/list out of that content type.

Please help me to achieve this in SharePoint 2010 using Designer.

0

This will be very hard for Site ContentTypes, since there could be multiple Lists, which support it. - So no New Form. You could however try to achieve this for a single list, like this:

<div>               
        <input id="TestBtn" name="Button1" type="button" value="Script test" onclick="getContentTypesOfSite()" /><br />
        <br/ >
        <table id="testTable" style="width:100%; border: 1px solid black;">
        <thead>
            <tr>
                <th>Name</th>
                <th>Description</th>
                <th>Link</th>
                <th>GUID</th>
            </tr>
        </thead>
        <tbody></tbody>
        </table>
        <br />
    </div>

<script type="text/javascript">
        var debug_mode = 1;

        var thisSiteUrl = L_Menu_BaseUrl;

        function getContentTypesOfSite(siteUrl) {
            if (SP) {
                var clientContext = new SP.ClientContext(siteUrl);
                var oList = clientContext.get_web().get_lists().getByTitle("Aktionsliste");
                this.collList = oList.get_contentTypes();


                clientContext.load(collList, 'Include(Name, Id, Description, Hidden, Group, NewFormUrl)');

                clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteQuerySucceeded), Function.createDelegate(this, this.onSiteQueryFailed));
            }
        }

        function onSiteQuerySucceeded() {

            var listInfo = '';

            var listEnumerator = collList.getEnumerator();
            $('#testTable').find('tbody').empty();

            while (listEnumerator.moveNext()) {
                var oContentType = listEnumerator.get_current();

                if ((!oContentType.get_hidden() === true) && (oContentType.get_group() != '_Hidden')) {
                    var link = '/Lists/Aktionsliste/NewForm.aspx';
                    var row;
                    if (oContentType.get_newFormUrl() == "") 
                        row = $('<tr><td>'+oContentType.get_name()+'</td><td>'+oContentType.get_description()+'</td><td><a href="'+link+'">New Form</a></td><td>'+oContentType.get_id()+'</td></tr>');
                    else
                        row = $('<tr><td>'+oContentType.get_name()+'</td><td>'+oContentType.get_description()+'</td><td><a href="'+oContentType.get_newFormUrl()+'">New Form</a></td><td>'+oContentType.get_id()+'</td></tr>');
                    $('#testTable').find('tbody').append(row);
                }
            }

        }

        function onSiteQueryFailed(sender, args) {
            console.log(JSON.stringify(args));
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }


    </script>

Please don't forget to insert/enable jQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.