Showing posts with label umbraco. Show all posts
Showing posts with label umbraco. Show all posts

Sunday, 14 July 2013

Umbraco Extensionless URL's

Simply go to web.config and find the key Set this to true and your done, now the pages will not show .aspx :D

Umbraco Items Not Rendering and Meta Description/Keywords

If you having problems with the umbraco items rendering out as just html, you can do the following to make them display. This will insert the html you require before and after.

Wednesday, 10 July 2013

Umbraco Dropdown Multiple(listbox) DataType Pre Values - How to get them

Its really simple, just do the following to bind it to your listbox: XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(1092); preValueRootElementIterator.MoveNext(); //move to first XPathNodeIterator preValueIterator = preValueRootElementIterator.Current.SelectChildren("preValue", ""); ListItemCollection categoryListItems = new ListItemCollection(); while (preValueIterator.MoveNext()) { categoryListItems.Add(new ListItem(" " + preValueIterator.Current.Value, preValueIterator.Current.GetAttribute("id", ""))); } //Bind data to the list eventscoveredListBox.DataSource = categoryListItems; eventscoveredListBox.DataTextField = "Text"; eventscoveredListBox.DataValueField = "Value"; eventscoveredListBox.DataBind(); You can find the id from going into the cms and passing the mouse over the node of the data type you want, put that node id in and your good to go.

Switch Body or another HTML Tag css class using master page and runat="server"

If you want to change the class on a body or html tag then you can target the master page and run a check. This following example is done using umbraco and allows you to check the node you are on then adde the class to that page accordingly. On your ASPX page you will need to mark up you body tag with: on your ASP.CS file you will require something along the lines of: using umbraco.NodeFactory; public partial class Core : System.Web.UI.MasterPage { public void Page_Load(object sender, EventArgs e) { HtmlGenericControl MasterPageBodyTag = (HtmlGenericControl)Master.FindControl("MasterPageBodyTag"); if (Node.GetCurrent() == 1111) { MasterPageBodyTag.Attributes.Add("class", "your-class"); } } So when the node is 1111 it will add the additional class. This has various uses, but it mainly used for when marking up for design purposes.

Tuesday, 9 July 2013

Using the Umbraco 6 ContentService for what you actually use.

Lot of crappy examples there on the web, hope this doesnt add to them :P

If anything is unclear let me know and I will try to write it in a more clear manner.

You will need to include this in your code behind

using Umbraco.Core.Services;

 // Get the Umbraco Content Service
var contentService = new ContentService();
var user = contentService.CreateContent(
                    "Barry Chuckle", // Node Name - what I want to call the new child node
                    1084, // Parent Node we want to add to
                    "MyUsers", // The alias of the Document Type
                    0); // Umbraco User ID this will be created by, default 0

// Sample Values
user.SetValue("fullname", "Noddy Holder");
user.SetValue("email", "hello@world.com");

contentService.SaveAndPublish(user);

This should allow you create new items in the CMS from the front end of the site, its useful for contact forms, registrations etc.

Note: Also you can use uploads on the front end to hook into this as well, I would use something along the lines to get the media path.  If you use the above in conjuction with the following you can also use the upload data type.

var saveLocation = MapPath("/media/");

if (!string.IsNullOrEmpty(publicLiabilityInsuranceUpload.FileName))
{
myDocument = Path.GetFileName(myDocument Upload.PostedFile.FileName);
myDocumentUpload.PostedFile.SaveAs(saveLocation + myDocument);
}

user.SetValue("myDocument", myDocument);

Hope this clears up a few matters.

ADDITIONAL:
The multi select dropdown list should be a comma separated value, but I need to confirm 100% how this works over the next day or two when I get chance to run some tests :)