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();
}
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?
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!
Hi Michael,
The code will work as long as you provide valid id in QueryString
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?
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
is working on a reply...