Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I create a new page with javascript csom. I am able to give it a title, byline, content etc., but it won't accept an image reference. It doesn't give me any error messages, nor reaching my error function, but I'm obviously missing something here as the new page does not have any images attached.

Any ideas on how to do this?

Here is my code:

var pageInfo = new SP.Publishing.PublishingPageInformation();
var newPage = pubWeb.addPublishingPage(pageInfo);
context.load(newPage);

context.executeQueryAsync(function () {

    var listItem = newPage.get_listItem();
    context.load(listItem);

    context.executeQueryAsync(function () {

        var title = $('#head').val();
        listItem.set_item('Title', title);

        listItem.set_item('PublishingPageImage', { "Url": "/sites/intranett/PublishingImages/ExampleImage.png", "Description": "testing" });

        listItem.update();

        context.executeQueryAsync(function () { }, onFailedCallback);

    }, onFailedCallback);
 }, onFailedCallback);
share|improve this question
    
Make sure the URL is ok ? (in your example you have "intranett" with 2 't' ... that could be a typo in the example code, or not... Just want to make sure ^^) –  AymKdn Apr 10 '13 at 13:38
    
Actually "intranett" is correct here, but thanks :) –  user1942910 Apr 11 '13 at 17:25

1 Answer 1

up vote 1 down vote accepted

I needed to include the html image tag when setting the PublishingPageImage property.

listItem.set_item('PublishingPageImage',  "<img alt='image' src='/sites/intranett/PublishingImages/ExampleImage'>"); 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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