Pergunta

When create a publishing page in SharePoint 2013, you select the content type/page layout, provide name and url, and then when you create the page, say MyHomePage.aspx, it just redirects to the Page library - AllItems View page. Is it possible to redirect to MyHomePage.aspx in edit mode ?

Foi útil?

Solução

Yes, you can totally do this, but not with the OOB "Add a Page" link. You'll need to provide a direct link to the CreatePage page with the Content Type ID specified via the query string. You also need to have your desired page layout bound to that content type. You can surface the link in a custom Site Action or some other UI action.

The link would look something like this:

window.location = "https://yourtenant.sharepoint.com/sites/yoursite/_layouts/15/CreatePage.aspx?ContentTypeId=0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D007B343FEF28E8BB4AA7E872750679F7A1003F19B3B4862CEE468966162498747811"

I tested this in both SharePoint Online and SP Server 2013. I can't explain why it works this way and not with the OOB method, but it does.

When you request the page like this your correct content type and page layout will be pre-selected. After completing the form you'll get redirected to the new page in edit mode.

Note that the list content type IDs will be different from site to site, so if you plan to deploy this to multiple sites you'll have some additional work to do to fetch that ID.

Outras dicas

I've just worked out the following script on my SP2010 VM.
Put that JavaScript code at the end of the <head> section of your System (Default) master page (use SharePoint Designer for instance to edit the current Default master page):

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.0.min.js"></script>

<script type="text/javascript">

$( document ).ready(function() {
    var currentAddress = window.location.pathname; 
    if (currentAddress.toLowerCase().indexOf('/createpage.aspx') == -1) // not the creation page page
        return;

    $("input[id$='buttonCreatePage']").each(function() {
        // The OK button
        var $OKButton = $(this);

        var previousClickHandler = this.onclick;
        this.onclick = null;

        // New click handler
        $OKButton.click(function() {
            var currentAction = $("form").attr('action');

            var newPageUrl = _spPageContextInfo.webServerRelativeUrl;
            if(!newPageUrl.endsWith('/'))
                newPageUrl = newPageUrl + "/";
            newPageUrl = newPageUrl + $("[id$='parentUrlLabel']").text();
            newPageUrl = newPageUrl + $("input[id$='urlNameTextBox']").val() + ".aspx?ControlMode=Edit";

            var newAction = UpdateQueryString("Source", newPageUrl , currentAction);
            $("form").attr('action', newAction);
        });
        $OKButton.click(previousClickHandler);
    });

});


// From http://stackoverflow.com/a/11654596/3439544
function UpdateQueryString(key, value, url) {
    if (!url) url = window.location.href;
    var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
        hash;

    if (re.test(url)) {
        if (typeof value !== 'undefined' && value !== null)
            return url.replace(re, '$1' + key + "=" + value + '$2$3');
        else {
            hash = url.split('#');
            url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
            if (typeof hash[1] !== 'undefined' && hash[1] !== null) 
                url += '#' + hash[1];
            return url;
        }
    }
    else {
        if (typeof value !== 'undefined' && value !== null) {
            var separator = url.indexOf('?') !== -1 ? '&' : '?';
            hash = url.split('#');
            url = hash[0] + separator + key + '=' + value;
            if (typeof hash[1] !== 'undefined' && hash[1] !== null) 
                url += '#' + hash[1];
            return url;
        }
        else
            return url;
    }
}

</script>

You can also use a server-local version of jQuery instead of the "http://ajax.aspnetcdn.com" one; ideally you already load jQuery for other purposes. Or you maybe can rewrite the whole thing without jQuery. I'll test on SP2013 as soon as I open my 2013 VM. But IMO it should work, unless maybe for some element Ids to be changed.

EDIT
OK, I tested it on SP2013, and it works just fine as well.

This functionality is hard coded into SharePoint, to redirect back to the Library.

As the only "documentation" for this is within SharePoint's own code, there is a large effort needed to provide that documentation.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top