Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

A Code Project Article Information Library (Part 2)

4.38/5 (11 votes)
1 May 2008CPOL5 min read 1   191  
This library provides a framework for using Code Project article information in applications, and provides a utility for extracting user information

Image 1

Introduction

This article is part 2 of a series of articles presenting the CodeProject.dll which may be used to extract information about users and articles on CodeProject. In this article the User class is discussed and the functionality expressed. The User class is responsible for obtaining information about a specific user by member number (or ID). The following information may be extracted;

  • Member Name - not to be confused with member id or number
  • User Status - i.e. bronze, silver, gold, or platinum
  • Number of Messages Posted - in both forums and responces to other articles
  • Number of Articles Posted
  • Biography - a short description of the user (may contain some HTML formatting)
  • Location
  • Job Title
  • Company
  • Member Since - date member join Code Project
  • Homepage - URL of personal website
  • Article Comments - list of articles user has commented in recently
  • Forum Comments - list of forums users has commented in recently

PLEASE DO NOT ABUSE THIS LIBRARY. This library allows information to be extracted from the Code Project website, please do retrieve too many user's information at one time or you will effective be performing a denial of service attack. If this happens too often this article will be removed! You have been warned. I would also like to remind Code Project members that it is against the site rules to download lists of users for purposes of distribution for profit or otherwise.

Background

This article is based upon two pages; http://www.codeproject.com/script/Membership/Profiles.aspx?mid=###memberid### and http://www.codeproject.com/script/Forums/LatestComments.aspx?fmid=###memberid###&pgnumpager=###pagenumber###. The first page is the Who's Who page which contains most information about a specific user. While the second page (which is actually a set of pages) contains a list of recent postings).

Note that in all html source whitespace has been trimmed.

The who's who page contains the following information;

Member Name

<h4><a name="1"/></a>1. 
###member name###</h4>

Status

<b><span id="ctl00_MC_MR_ctl00_S" class="###styleclass###">###status###</span></b>.

Messages Posted

<td style="white-space:nowrap"  class="SmallText"><a id="ctl00_MC_MR_ctl00_MP" 
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
href="http://www.codeproject.com/script/Forums/LatestComments.aspx?fmid=###memberid###"> 
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
Messages Posted</a></td>
<td class="SmallText" align="left">###number### - ###category###</td>

Posting status:

  • No Messages have been posted
  • Poster: The member has posted up to 100 messages
  • Regular: The member has posted from 100 up to 1000 messages
  • Personality: The member has posted 1000 up to 5000 messages
  • Fixture: The member has posted over 5000 messages

Articles Posted

<td style="white-space:nowrap"  class="SmallText"><a id="ctl00_MC_MR_ctl00_AS"  
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=###memberid###"> 
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
Articles Submitted</a></td>
<td class="SmallText" align="left">###number### - ###category###</td>

Author status:

  • Browser: No Articles have been posted
  • Contributor: The member has submitted up to 4 articles
  • Writer: The member has submitted 5-14 articles
  • Prolific: The member has submitted 15-24 articles
  • Legend: The member has submitted over 25 articles

Biography

<td  class="SmallText" align="left" colspan="2" width="100%">###biography###</td>

Note that the biography may contain some HTML formatting; the CodeProject.dll removes <br /> line breaks are replaces with the \r\n notation.

Location

<td class="SmallText">Location</td>
<td  class="SmallText" align="left" colspan="2"><img  
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
src="###location of country graphic###" alt="###country name###" width="16"  
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
height="11" /> ###country name###</td>

Note the preceeding space on the ###country name### text.

Job Title

<td class="SmallText">Job Title</td>
<td class="SmallText" align="left" colspan="2">###job title###</td>

Company

<td class="SmallText">Company</td>
<td class="SmallText" align="left" colspan="2">###company###</td>

Member Since

