Wednesday 17 July 2013

Umbraco - uTwit - Fun and Games - Errors, Bad Request Etc

After messing around with uTwit and reading a lot of other posts, I finally managed to get it going. The following script actually works, others have posted similar scripts, but they always seem to be missing something. You have to setup a twitter account and goto dev.twitter, setup an application, setup a callback url(can be anything, but needs to be there), generate auth details. Few things to check, make sure you have installed the Uwit package datatype etc. Add the property for example to your homepage which is what I have done in this case called 'twitter'. You install using the .zip files, I didn't realise this at first, lol :D The home node is the id that you will need to reference, I have tried to cover all bases here as I appreciate everyone has different uses and implementations. Hopefully this will all make sense. There are commented out lines should you need to hardcode or called a specific node id. You will need to add the following references to you project: Our.Umbraco.uTwit.DataType.dll Our.Umbraco.uTwit.Web.dll @inherits umbraco.MacroEngines.DynamicNodeContext @using Our.Umbraco.uTwit @using umbraco.NodeFactory @{ const string twitterOAuthPropertyAlias = "twitter"; const int numberOfTweetsToDisplay = 3; const bool includeReplies = false; const bool includeRetweets = true; // Get current node Node home = umbraco.NodeFactory.Node.GetCurrent(); // Alternatively if you have a settings node for example use a specific id //var home = Model.NodeById(1079); // If you want to hard code the details then use this line // string twitterOAuth = "{'ScreenName': 'xxx','OAuthToken': 'xxx','OAuthTokenSecret': 'xxx','ConsumerKey': 'xxx','ConsumerSecret': 'xxx'}"; string twitterOAuth = home.GetProperty(twitterOAuthPropertyAlias); // If you use a specific node ID then use this instead //string twitterOAuth = home.GetPropertyValue(twitterOAuthPropertyAlias) as string(); var config = uTwit.DeserializeValue(twitterOAuth); var tweets = uTwit.GetLatestTweets(config, numberOfTweetsToDisplay, includeReplies, includeRetweets); if (tweets != null) { foreach (var tweet in tweets) { var tweetToDisplay = tweet.IsRetweet ? tweet.RetweetedStatus : tweet;
@tweetToDisplay.User.Name @tweetToDisplay.User.Name @uTwit.FormatDate(tweetToDisplay.CreatedAt)

@tweetToDisplay.LinkifiedText

@if(tweet.IsRetweet) {

Retweeted by @tweet.User.ScreenName

}
} } } Hope this saved some of you some headaches when it wasn't working.

Monday 15 July 2013

__doPostBack is not defined

If you using chrome check User Agent Switcher plugin, After removing this the error magically disappeared. There are several other solutions to this problem, but its not worth me resisting them here.

Sunday 14 July 2013

Jquery, resize li tags automatically

Heres a bit of code I put together to stretch a menu to to the full width of the page regardless of how many items there are. var orginalwidth = $(".nav").width; var newwidth = 100 / $(".nav li").length; $(".nav li").each( function () { $(this).css("width", newwidth + "%"); } )

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.

Friday 12 July 2013

Could not find file DotNetOpenAuth.Core.dll

Error 1 Copying file bin\DotNetOpenAuth.Core.dll to obj\Release\Package\PackageTmp\bin\DotNetOpenAuth.Core.dll failed. Could not find file 'bin\DotNetOpenAuth.Core.dll'. 0 0 UKDJAgencyUmbraco You can fix this by downloading the package using nuget, or if you have already done that, have a look in the packages folder in your solution, this should have all the dlls you require, just make sure you use the correct dll for the relevant .net version you are working on.

"Content controls are allowed only in content page that references a master page" Error Fix

Make sure you have MasterPageFile= at the top of your master page. Fixed :D

Code Behind Problem - Control References Not Working

Really simple problem, but is easy to fix. Sometimes the designer class is missing which references the controls inside the placeholder content. You shouldn't need to do findcontrol or any of that jazz, just create a new master page and copy your existing code into the master page. That's basically it.

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 :)