Copied to clipboard

Flag this post as spam?

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


  • Michael Cazzarolli 16 posts 37 karma points
    Nov 15, 2011 @ 10:14
    Michael Cazzarolli
    0

    Document Manipulation - Object reference not set error

    Hi! So, I made a news system on my website where me and the other users can publish, delete and edit simple news.

    Here's the problem: When trying to edit/delete an existing news I get that Object reference not set error!

    Here's how I did it: I make a request with ajax for an aspx page which edits the document or deletes it.

    this is the request that it sends (cancella.aspx would be delete.aspx in english).

    <code> http://localhost:28799/umbraco/cancella.aspx?id=1150 </code>

    here's the code in that page

     

    <code>

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using umbraco.cms.businesslogic;

    using umbraco.cms.businesslogic.web;

    using umbraco.NodeFactory;

     

    public partial class cancella : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if (Page.Request.QueryString["id"] != "")

            {

                int id = Convert.ToInt32(Page.Request.QueryString["id"]);

                if (id != 0)

                {

                    Document doc = new Document(id);

                    doc.UnPublish();                

                    umbraco.library.UnPublishSingleNode(id);

                    umbraco.library.UpdateDocumentCache(id);

                    doc.delete();

                }

            }

        }

    }

    </code>

    The idea would be to instantiate the node, unpublish it and then delete it.

    I've tried some different things, but it won't matter what I do, when I instantiate the Document, every operation i try to do on it gives that error.

    If someone could be so kind to help me it would be great!

  • SideSam 13 posts 33 karma points
    Nov 15, 2011 @ 10:41
    SideSam
    0

    Hi Michael,

    The code will work as long as you provide valid id in QueryString

            int id;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]) && Int32.TryParse(Request.QueryString["id"], out id))
            {
                Document doc = new Document(id);
                doc.UnPublish();
                umbraco.library.UnPublishSingleNode(id);
                umbraco.library.UpdateDocumentCache(id);
                doc.delete();
            }
    

     

  • Michael Cazzarolli 16 posts 37 karma points
    Nov 15, 2011 @ 10:48
    Michael Cazzarolli
    0

    Thanks a lot Sam, but I'm still getting the same error, and I don't know why.. : (

    Do you need some more detail to see where the error is?

    I checked the document, the passed ID is correct, the document is published and everything, so I think the error must be in the instantiation within the delete method, right?

  • Michael Cazzarolli 16 posts 37 karma points
    Nov 15, 2011 @ 11:05
    Michael Cazzarolli
    0

    Problem solved!!

    I just needed to change:

     [code] <%@ Page Language="C#" AutoEventWireup="true" CodeFile="cancella.aspx.cs" Inherits="cancella" %> [/code]

    in my cancella.aspx file, to:

    [code]  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="~/umbraco/cancella.aspx.cs" Inherits="cancella" %> [/code]

    sorry : p

Please Sign in or register to post replies

Write your reply to:

Draft