Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi!
First of all, I would like to thank for this great stuff!
I ma usind Umbraco 4.7.1 with uBlogsy.
I am facing a problem, where the site is in intranet, and the need is to add blogposts without logging in.
Like having the comment form, but adding posts with it.
All help / idea is apreciated!
You could try using windows live writer if that's an option.
Otherwise you'll have to make a form and use the document api http://our.umbraco.org/wiki/reference/api-cheatsheet
Hi Anthony!
Problem solved, in fact I have been creating a form, and so on... I am happy to post here the solution, if you don't mind.
Go for it.
So, what I did, copied the Content.aspx, and changed it to be able to add a blogpost. I am sure, that there is a better solution. Howerver it does work. All suggestions are wellcome!
As follows.
AdduBlogsyPost.ascx file source
<%@ControlLanguage="C#"AutoEventWireup="true"CodeBehind="AdduBlogsyPost.ascx.cs"Inherits="uBlogsyAddPost.AdduBlogsyPost"%>
<divclass="uBlogsy_comment_form">
<asp:MultiViewID="mv"runat="server"ActiveViewIndex="0">
<asp:ViewID="vwForm"runat="server">
<divclass="uBlogsy_row">
<labelfor="txtName"id="txtNameLabel"class="postlabel">
Navn/Name<asp:RequiredFieldValidatorID="RequiredFieldValidator3"runat="server"ControlToValidate="txtName"
Display="Dynamic">*</asp:RequiredFieldValidator>
</label>
<asp:TextBoxID="txtName"runat="server"></asp:TextBox>
</div>
<divclass="uBlogsy_row tall">
<labelfor="txtMessage"id="txtMessageLabel"class="postlabel">
Kommentar/comment<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="txtMessage"
<asp:TextBoxID="txtMessage"runat="server"TextMode="MultiLine"></asp:TextBox>
<asp:ButtonID="btnSubmit"runat="server"Text="Submit"OnClick="btnSubmit_Click"/>
</asp:View>
<asp:ViewID="vwSuccess"runat="server">
Tak for dit indlæg.
</asp:MultiView>
-----------------------------------------------------------------------
AdduBlogsyPost.ascx.cs source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using umbraco.presentation.templateControls;
using umbraco.MacroEngines;
using uHelpsy.Core;
using umbraco.NodeFactory;
using uBlogsy.BusinessLogic;
using umbraco.cms.businesslogic.web;
namespace uBlogsyAddPost
{
publicpartialclassAdduBlogsyPost : System.Web.UI.UserControl
private string m_NodeTypeAlias;
private int m_PageId;
private int m_BlogPageID;
public string blogPageId
get
return m_BlogPageID.ToString();
}
set
m_BlogPageID = int.Parse(value);
#region OnLoad
protected override void OnLoad(EventArgs e)
base.OnLoad(e);
Item item = new Item();
m_PageId = int.Parse(item.PageElements["pageID"].ToString());
// check what type of page this is
m_NodeTypeAlias = item.PageElements["nodeTypeAlias"].ToString();
// was redirected to current page to ensure razor macro is refreshed
if (!string.IsNullOrEmpty(Request.QueryString["success"]) && Request.QueryString["success"] == "true")
mv.ActiveViewIndex = 1;
#endregion
#region btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
CreatePost();
// redirect to current page to ensure razor macro is refreshed
Response.Redirect(Request.Url.AbsolutePath.ToString() + "?success=true");
#region Post methods
#region CreatePost
///<summary>
/// Creates an umbraco node under the current page
///</summary>
private void CreatePost()
DateTime today = DateTime.Now;
int year = today.Year;
int month = today.Month;
int day = today.Day;
Document yearFolder = null;
Document monthFolder = null;
Document dayFolder = null;
// blogNode id
Document blogFolder = new Document(m_BlogPageID);
// year node
yearFolder = GetYearFolder(blogFolder, today);
// month node
monthFolder = GetMonthFolder(yearFolder, today);
// day node
dayFolder = GetDayFolder(monthFolder, today);
string name = Server.HtmlEncode(txtName.Text);
Dictionary<string, object> postDic = GetDefaultDictionary();
postDic["uBlogsyContentTitle"] = "eksampel";
postDic["uBlogsyContentSummary"] = Server.HtmlEncode(txtMessage.Text);
postDic["uBlogsyContentBody"] = Server.HtmlEncode(txtMessage.Text);
postDic["uBlogsyPostDate"] = DateTime.Now;
postDic["uBlogsyPostDisableComments"] = 0;
postDic["uBlogsyPostAuthor"] = Server.HtmlEncode(txtName.Text);
postDic["uBlogsySeoDescription"] = "";
Document post = UmbracoAPIHelper.CreateContentNode("ekspempel", "uBlogsyPost", postDic, dayFolder.Id/*dayFolder.Id*/, true);
umbraco.library.UpdateDocumentCache(post.Id);
//post.Save();
// create the Comments folder too!
Document commentsFolder = CreateCommentsFolder(post.Id);
umbraco.library.UpdateDocumentCache(commentsFolder.Id);
#region CreateCommentsFolder
/// Creates a uBlogsyPost Document
///<param name="item"></param>
///<param name="parentId"></param>
///<returns></returns>
///
private Document CreateCommentsFolder(int parentId)
Dictionary<string, object> commentFolderDic = GetDefaultDictionary();
commentFolderDic["uBlogsyContentTitle"] = "Comments";
commentFolderDic["uBlogsyContentBody"] = "";
return UmbracoAPIHelper.CreateContentNode("Comments", "uBlogsyContainerComment", commentFolderDic, parentId, true);
public static Dictionary<string, object> GetDefaultDictionary()
Dictionary<string, object> dictionary = new Dictionary<string, object>()
{ "uBlogsyContentTitle", string.Empty },
{ "uBlogsyContentBody", string.Empty },
{ "uBlogsySeoKeywords", string.Empty},
{ "uBlogsySeoDescription", string.Empty},
{ "umbracoNaviHide", 0},
{ "umbracoRedirect", string.Empty},
{ "umbracoUrlName", string.Empty},
{ "umbracoInternalRedirectId", string.Empty},
{ "umbracoUrlAlias", string.Empty}
};
return dictionary;
#region GetYearFolder
/// Creates a uBlogsyFolderYear document
///<param name="blogFolderId"></param>
///<param name="year"></param>
private Document GetYearFolder(Document blogFolder, DateTime today)
string yearName = today.ToString("yyyy");
foreach (var child in blogFolder.Children)
if (child.ContentType.Alias == "uBlogsyFolderYear")
if (child.Text.Contains(yearName))
return child;
Dictionary<string, object> yearDic = GetDefaultDictionary();
yearDic["uBlogsyContentTitle"] = yearName;
yearDic["uBlogsyContentBody"] = "";
return UmbracoAPIHelper.CreateContentNode(yearName, "uBlogsyFolderYear", yearDic, blogFolder.Id, true);
#region GetMonthFolder
/// Creates a month folder
private Document GetMonthFolder(Document yearFolder, DateTime today)
string monthName = today.ToString("MMMM");
foreach (var child in yearFolder.Children)
if (child.ContentType.Alias == "uBlogsyFolderMonth")
if (child.Text.Trim().ToLower().Contains(monthName.ToLower()))
Dictionary<string, object> monthDic = GetDefaultDictionary();
monthDic["uBlogsyContentTitle"] = monthName;
monthDic["uBlogsyContentBody"] = "";
return UmbracoAPIHelper.CreateContentNode(monthName, "uBlogsyFolderMonth", monthDic, yearFolder.Id, true);
#region GetDayFolder
private Document GetDayFolder(Document monthFolder, DateTime today)
string dayName = today.ToString("dd");
foreach (var child in monthFolder.Children)
if (child.ContentType.Alias == "uBlogsyFolderDay")
if (child.Text.Contains(dayName))
monthDic["uBlogsyContentTitle"] = dayName;
return UmbracoAPIHelper.CreateContentNode(dayName, "uBlogsyFolderDay", monthDic, monthFolder.Id, true);
Yep. That's more or less the way to do it.
I think I have forgotten to publish the year, month, day nodes.... so that could be fixed...
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to add post, by not authenticated visitor?
Hi!
First of all, I would like to thank for this great stuff!
I ma usind Umbraco 4.7.1 with uBlogsy.
I am facing a problem, where the site is in intranet, and the need is to add blogposts without logging in.
Like having the comment form, but adding posts with it.
All help / idea is apreciated!
You could try using windows live writer if that's an option.
Otherwise you'll have to make a form and use the document api http://our.umbraco.org/wiki/reference/api-cheatsheet
Hi Anthony!
Problem solved, in fact I have been creating a form, and so on... I am happy to post here the solution, if you don't mind.
Go for it.
So, what I did, copied the Content.aspx, and changed it to be able to add a blogpost. I am sure, that there is a better solution. Howerver it does work. All suggestions are wellcome!
As follows.
AdduBlogsyPost.ascx file source
<%@ControlLanguage="C#"AutoEventWireup="true"CodeBehind="AdduBlogsyPost.ascx.cs"Inherits="uBlogsyAddPost.AdduBlogsyPost"%>
<divclass="uBlogsy_comment_form">
<asp:MultiViewID="mv"runat="server"ActiveViewIndex="0">
<asp:ViewID="vwForm"runat="server">
<divclass="uBlogsy_row">
<labelfor="txtName"id="txtNameLabel"class="postlabel">
Navn/Name<asp:RequiredFieldValidatorID="RequiredFieldValidator3"runat="server"ControlToValidate="txtName"
Display="Dynamic">*</asp:RequiredFieldValidator>
</label>
<asp:TextBoxID="txtName"runat="server"></asp:TextBox>
</div>
<divclass="uBlogsy_row tall">
<labelfor="txtMessage"id="txtMessageLabel"class="postlabel">
Kommentar/comment<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="txtMessage"
Display="Dynamic">*</asp:RequiredFieldValidator>
</label>
<asp:TextBoxID="txtMessage"runat="server"TextMode="MultiLine"></asp:TextBox>
</div>
<asp:ButtonID="btnSubmit"runat="server"Text="Submit"OnClick="btnSubmit_Click"/>
</asp:View>
<asp:ViewID="vwSuccess"runat="server">
Tak for dit indlæg.
</asp:View>
</asp:MultiView>
</div>
-----------------------------------------------------------------------
AdduBlogsyPost.ascx.cs source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using umbraco.presentation.templateControls;
using umbraco.MacroEngines;
using uHelpsy.Core;
using umbraco.NodeFactory;
using uBlogsy.BusinessLogic;
using umbraco.cms.businesslogic.web;
namespace uBlogsyAddPost
{
publicpartialclassAdduBlogsyPost : System.Web.UI.UserControl
{
private string m_NodeTypeAlias;
private int m_PageId;
private int m_BlogPageID;
public string blogPageId
{
get
{
return m_BlogPageID.ToString();
}
set
{
m_BlogPageID = int.Parse(value);
}
}
#region OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Item item = new Item();
m_PageId = int.Parse(item.PageElements["pageID"].ToString());
// check what type of page this is
m_NodeTypeAlias = item.PageElements["nodeTypeAlias"].ToString();
// was redirected to current page to ensure razor macro is refreshed
if (!string.IsNullOrEmpty(Request.QueryString["success"]) && Request.QueryString["success"] == "true")
{
mv.ActiveViewIndex = 1;
}
}
#endregion
#region btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
{
CreatePost();
// redirect to current page to ensure razor macro is refreshed
Response.Redirect(Request.Url.AbsolutePath.ToString() + "?success=true");
}
#endregion
#region Post methods
#region CreatePost
///<summary>
/// Creates an umbraco node under the current page
///</summary>
private void CreatePost()
{
DateTime today = DateTime.Now;
int year = today.Year;
int month = today.Month;
int day = today.Day;
Document yearFolder = null;
Document monthFolder = null;
Document dayFolder = null;
// blogNode id
Document blogFolder = new Document(m_BlogPageID);
// year node
yearFolder = GetYearFolder(blogFolder, today);
// month node
monthFolder = GetMonthFolder(yearFolder, today);
// day node
dayFolder = GetDayFolder(monthFolder, today);
string name = Server.HtmlEncode(txtName.Text);
Dictionary<string, object> postDic = GetDefaultDictionary();
postDic["uBlogsyContentTitle"] = "eksampel";
postDic["uBlogsyContentSummary"] = Server.HtmlEncode(txtMessage.Text);
postDic["uBlogsyContentBody"] = Server.HtmlEncode(txtMessage.Text);
postDic["uBlogsyPostDate"] = DateTime.Now;
postDic["uBlogsyPostDisableComments"] = 0;
postDic["uBlogsyPostAuthor"] = Server.HtmlEncode(txtName.Text);
postDic["uBlogsySeoDescription"] = "";
Document post = UmbracoAPIHelper.CreateContentNode("ekspempel", "uBlogsyPost", postDic, dayFolder.Id/*dayFolder.Id*/, true);
umbraco.library.UpdateDocumentCache(post.Id);
//post.Save();
// create the Comments folder too!
Document commentsFolder = CreateCommentsFolder(post.Id);
umbraco.library.UpdateDocumentCache(commentsFolder.Id);
}
#region CreateCommentsFolder
///<summary>
/// Creates a uBlogsyPost Document
///</summary>
///<param name="item"></param>
///<param name="parentId"></param>
///<returns></returns>
///
private Document CreateCommentsFolder(int parentId)
{
Dictionary<string, object> commentFolderDic = GetDefaultDictionary();
commentFolderDic["uBlogsyContentTitle"] = "Comments";
commentFolderDic["uBlogsyContentBody"] = "";
return UmbracoAPIHelper.CreateContentNode("Comments", "uBlogsyContainerComment", commentFolderDic, parentId, true);
}
#endregion
#endregion
#endregion
public static Dictionary<string, object> GetDefaultDictionary()
{
Dictionary<string, object> dictionary = new Dictionary<string, object>()
{
{ "uBlogsyContentTitle", string.Empty },
{ "uBlogsyContentBody", string.Empty },
{ "uBlogsySeoKeywords", string.Empty},
{ "uBlogsySeoDescription", string.Empty},
{ "umbracoNaviHide", 0},
{ "umbracoRedirect", string.Empty},
{ "umbracoUrlName", string.Empty},
{ "umbracoInternalRedirectId", string.Empty},
{ "umbracoUrlAlias", string.Empty}
};
return dictionary;
}
#region GetYearFolder
///<summary>
/// Creates a uBlogsyFolderYear document
///</summary>
///<param name="blogFolderId"></param>
///<param name="year"></param>
///<returns></returns>
private Document GetYearFolder(Document blogFolder, DateTime today)
{
string yearName = today.ToString("yyyy");
foreach (var child in blogFolder.Children)
{
if (child.ContentType.Alias == "uBlogsyFolderYear")
{
if (child.Text.Contains(yearName))
{
return child;
}
}
}
Dictionary<string, object> yearDic = GetDefaultDictionary();
yearDic["uBlogsyContentTitle"] = yearName;
yearDic["uBlogsyContentBody"] = "";
return UmbracoAPIHelper.CreateContentNode(yearName, "uBlogsyFolderYear", yearDic, blogFolder.Id, true);
}
#endregion
#region GetMonthFolder
///<summary>
/// Creates a month folder
///</summary>
///<param name="item"></param>
///<param name="parentId"></param>
///<returns></returns>
private Document GetMonthFolder(Document yearFolder, DateTime today)
{
string monthName = today.ToString("MMMM");
foreach (var child in yearFolder.Children)
{
if (child.ContentType.Alias == "uBlogsyFolderMonth")
{
if (child.Text.Trim().ToLower().Contains(monthName.ToLower()))
{
return child;
}
}
}
Dictionary<string, object> monthDic = GetDefaultDictionary();
monthDic["uBlogsyContentTitle"] = monthName;
monthDic["uBlogsyContentBody"] = "";
return UmbracoAPIHelper.CreateContentNode(monthName, "uBlogsyFolderMonth", monthDic, yearFolder.Id, true);
}
#endregion
#region GetDayFolder
///<summary>
/// Creates a month folder
///</summary>
///<param name="item"></param>
///<param name="parentId"></param>
///<returns></returns>
private Document GetDayFolder(Document monthFolder, DateTime today)
{
string dayName = today.ToString("dd");
foreach (var child in monthFolder.Children)
{
if (child.ContentType.Alias == "uBlogsyFolderDay")
{
if (child.Text.Contains(dayName))
{
return child;
}
}
}
Dictionary<string, object> monthDic = GetDefaultDictionary();
monthDic["uBlogsyContentTitle"] = dayName;
monthDic["uBlogsyContentBody"] = "";
return UmbracoAPIHelper.CreateContentNode(dayName, "uBlogsyFolderDay", monthDic, monthFolder.Id, true);
}
#endregion
}
}
Yep. That's more or less the way to do it.
I think I have forgotten to publish the year, month, day nodes.... so that could be fixed...
is working on a reply...