I am writing an extension for the umbraco package CMSImport that organises your posts into their respective date folders.
This is the first time I have written any .net and I am having a scope problem (I think...)
I have a .aspx page with a listbox that should get auto populated with the nodes from umbraco on page load but visual studio is showing an error saying "The name 'listOfNodes' does not exist in the current context".
Here is my code behind:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.presentation.nodeFactory;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
namespace umbracoDocumentApi
{
public partial class editContent : System.Web.UI.UserControl
{
public void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//get details for the current node
Node currentPage = Node.GetCurrent();
//use those details to go to the top level node
Node topPage = Node.GetCurrent();
while (topPage.Parent != null)
{
topPage = topPage.Parent;
}
//and add each child of the top level node (every page on the site) to the drop down box
foreach (Node Child in topPage.Children)
{
listOfNodes.Items.Add(Child.Id.ToString());
}
}
}
protected void go_click(object sender, EventArgs e)
{
if (Page.IsValid)
{
Node Parent = new Node(int.Parse(listOfNodes.SelectedValue));
foreach (Node Child in Parent.Children)
{
//create blog date folder nodes ///////////////////////////////////////////////////////////////////////////
//for each child of the selected node, load create dates
DateTime createDate = Child.CreateDate;
int year = createDate.Year;
int month = createDate.Month;
int day = createDate.Day;
//load date page doc type
DocumentType BlogDateFolderDocTypeId = DocumentType.GetByAlias("umbracoBlogDateFolder");
//load author info
User author = User.GetUser(0);
//create year, month and date folders
Document createYearDateFolder = Document.MakeNew(year.ToString(), BlogDateFolderDocTypeId, author, int.Parse(listOfNodes.SelectedValue));
Document createMonthDateFolder = Document.MakeNew(month.ToString(), BlogDateFolderDocTypeId, author, createYearDateFolder.Id);
Document createDayDateFolder = Document.MakeNew(day.ToString(), BlogDateFolderDocTypeId, author, createMonthDateFolder.Id);
//publish those folders
createYearDateFolder.Publish(author);
createMonthDateFolder.Publish(author);
createDayDateFolder.Publish(author);
//update the umbraco cache
umbraco.library.UpdateDocumentCache(createYearDateFolder.Id);
umbraco.library.UpdateDocumentCache(createMonthDateFolder.Id);
umbraco.library.UpdateDocumentCache(createDayDateFolder.Id);
//move blog posts into their appropriate blog date folders //////////////////////////////////////////////////
//specify document to be moved
Document itemToMove = new Document(Child.Id);
//move the document
itemToMove.Move(createDayDateFolder.Id);
}
//refresh umbraco library
umbraco.library.RefreshContent();
}
}
}
}
Your class uses umbracoDocumentApi.editContent and derives from Usercontrol. So it doesn't match with the page. On the aspx page change Inherits="umbracoDocumentApi.organisePosts to Inherits="umbracoDocumentApi.editContent" and in the code behind change System.Web.UI.UserControl to System.Web.UI.Page
Thanks very much, that fixed the errors I was getting. There is now one more:
Error1'System.Security.Principal.IPrincipal' does not contain a definition for 'GetUser' and no extension method 'GetUser' accepting a first argument of type 'System.Security.Principal.IPrincipal' could be found (are you missing a using directive or an assembly reference?)\umbracoDocumentApi\organisePosts.aspx.cs5740umbracoDocumentApi
Object scope issue in .net & cs code behind
Hi all,
I am writing an extension for the umbraco package CMSImport that organises your posts into their respective date folders.
This is the first time I have written any .net and I am having a scope problem (I think...)
I have a .aspx page with a listbox that should get auto populated with the nodes from umbraco on page load but visual studio is showing an error saying "The name 'listOfNodes' does not exist in the current context".
Here is my code behind:
Here is my .aspx page code:
Anybody?
Hi,
Your class uses umbracoDocumentApi.editContent and derives from Usercontrol. So it doesn't match with the page. On the aspx page change Inherits="umbracoDocumentApi.organisePosts to Inherits="umbracoDocumentApi.editContent" and in the code behind change System.Web.UI.UserControl
to System.Web.UI.Page
Cheers,
Richard
Thanks very much, that fixed the errors I was getting. There is now one more:
Error 1 'System.Security.Principal.IPrincipal' does not contain a definition for 'GetUser' and no extension method 'GetUser' accepting a first argument of type 'System.Security.Principal.IPrincipal' could be found (are you missing a using directive or an assembly reference?) \umbracoDocumentApi\organisePosts.aspx.cs 57 40 umbracoDocumentApi
If you hover over the Author variable what is the type it gives you?
There was no popup if I hover over author. I found this article however:
http://forum.umbraco.org/yaf_postst6870_Cant-get-GetUser-function-to-work.aspx
and here is my new code:
int userID = 0;
umbraco.BusinessLogic.User author = new User(userID);
which compiles :) Thanks for your help.
Max.
is working on a reply...