Loop through an Enum

How to loop through an Enum and output Names.

1
2
3
4
5
6
7
8
9
10
11
public enum Contact
{
Name = 1,
Address = 2,
Phone = 3
}

foreach (var contact in Enum.GetNames(typeof(Contact)))
{
Reponse.Write(contact);
}

 

Output

Name
Address
Phone

 

SQL Server Database stuck in Restoring state

From time to time your sql database will get stuck in Restoring state.  Here are two different ways to get your database out of restoring state.

1
2
3
RESTORE DATABASE MyDatabase
FROM DISK = ‘MyDatabase.bak’
WITH REPLACE,RECOVERY
or
  1. Stop the service (MSSQLSERVER);
  2. Rename or delete the Database and Log files (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data…) or wherever you have the files;
  3. Start the service (MSSQLSERVER);
  4. Delete the database with problem;
  5. Restore the database again.

 

Convert VB to C# or C# to VB

Handy tool for conveting code inbetween VB and C# or vice versa.

http://converter.telerik.com/

 

Get MP3 file duration/length

C# code for if you are trying to get the mp3 length or duration of a media file.  You will need to reference Windows Media Player.  Go to Com Add-ins to add the wmp.dll to your project. 

1
2
3
4
5
6
7
string Duration = null;
 WMPLib.WindowsMediaPlayer w = new WMPLib.WindowsMediaPlayer();
 WMPLib.IWMPMedia m = w.newMedia(Filename);
 if (m != null) {
  Duration = m.durationString;
 }
 w.close();

Link Building with Blog Directories

Here is a list of Blog Directories that you can submit your site to and recieve more links to your site.  Which is always a good thing!  Be sure to submit your site to the 3 big search engines as well (Google, Yahoo, MSN).

GlobeofBlogs.com

Submit here:  http://www.globeofblogs.com/register.php

ReadaBlog.com

Submit here:  http://www.readablog.com/AddFeed.aspx

2RSS.com

Submit here:  http://www.2rss.com/index.php - about half way down the page there is a Suggest RSS feed area.

blogarama.com

Submit here:  http://www.blogarama.com/add-a-site/

Blogdigger.com

Submit here:  http://www.blogdigger.com/addFeedForm.jsp

BlogHop.com

Submit here:  http://www.bloghop.com/account/join.htm

Technorati.com

Submit here:  http://www.technorati.com/ping.html

BlogCatalog.com

Submit here:  http://www.blogcatalog.com/blogs/submit_blog.html

BLOGDUP.com

Submit here:  http://www.blogdup.com/submit.php

 

Replace line breaks with BR tags

  In Classic ASP we used to replace line breaks or vbCrLf tags in the following way.

strValue = Replace(strValue, vbCrLf, "<br>")

In ASP.NET it is a bit different.  Now we have the Environment.NewLine command that will determine the coding environment you are running in either VB or C#.  So you can replace the line break command wether it is vbCrLf or /n.

string strValue = strValue;

strValue.Text = strValue.Replace(Environment.NewLine, "<br/>");

 

How to use the Union statement with a dynamic order by


I don’t use the Union statement to much in my SQL coding but today I needed to use it to combine results from two separate tables.  But I ran into an error when I wanted to add in my usual code for doing a dynamic order by.  SQL wouldn’t run my query and output this error message.

ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.

 To fix this problem I put my Union statement into a derived table by doing the following.

SELECT * FROM (

SELECT Column1, Column2 FROM Table_A

UNION ALL

SELECT Column1, Column2 FROM Table_B

) DerivedTableName (Column1, Column2)

Next I added in my dynamic Order By code as such.

SELECT * FROM (

SELECT Column1, Column2 FROM Table_A

UNION ALL

SELECT Column1, Column2 FROM Table_B

) DerivedTableName (Column1, Column2)

ORDER BY

CASE @OrderBy WHEN ‘Column1ASC’ THEN Column1 END ASC,

CASE @OrderBy WHEN ‘Column1DESC’ THEN Column1 END DESC

reCAPTCHA Classic ASP Implementation


Recently had to work with a new CAPTCHA program called reCAPTCHA.  It was fairly easy to implement with Classic ASP coCAPTCHA - World of Codede but had some problems figuring out some parts of it.

First off what is CAPTCHA?  It stands for Completely Automated Public Turing test to tell Computers and Humans Apart.  CAPTCHA is basically an image of letters and numbers that is randomly generated.  The image makes it difficult for spam bots to read.  So they can be used as a way to verify if a computer is submitting a form on a website or an actual person.  So we can eliminate all of that pesky spam!

The reCAPTCHA software is free to use and also helps digitize books when it is being used.  Check out their site for more information on that.

I needed to implement this software on a site that runs Classic ASP.  They did not have a specific example on how to do this but I was able to find an example done from a very kind person Andre F. Bruton on the discussion boards.  Click here to go and view the example.

Update it appears that the above site has gone down so here is a link to the example that was offered by that site.

Download the example.

The example worked great I just had to insert the code into my pages and I was off and running in no time.  However on a few of the pages I was running them in SSL which when using the reCAPTCHA software on those page brought up some secure errors.  Through searching around the internet and trying various things I found out that reCAPTCHA has a secure server to send to so you will no longer get the security errors.  That URL is https://api-secure.recaptcha.net

Here is an example of where you need to put it in your code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function recaptcha_challenge_writer(publickey)
recaptcha_challenge_writer = "&lt;script type=""text/javascript""&gt;" &amp; _
"var RecaptchaOptions = {" &amp; _
" theme : 'white'," &amp; _
" tabindex : 0" &amp; _
"};" &amp; _
"&lt;/script&gt;" &amp; _
"&lt;script type=""text/javascript"" src=""https://api-secure.recaptcha.net/challenge?k=" &amp; publickey &amp; """&gt;&lt;/script&gt;" &amp; _
"&lt;noscript&gt;" &amp; _
"&lt;iframe src=""http://api.recaptcha.net/noscript?k=" &amp; publickey &amp; """ frameborder=""1""&gt;&lt;/iframe&gt;&lt;br&gt;" &amp; _
"&lt;textarea name=""recaptcha_challenge_field"" rows=""3"" cols=""40""&gt;&lt;/textarea&gt;" &amp; _
"&lt;input type=""hidden"" name=""recaptcha_response_field"" value=""manual_challenge""&gt;" &amp; _
"&lt;/noscript&gt;"
end function

Hello World of Code!

WorldofCode.comWelcome to the WorldofCode.com!  This blog is for talking about the the world of code we live in, code surrounds our daily lifes, there is no escaping it any more.  I am a web developer so this site will deal with a variety of things, from articles on how to code in certain languages such as ASP.Net, search engine optimization, blogging, happenings around the WWW, software, and computers.