CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Create a blog in c#

    I have a very basic understanding of the programming in C# but i try to create a blog for my website...
    I just have problems, calculating the labels for total of tuits in blog, nb of tuits from the current person, and nb of person that the current person follow.
    I have another problem, i want to show by login the first time for example with tom, just his own tuit and after that just his own tuits and the tuit from the persons he follow...
    But i could not did it.
    CAN SOMEONE HELP PLEASE? THANKS.

  2. #2
    Join Date
    Jun 2012
    Posts
    3

    Exclamation Re: Create a blog in c#

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.IO;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class TuitterWebste_TuitterLogin : System.Web.UI.Page
    {
        protected void Page_PreRender(object sender, EventArgs e)
        {
            //Populate unfollowDropDownList with users that want to follow.
            string[] tuitterFollowerArray = File.ReadAllLines(Server.MapPath(" ") + "/App_Data/tuitterUsers.txt");
            string[] userFollowerPair;
    
    
            for (int h = 1; h < tuitterFollowerArray.Length; h++)
            {
                userFollowerPair = tuitterFollowerArray[h].Split(' ');
            }
    
            for (int v = 0; v <= unfollowDropDownList.Items.Count; v++)
            {
    
            }
            //creating array for Tuit messages
            string[] tuitterArray = File.ReadAllLines(Server.MapPath("") + "/App_Data/tuitterMessages.txt");
            string[] tuitterMessageArray = File.ReadAllLines(Server.MapPath(" ") + "/App_Data/tuitterMessages.txt");
            //reverse tuitMessages in Array
            Array.Reverse(tuitterMessageArray);
            //Empty the tuitTextBox
            tuitTextBox.Text = "";
            //displaying the tuit messages
            for (int i = 0; i < tuitterMessageArray.Length; i++)
            {
                tuitTextBox.Text += tuitterMessageArray[i] + System.Environment.NewLine;
            }
            //displaying the tuit messages
            for (int i = 0; i < tuitterMessageArray.Length; i += 3)
            {
                
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            string[] tuitterNameArray = File.ReadAllLines(Server.MapPath(" ") + "/App_Data/tuitterUsers.txt");
    
            //Populate followDropDownList with users that you can follow.
            if (!IsPostBack)
            {
    
    
            }
            for (int i = 1; i < tuitterNameArray.Length; i++)
            {
                string[] userNamePair = tuitterNameArray[i].Split(' ');
                followDropDownList.Items.Add(userNamePair[0]);
    
    
                // use a session to greet User per his name.
                try
                {
                    string usernameString = Session["User"].ToString();
                    welcomeLabel.Text = "Welcome " + usernameString + "!";
                    welcomeLabel.Text = Convert.ToString("Welcome" + Session["User"]);
                }
                catch
                {
                    Response.Redirect("TuitterLogIn.aspx");
                }
    
                //creating array for Tuit messages
                string[] tuitterArray = File.ReadAllLines(Server.MapPath("") + "/App_Data/tuitterMessages.txt");
                string[] tuitterMessageArray = File.ReadAllLines(Server.MapPath(" ") + "/App_Data/tuitterMessages.txt");
                //reverse tuitMessages in Array
                Array.Reverse(tuitterMessageArray);
                      
    
                //displaying total tuits
                for (int j = 0; j < tuitterMessageArray.Length; j++)
                {
                    string[] splitName = tuitterMessageArray[j].Split(' ');
                    totalNbLabel.Text = Convert.ToString(tuitterMessageArray.Length / 3);
                }
                //displaying tuits by current user
                int counter = 0;
                for (int g = 0; g < tuitterMessageArray.Length; g++)
                {
                    if (tuitTextBox.Text == tuitterMessageArray[g].ToString())
                    {
                        tuitTextBox.Text += tuitterMessageArray[g].ToString();
                        counter++;
                        tuitNbLabel.Text = counter.ToString();
                    }
                }
    
    
                //displaying follower by current user
    
                for (int k = 0; k < tuitterMessageArray.Length / 3; k++)
                {
                    if (unfollowDropDownList.Text == tuitterMessageArray[k].ToString())
                    {
                        unfollowDropDownList.Text += tuitterMessageArray[k].ToString();
                        counter++;
                        followingNbLabel.Text = counter.ToString();
    
    
                    }
                }
            
            }
        }
        
        protected void tuitterImageButton_Click(object sender, ImageClickEventArgs e)
        {
    
            // drag blog from  tuitMessagesTextBox  to tuitTextBox
            // Use AppendAllText to write in the box for the first line/box
            File.AppendAllText(Server.MapPath(" ") + "/App_Data/tuitterMessages.txt", System.Environment.NewLine + ("\n") + DateTime.Now.ToString()  +("\n") + tuitMessagesTextBox.Text  +  ("\n") + welcomeLabel.Text);
            
            string[] tuitterMessageArray = File.ReadAllLines(Server.MapPath(" ") + "/App_Data/tuitterMessages.txt");
            //reverse tuitMessages in Array
            Array.Reverse(tuitterMessageArray);
            
            for (int i = 0; i < tuitterMessageArray.Length; i++)
            {
                tuitTextBox.Text = tuitTextBox.Text + "\n" + tuitterMessageArray[i];
                
            }
           
        }
        protected void followImageButton_Click(object sender, ImageClickEventArgs e)
        {
           
            // drag can follow tuitter in the unfollow box 
            unfollowDropDownList.Items.Add(followDropDownList.SelectedValue);
            
            //selected user is going to the i follow box when the follow button is clicked
            followDropDownList.Items.Remove(followDropDownList.SelectedValue);
            
        }
        protected void unfollowImageButton_Click(object sender, ImageClickEventArgs e)
        {
            //Populate unfollowDropDownList with users that i want to follow.
            followDropDownList.Items.Add(unfollowDropDownList.SelectedValue);
            
            //selected user is going back to the i can follow box when the follow button is clicked
            unfollowDropDownList.Items.Remove(unfollowDropDownList.SelectedValue);
        }
        protected void tuitTextBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }
    }
    Last edited by DataMiser; June 5th, 2012 at 11:43 PM. Reason: added code tags for readability

  3. #3
    Join Date
    Jun 2012
    Posts
    3

    Re: Create a blog in c#

    How to create something like this in C# very basic without Database?
    A search feature - only tuits containing a search keyword will be displayed
    -A user profile page where a user can add information about themselves (such as name, email, hobbies) and use a text file to store this information like you did with tuittermessages
    -The option to delete your tuits
    -The ability to post images
    Thanks

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Create a blog in c#

    Why not use a database for this sort of thing? It's what they're made for.

  5. #5
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: Create a blog in c#

    Don't reinvent the wheel! Wordpress is stable and works well; you can install it on your own server. Otherwise Google Blogger using a custom domain is an adequate solution.
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured