Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 Displaying forum topic in asp.net
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

chrisfildes
Starting Member

4 Posts

Posted - 18 December 2006 :  11:24:37  Show Profile
Hi,
I have an asp.net content management system that i'd like to display various forum threads on. I can eaily pull out the topics and replies from the db, but they have forum code within them (such as etc...)

Has anyone got a handy function that could convert from forum code to html ????

Thanks in advance!

Chris

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 18 December 2006 :  11:39:07  Show Profile  Visit HuwR's Homepage
the simple answer to your question is no, there is not a simple function that will translate the forumcode, it actually requires about half a dozen different functions or so, I can however provide you with a formatting class which you should be able to use fairly easily, but it will take me a day or two to sort it out as I am a little tied up at present doing other stuff.
Go to Top of Page

chrisfildes
Starting Member

4 Posts

Posted - 18 December 2006 :  13:28:38  Show Profile
HuwR - thats fantastic - really appreciate your help!
Regards,
Chris
Go to Top of Page

chrisfildes
Starting Member

4 Posts

Posted - 27 January 2007 :  13:41:44  Show Profile
quote:
Originally posted by HuwR

the simple answer to your question is no, there is not a simple function that will translate the forumcode, it actually requires about half a dozen different functions or so, I can however provide you with a formatting class which you should be able to use fairly easily, but it will take me a day or two to sort it out as I am a little tied up at present doing other stuff.



Thanks again for the offer - was wondering if you'd had a chance to look at it. Sorry to be a pest
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 27 January 2007 :  14:56:59  Show Profile  Visit HuwR's Homepage
sure, sorry, got carried away getting the .net version ready for testing, I will zip up the formatting class file for you and post a link to it later
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 27 January 2007 :  15:27:49  Show Profile  Visit HuwR's Homepage
Ok, try the file in this zip, you should place it in a directory called App_code, you can then call the function from anywhere in your .Net code by using the following function.

Formatting.FormatStr(string fString, int MessageId,string idType)

where fString is the message text to display, for your purposes you should pass it -1 for the MessageId and null for the idType (these are used in the ne .Net version so passing -1 and null will bypass the new code), it will return you a string with all the code tags replaced with HTML.Also if you want to display the forum date string as a date/time you can use the following function

Formatting.ForumDate(string fDate, string Seperator,bool ShowTime)
This function will return you a string which is the date and time formatted to the forum date time type, for the functions to work you will need to add some values to the AppSettings section of your web config as detailed below.

<add key="boolAllowForumCode" value="1" />
<add key="boolImgInPosts" value="1" />
<add key="boolAllowHTML" value="0" />
<add key="boolIcons" value="1" />
<add key="strDateType" value="dd MMMM yyyy" />
<add key="strTimeType" value="HH:mm:ss" />
<add key="strBadWords" value="Your badwords go here, seperated by a | " />


I can't guarantee it will work perfectly as it is designed for the .Net version of the forum, but it should give a reasonable result, anyway if you have problems with it, please email me and I will see what I can do to help.
Go to Top of Page

chrisfildes
Starting Member

4 Posts

Posted - 01 February 2007 :  04:24:05  Show Profile
Thanks so much for your help HuwR!!
I'll be testing it out this weekend - cheers!
Go to Top of Page

the agony booth
Starting Member

19 Posts

Posted - 08 February 2007 :  15:49:34  Show Profile
HuwR, thanks for the code! I used it to create an assembly in .Net 2.0 that I can reference from SQL 2005. Now I can do the following in my stored procedures and retrieve fully-formatted HTML:

select dbo.SnitzFormatStr(t.T_MESSAGE, -1, null) 
from FORUM_TOPICS 

If anyone is interested in doing the same thing, I can post the modified version of Formatting.cs here. The trick is to declare FormatStr like this:

  [SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.None)]
  public static SqlString FormatStr(string fString, int MessageId, string idType)
  {

And then after you add your assembly to SQL 2005, this will let you create a function like so:

create function dbo.SnitzFormatStr (@fString nvarchar(max), @MessageId int, @idType nvarchar(100))
returns nvarchar(max)
AS EXTERNAL NAME
[SnitzUtility].[SnitzUtility.Formatting].[FormatStr] 

All functions in the C# code have to be declared as static, and any public variables have to be declared as static readonly. Also, you will not be able to access ConfigurationManager.AppSettings or HttpContext.Current from within SQL Server. So I ended up hardcoding some stuff to get it to run within SQL. But other than that, it works great, with no real performance issues.



http://www.agonybooth.com/
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 08 February 2007 :  17:30:39  Show Profile  Visit HuwR's Homepage
you can't really hardcode replacements for ConfigurationManager.AppSettings as these are the forums config values and may change, however, for the current asp version of snitz you can fetch these values from the forum_config_new table. Hard coding of the httpcontext.current value in GetCurrentIcon (the image path) should be replaced by the ImageUrl path aslo stored in forum_config_new. The other occurence of httpcontext can be removed as the forumdate function is not used to format a message.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2019 Snitz™ Communications Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000 Version 3.4.07