Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 02, 2011 @ 15:51
    Jan Skovgaard
    0

    Problem publishing node using the API

    Hi there guys

    I'm having a weird problem with publishing nodes through the API all of the sudden.

    I'm running a Umbraco 4.5.2 using the .NET 4 framework.

    I'm using the code below to create and publish news item through the API. I'm sure that it has been working earlier on but yesterday I suddenly experience this weird behavior. The problem is the in the content section the node icon indicates that the node has been published but under properties in the link it just gets the "#" character instead of a published URL. (Which you can see on the image)

    namespace mysite.usercontrols
    {
        public partial class OpretNyhed : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {

            }

            protected void Page_Init(object sender, EventArgs e)
            {
                ((umbraco.UmbracoDefault)this.Page).ValidateRequest = false;

            }
            protected void submit_Click(object sender, EventArgs e)
            {
                //Set the root user
                User author = User.GetUser(0);

                //Find the document type with the alias of "nyhed"
                DocumentType dt = DocumentType.GetByAlias("Nyhed");

                //Find the id of the node

                Node currentPage = Node.GetCurrent();

                //Where should the node be stored
                int nodeid = 1059; //I should be cover my head in shame for using a hardcoded value...

                //Find id on logged in member
                var member = System.Web.Security.Membership.GetUser().UserName;

                //Create a new document

                Document d = Document.MakeNew(
                    header.Text,
                    dt,
                    author,
                    nodeid
                );
                d.getProperty("header").Value = header.Text;
                d.getProperty("date").Value = date.Text;
                d.getProperty("teaser").Value = teaser.Text;
                d.getProperty("bodyText").Value = bodytext.Text;
                d.getProperty("author").Value = member;

                //Publish the document
                d.Publish(author);

                //Update the XML cache
                umbraco.library.UpdateDocumentCache(nodeid);

                //Reload the page
                Response.Redirect(umbraco.library.NiceUrl(currentPage.Id));
            }
        }
    }

     

    Any ideas why this is happening?

    I'm using jquery ui datepicker to set the date and I'm using tinyMce on a multiple textform to make the editors able to format the text. I have tried disabling these features but the problem remains. I'm clueless here.

    Looking forward to hear some suggestions. Thanks in advance.

    /Jan

  • webmonger 130 posts 285 karma points
    Jan 02, 2011 @ 16:53
    webmonger
    0

    You may be missing:

     d.Save();

    Try adding it before publish() hopefully that will work.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 02, 2011 @ 16:57
    Jan Skovgaard
    0

    Hi Billy

    I have added the line now - but unfortunately still no luck :-/ - I'm really puzzled about this. Any other suggesions maybe?

    /Jan

  • webmonger 130 posts 285 karma points
    Jan 02, 2011 @ 17:01
    webmonger
    1

    Ah sorry i did not look at the image very well. You need to make sure the name does not contain reserved characters.

    I have a string extension method to remove such characters this may not be the main problem but Umbaco will have difficulty with ? in the document name.

    run the name through this function and see what happens

            public string RemoveUnsafeCharacters(string input)
    {
    string output = "";
    input = input.Replace(' ', '-');
    output = System.Text.RegularExpressions.Regex.Replace(input, @"[^\w\.-]", "");
    output = System.Text.RegularExpressions.Regex.Replace(output, @"[-]+", "-");
    return output;
    }
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 02, 2011 @ 17:02
    Jan Skovgaard
    1

    Hi again

    Got it solved now. I must have rewritten something at some point...I starred myself blind...for some reason I had set the id to update the document cache to "nodeid", which is completely wrong

    umbraco.library.UpdateDocumentCache(nodeid);

    Should of course be

    umbraco.library.UpdateDocumentCache(d.Id);

    Thanks for the help Billy, somehow it led to the solution in the end :-)

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 02, 2011 @ 17:04
    Jan Skovgaard
    0

    Hi Billy

    That's a nice function, which I will study later on - thans for trying to help me out :-)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft