- Posted by Admin on January 24, 2010
If you see this post it means that BlogEngine.NET 1.6.0 is running and the hard part of creating your own blog is done. There is only a few things left to do.
Write Permissions
To be able to log in to the blog and writing posts, you need to enable write permissions on the App_Data folder. If you’re blog is hosted at a hosting provider, you can either log into your account’s admin page or call the support. You need write permissions on the App_Data folder because all posts, comments, and blog attachments are saved as XML files and placed in the App_Data folder.
If you wish to use a database to to store your blog data, we still encourage you to enable this write access for an images you may wish to store for your blog posts. If you are interested in using Microsoft SQL Server, MySQL, VistaDB, or other databases, please see the BlogEngine wiki to get started.
Security
When you've got write permissions to the App_Data folder, you need to change the username and password. Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password. Passwords are hashed by default so if you lose your password, please see the BlogEngine wiki for information on recovery.
Configuration and Profile
Now that you have your blog secured, take a look through the settings and give your new blog a title. BlogEngine.NET 1.4 is set up to take full advantage of of many semantic formats and technologies such as FOAF, SIOC and APML. It means that the content stored in your BlogEngine.NET installation will be fully portable and auto-discoverable. Be sure to fill in your author profile to take better advantage of this.
Themes and Widgets
One last thing to consider is customizing the look of your blog. We have a few themes available right out of the box including two fully setup to use our new widget framework. The widget framework allows drop and drag placement on your side bar as well as editing and configuration right in the widget while you are logged in. Be sure to check out our home page for more theme choices and downloadable widgets to add to your blog.
On the web
You can find BlogEngine.NET on the official website. Here you'll find tutorials, documentation, tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at CodePlex where the daily builds will be published for anyone to download.
Good luck and happy writing.
The BlogEngine.NET team
- Posted by Shay Friedman on January 16, 2010
During our everyday programming tasks we run into several repetitive code blocks that after the 20th time you implement them become really annoying. The worst case is to re-implement these code blocks every time, and the better case is to create a central class library with helper classes and methods. However, a large amount of these tasks can be achieved easily with built-in .NET methods.
In this post I will go through several repetitive code blocks and show you how to implement them using built-in .NET method. If you want to add your suggestions, comment! I’ll add your suggestions to the post periodically.
Disclaimer: I’m sure some of the code blocks I use in the NOT Recommended sections can be written much better. These code blocks are here just for demonstration purposes.
Code Block #1 – Check string for nullity or emptiness
NOT Recommended
str = "something"
if (str == null || str == String.Empty)
{
// Oh no! the string isn't valid!
}
Recommended
str = "something"
if (String.IsNullOrEmpty(str))
{
// Oh no! the string isn't valid!
}
Code Block #2 – Check string for nullity or emptiness (spaces only string is invalid too)
NOT Recommended
str = "something"
if (str == null || str.Trim() == String.Empty)
{
// Oh no! the string isn't valid!
}
Recommended (C# 4.0 Only)
str = "something"
if (String.IsNullOrWhiteSpace(str))
{
// Oh no! the string isn't valid!
}
Code Block #3 – Copy an Array
NOT Recommended
string[] source = new string[] { "a", "b", "c" };
string[] dest = new string[3];
for (int i=0; i < source.Length; i++)
{
dest[i] = source[i];
}
Recommended
string[] source = new string[] { "a", "b", "c" };
string[] dest = new string[3];
Array.Copy(surce, dest, source.Length);
Code Block #4 – Check if a char is a digit
NOT Recommended
char c = '1';
if (c == '1' || c == '2' || c == '3' ||
c == '4' || c == '5' || c == '6' ||
c == '7' || c == '8' || c == '9' ||
c == '0')
{
// It's a digit!
}
Recommended
char c = '1';
if (Char.IsDigit(c))
{
// It's a digit!
}
Code Block #5 – Combine Paths
NOT Recommended
string folder = @"C:\MyDir";
string file = "MyFile.docx";
// Combine to make a path
string path = folder + @"\" + file;
Recommended
string folder = @"C:\MyDir";
string file = "MyFile.docx";
// Combine
string path = System.IO.Path.Combine(folder, file);
Code Block #6 – Get file extension out of a file path
NOT Recommended
string path = @"C:\MyDir\MyFile.docx";
string extension = path.Substring(path.LastIndexOf("."));
Recommended
string path = @"C:\MyDir\MyFile.docx";
string extension = System.IO.Path.GetExtension(path);
Code Block #7 – Get MyDocuments Path
NOT Recommended
// Probably some nasty stuff here
Recommended
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Code Block #8 – Check if object is of a specific type
NOT Recommended
object obj = "str";
if (obj.GetType() == typeof(String))
{
// It's a string!
}
Recommended
object obj = "str";
if (obj is String)
{
// It's a string!
}
As Adrian Aisemberg has pointed out, these samples are not entirely the same. The is keyword will return true also if obj is of a derivative type of String (in this sample).
Code Block #9 – Set default enum value
NOT Recommended
public class MyClass
{
private enum Sample
{
A,
B,
C
}
static Sample s = Sample.B; // Set default value explicitly
public static void Run()
{
Console.WriteLine(s); // Prints B
}
}
Recommended
public class MyClass
{
private enum Sample
{
A,
B = 0, // Make B the default value
C
}
static Sample s; // Default value will be used
public static void Run()
{
Console.WriteLine(s); // Prints B
}
}
Code Block #10 – Check if a string starts with another string
NOT Recommended
string str = "Hello World";
if (str.Substring(0, 5) == "Hello")
{
// String starts with Hello!
}
Recommended
string str = "Hello World";
if (str.StartsWith("Hello"))
{
// String starts with Hello!
}
Code Block #11 – Convert list of items of one type to a list of items of a different type
NOT Recommended
List<int> list = new List<int>(new[] { 1, 2, 3, 4, 5 });
List<string> convertedList = new List<string>();
foreach (int item in list)
{
convertedList.Add(item.ToString());
}
Recommended
List<int> list = new List<int>(new[] { 1, 2, 3, 4, 5 });
List<string> convertedList = list.ConvertAll<string>(Convert.ToString);
Code Block #12 – Check if a string contains a number and get the number
NOT Recommended
string str = "4";
int num = 0;
bool success = false;
try
{
num = Convert.ToInt32(str);
success = true;
}
catch
{
success = false;
}
if (success)
{
// Do something with the number
}
Recommended
string str = "4";
int num = 0;
if (Int32.TryParse(str, out num))
{
// Do something with the number
}
Code Block #13 – Writing a string to a file (courtesy of Yaron Naveh)
NOT Recommended
const string str = "put me in a file";
const string file = @"c:\logs\file.txt";
var fs = new FileStream(file, FileMode.Create);
var sw = new StreamWriter(fs);
sw.Write(str);
sw.Close();
fs.Close();
Recommended
const string str = "put me in a file";
const string file = @"c:\logs\file.txt";
File.WriteAllText(file, str);
Code Block #14 – Pick value if not null and a different on if it is (courtesy of Abhishek)
NOT Recommended
string input = "sdfds";
string result = null;
if (input == null)
{
result = "Input is null!";
}
else
{
result = input;
}
Recommended
string input = "sdfds";
string result = input ?? "Input is null!";
This is it for now. If you have more, comment and I’ll add your suggestions to the list (with credits).
All the best,
Shay.
- Posted by Shay Friedman on January 6, 2010
Do you want to hear about IronRuby in the upcoming MIX10 conference? If so, make sure to vote for my IronRuby session - IronRuby - the Development Booster Machine.
In the session I plan to talk a bit about the Ruby language and its strengths and then move on and show how .NET developers can take advantage of these stengths in several different scenarios like testing, debugging and Silverlight.
YOU have the power to make it happen! Go ahead and vote!
http://visitmix.com/opencallvote/Entry?entryId=IRONRU127
See you all there,
Shay.
- Posted by Shay Friedman on January 5, 2010
2010!
It’s a new year and the wind of change is in the air. This year is a big year for me – IronRuby Unleashed will be published (est. FEB 15th), another big project is coming (more details in a few weeks) and I changed jobs!
In the last 4 years I worked at a startup named ActionBase. I learned a lot at this place and managed to work with various platforms – Office addins, WinForms, Silverlight and ASP.NET. After 4 years it was a time for a change and I decided to move on. Starting from 1/1/2010 I’m a .NET technologies consultant and instructor at Sela. My main field is dynamic languages but I’ll be doing other stuff too. I’m really thrilled and excited to get started, help customers and spread my knowledge.
If you want me to come to your company to run a course or consult, don’t hesitate to contact me. This is my job now, not a hobby anymore, so go ahead and use me! :)
I wish you all a wonderful and happy new year. May this year will be the one you were waiting and hoping for!
Peace and love,
Shay.