Programming Solutions

Your Source for Information

How to Add a Custom Field to a Post in BlogEngine.Net

by kbdavis07 27. November 2011 10:10

Instructions below are for using an XML Database only.

This applies to BE 2.5

You will need to use:

Microsoft Visual Web Developer  (Express or Paid) versions are ok.

Who could do this?

If you can copy and paste and follow directions you can do it!

Files that needs to be Edited:

1. DotNetSlave.BusinessLogic –> Post.cs

2. DotNetSlave.BusinessLogic –> XmlProvider –> Posts.cs

3. BlogEngine.Net –> Admin –> AjaxHelper.aspx.cs

4. BlogEngine.Net –> Admin –>  Posts –> Add_entry.aspx

5. BlogEngine.Net –> Admin –> Posts –> Add_entry.aspx.cs

6. BlogEngine.Net –> App_GlobalResources –> labels

7. BlogEngine.Net –> App_Data –> posts –> post.xml files

Total of 7 Files that needs to be edited

Follow These Steps below in Order:

Step 1: Download the latest version of BlogEngine.Net “Source Code” not the Web version.

Note: If you just want to upgrade your existing Website then you must use the Source Code that your current site is using. You can’t use the “Web Version” to add an custom field. You must have the original source code. If you only downloaded the Web version go to your Admin section and look at the very bottom of the page for your BlogEngine.Net version. Then go to the BlogEngine.Net Source Code section to find your existing website version.

Step 2: Unzip the folder after you had downloaded it. 

The folder should look like the screenshot below:

FolderContents

Step 3: Click on the icon that has BlogEngine with the Visual Studio logo next to it. The 4th one.

Step 4: Now it brings up Microsoft Visual Web Developer

Step 5: Rebuild the solution to get the /bin files.

Right click on the BlogEngine.Core and select Rebuild

Rebuild

Step 6: Now press Ctrl+F5 to launch the website. Make sure everything is running ok.

Step 7: Now open up the 1st file:

1. DotNetSlave.BusinessLogic –> Post.cs

Now edit the following line:

I am showing the original code for title for reference and will continue to do so through out this post.

Starting at around line# 108 in the source code

/// <summary>
/// The title.
/// </summary>
private string title;  
 /// <summary> 
/// The Meta Post title. Kbdavis07 added
 /// </summary>
 private string metaposttitle;
 
        
 

The first line of code to change:

 1:    ///     The Meta Post title.  Kbdavis07 added

Is the summary of the field you are adding.

Put your field description there for mine its “The Meta Post Title”

Now the 2nd line of code to change:

 1: private string metaposttitle;

Make sure that it is all lowercase.

3rd and final section to change in this file:

 1:   /// <summary>
 2:         /// Gets or sets the Title or the post.
 3:         /// </summary>
 4:         public string Title
 5:         {
 6:             get
 7:             {
 8:                 return this.title;
 9:             }
 10:  
 11:             set
 12:             {
 13:                 base.SetValue("Title", value, ref this.title);
 14:             }
 15:         }
 16:  
 17:          /// <summary>
 18:         /// Gets or sets the Meta Post Title or the post. Kbdavis07 added
 19:         /// </summary>
 20:         public string MetaPostTitle
 21:         {
 22:             get
 23:             {
 24:                 return this.metaposttitle;
 25:             }
 26:  
 27:             set
 28:             {
 29:                 base.SetValue("MetaPostTitle", value, ref this.metaposttitle);
 30:             }
 31:         }
 32:         

Change the Following:

The Summary:

 1:    /// <summary> 
 2:   /// Gets or sets the Meta Post Title or the post. Kbdavis07 added 
 3: /// </summary> 
 
 

The Function:

 1: public string MetaPostTitle
 2:   {  
 3:      get { 
 4:               return this.metaposttitle;  
 5:             }        
 6:  set  {             
 7:            base.SetValue("MetaPostTitle", value, ref this.metaposttitle);            
 8:          }       
 9:  
 10:  }
Very Important make sure to watch your Cases. C# is case sensitive!
Just change “MetaPostTitle” and “metaposttitle” to your field name
These are two different objects.
MetaPostTitle is public 
metaposttitle is private  

Now save and you are done with Part 1 of 7 Files.

Summary:

Basically for all 7 files just follow the “title” field and adjust your field according to it.

Like we did above.

Once you are done with all of the 7 Files make sure that:

In all of your existing posts:

7. BlogEngine.Net –> App_Data –> posts –> post.xml files

Make sure that all of your posts have the new field in them other wise you are going to get an

Error: Object not set to an instance of an object

Also don’t deploy this to a live server until you had uploaded all of your existing posts into your local copy first to make sure that everything works ok.

Then once everything is working then FTP to your server.

Next:

This is it for Part 1 of the series of adding a custom field to a post.

With this post you are able to do it all.

But, later on I will continue with this series with details steps for Files 2 through 7.

Just right now don’t have the time to complete it and hopefully this can get you through the process.

My goal is to get this out as fast as possible so you can use it.

If you have any questions,feedback,problems, and etc. please leave it in the comment section below.

In the mean time if you like this post please share it with others by using the social buttons above.

Sign up for the Newsletter, or use the RSS Feed to follow.

Have a Great Day!

Brian Davis

 

Tags:

Category: BlogEngine.NET



Add comment

biuquote
  • Comment
  • Preview
Loading

Alpha Tags