<td class="SmallText">Member since</td>
<td  class="SmallText" align="left">
###day of week###, ###month### ###day of month###, ###year###<br />
(###number of months### months) 
</td>

E.g.

<td class="SmallText">Member since</td>
<td  class="SmallText" align="left">
Friday, January 18, 2008<br />
(3 months) 
</td>

Homepage

<td class="SmallText">Homepage</td>
<td  class="SmallText" align="left"><a id="ctl00_MC_MR_ctl00_H"  
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
href="http://www.derek-bartram.co.uk">http://www.derek-bartram.co.uk</a></td>

Using the code

The user's portion of the library is based around the User class which has the following events, methods, and properties;

  • User(String userID) - constructor accepts a member id (or number) used to identify the user to Code Project. Also calls update()
  • void update() - updates the object to the latest information; all event firing is a direct result of a call to update
  • List<String> ArticleComments {get;} - returns a list of articles the user has commented on (in no particular order, but with no duplicates)
  • List<String> ForumComments {get;} - returns a list of forums the user has posted in (in no particular order, but with no duplicates)
  • String MemberName {get;} - returns the friendly name of the user (e.g. Derek Bartram)
  • User.Status UserStatus {get;} - returns the user status of the user (e.g. Gold for myself as I have posted between 15-24 articles)
  • int NumberMessagesPosted {get;} - returns the total number of messages posted in articles and the forums
  • int NumberArticlesPosted {get;} - returns the number of articles publically available (not including those removed or not published)
  • String Biography {get;} - returns the biography as a string, with <br /> changed to \r\n
  • String Location {get;} - returns the location of the user
  • String JobTitle {get;} - returns the job title of the user
  • String Company {get;} - returns the company the user works for
  • DateTime MemberSince {get;} - returns the date the user joined Code Project
  • String Homepage {get;} - returns the user's personal homepage
  • event MemberNameChangedEventDelegate MemberNameChanged - Fired when the member name changes*
  • event UserStatusChangedEventDelegate UserStatusChanged - Fired when the user status changes*
  • event NumberMessagesPostedChangedEventDelegate NumberMessagesPostedChanged - Fired when the number of posted messages changes*
  • event NumberArticlesPostedChangedEventDelegate NumberArticlesPostedChanged - Fired when the number of articles posted changes*
  • event BiographyChangedEventDelegate BiographyChanged - Fired when the biography changes*
  • event LocationChangedEventDelegate LocationChanged - Fired when the location changes*
  • event JobTitleChangedEventDelegate JobTitleChanged - Fired when the job title changes*
  • event CompanyChangedEventDelegate CompanyChanged - Fired when the company changes*
  • event MemberSinceChangedEventDelegate MemberSinceChanged - Fired when the member joined date changes (should never be called after initial update())*
  • event HomepageChangedEventDelegate HomepageChanged - Fired when the homepage changes*

Only fired in responces to changes detected during a call to update() (which also occurs during the constructor)

Getting User Information

The following code sample shows how to use the User class to obtain information as per the demo (and screen shot above).

C#
User u = new User("4843375");

Console.WriteLine("Name : " + u.MemberName);
Console.WriteLine("Status : " + u.UserStatus.ToString());
Console.WriteLine("Messages Posted : " + u.NumberMessagesPosted);
Console.WriteLine("Articles Posted : " + u.NumberArticlesPosted);
Console.WriteLine("Location : " + u.Location);
Console.WriteLine("Job Title : " + u.JobTitle);
Console.WriteLine("Company : " + u.Company);
Console.WriteLine("Member Since : " + u.MemberSince.ToString());
Console.WriteLine("Homepage : " + u.Homepage);

Console.WriteLine("");
Console.WriteLine("Biography : " + u.Biography);
Console.WriteLine("");

foreach (String articleName in u.ArticleComments)
{
    Console.WriteLine("Commented in article \"" + articleName + "\"");
}

Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");

foreach (String forum in u.ForumComments)
{
    Console.WriteLine("Commented in forum \"" + forum + "\"");
}

History

Version 1.0.0.1 - Second build of CodeProject.dll, introducing the User class

Useful Links

codeprojectarticle.aspx (Part 1, Articles)

codeprojectuser.aspx (Part 2, Users)

codeprojectkevinbacon.aspx (Part 3, Kevin Bacon)

Additional Licensing Notes

Please feel free to use this in your work, however please be aware that a modified The Code Project Open License (CPOL) is in use; basically it is the same as the standard license except that this code must not be used for commercial or not-for-profit commercial use without prior authorisation. Please see license.txt or license.pdf in the included source and demo files.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)