1.5.11

Danpe Presents: C# HTML Builder

Having trouble building HTML with C# ?

Have you ever used something like this to generate HTML tables for example:
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= 32; i++)
{
    sb.AppendLine("<tr class=\"row\">");
    sb.AppendLine("<td>" + i + "</td>");
    sb.AppendLine("<td> </td>");
    sb.AppendLine("<td> </td>");
    sb.AppendLine("<td> </td>");
    sb.AppendLine("</tr>");
}
return sb.ToString();
(As you see even the SyntaxHighlighter couldn't handle all of those Escape Characters)

I'm pretty sure you did :)
And you probably you hate all of those Escape Characters! (/" " +)
And doing sb.AppendLine all the time and doing all this formating!
Imagine you have 50 lines?? OMG...

So anyway i made an Application to make you'r life easier :)


Simple as it looks :)
Download Here: C# HTML Builder

18.4.11

Increase SQL Value By 1?

Hey,

Fast solution for today.
Ever wanted to increase SQL value by 1 ?
Yes, a stupid way to do it is by using SELECT to read the value, and then use UPDATE to update to the new value. (Your prolly asked your self, why cant i VALUE++?!)

So you can do it in 1 request using UPDATE :)
Ever thought of Value = Value + 1 ? 

using (SqlConnection con = new SqlConnection(SQL.ConnectionString())) //Use your own Connection String
{
    con.Open();
    string sqlString = "UPDATE Table SET Value=Value+1 WHERE Condition=@Condition";
    SqlCommand cmd = new SqlCommand(sqlString, con); 
    cmd.Parameters.Add("@Condition", ConditionString); 
    rowAffected = cmd.ExecuteNonQuery(); 
    if (rowAffected > 0) 
        DoSomething(); //Success! 
    else 
        DoSomething(); //Fail!
}

As you see i'm using Parameterized Query that i will explain in a later post.
This code will increase 'Value' by 1 where 'Condition'='ConditionString'. 
connection will automaticly close becuase of the 'using' statement.

Hope it helps you,
Have fun and Happy Passover :P

11.4.11

SQL NOW() wont work in Stored Procedures

Hey everyone im back after long time.. :)

This time i'm gonna give you a little solution to a problem i faced few weeks ago.

Have you ever wondered why 'NOW()' wont work in MSSQL Stored Procedure?
Yes, i wondered too.

So the replacment to 'NOW()' is 'GETDATE()' :)
So just use 'GETDATE()' it will give you the same result as 'NOW()'

Hope this little solution helps you
And i'm back now to give you all more solutions :)

21.10.10

Disable Direct Access to iframe !

Hey today i'm gonna show you how to NOT let people access your iframe directly !

It's quiet simple in JavaScript ;)

here is the code: (make sure you put it above the </head> tag)

<script type="text/javascript">
    if (top.location == self.location) {
        top.location = "FULL-URL-HERE";
    }
</script>
Just make sure you replace the "FULL-URL-HERE" to the URL you would like to redirect them ;)

And you'r done no one can access your iframe directly :)

6.10.10

Run C# Console Application Without a Window

Or simply run a hidden Console Application. (C#)

Ok first of all if you want the application to be hidden right click the Project in the Solution Explorer then Properties inside Properties go to Application then Output type and change Console Application to Windows Application.

Now if you want to run a hidden Console Application from a running Console Application we gonna do some coding :)

First of all - using System.Diagnostics;

Then:

Process myProcess = new Process();
myProcess.StartInfo.FileName = @"C:\App.exe"; // Path to the Application
myProcess.StartInfo.CreateNoWindow = true; // YES create in new window
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //Make the new window Hidden :)
myProcess.Start();
Now you'r done :)

Happy coding, and don't forget to subscribe ! :P

20.9.10

Internet Explorer breaks setInterval ?

Today i faced a stupid bug in Internet Explorer 8 and javascript.

I had my code in javascript: setInterval(timer, 0.1);
If you are not familiar with setInterval <- click the link :)

This code worked perfectly on any browser except IE 8 and below.
I sat for hours trying to sort it out, and finely found the problem.

IE is too slow to make this loop work... (WTF?)
So i changed it to setInterval(timer, 1); And tested it on few computers..

Only fast PCs could run this code on IE.. but on other browsers it worked perfectly even on slow PCs.

SO.... i changed the line to setInterval(timer, 10); and its finely did the job.

This article was written to tell you DO NOT USE IE.

Friends doesn't let friends use Internet Explorer.

Facebook Comments Integration

Hey, 
This time i'll show you how to integrate Facebook Comments into your website using 
  1. Facebook JavaScript SDK
  2. XFBML

First of all Sign up to Facebook ;) (Duh)

After you have an account you need to verify your self as a developer.
You need to go Here and follow the steps, a code will be sent to your Phone and you need to type it there and you will get confirmed.

Now you need to sign up for an application go here - Create an Application.
And fill in the necessary fields.
Notice: You may get "Sorry, an error has occurred" - This is bullshit !

After you get this error or succeeds to create application go to My Applications.
Inside your application you'll see Application ID, We will use it later.
Notice: It can take between 2 to 20 minutes until it will be ready to use.


Now go to the page that you want to the FB Comments to it, go to your <html> tags and add this line inside the tag: xmlns:fb="http://www.facebook.com/2008/fbml"
So now your <html> tag should look like this: 


<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
After the <body> tag add this:
<body>
<div id="fb-root"></div>
<script src="http://static.ak.fbcdn.net/connect/en_US/core.js"></script>
<script>
    FB.init({ apiKey: 'YOUR APP ID',
              status: true,
              xfbml: true });
    FB.XFBML.parse();
</script>

And change 'YOUR APP ID' to the  Application ID we got before.
Now go to Comments Social Plugin on facebook, and generate the code you would like to use.


for an example i use:
<div id="RectFacebookComments">
    <fb:comments xid="123" width="640" canpost="true" candelete="true"></fb:comments>
</div>
Now offcourse that we want a Dynamic xid...
This is how you do it in ASP .NET (C#):
Go to the page.cs file and create a method that returns the ID you want as a string:
public string GetID()
{
    if (Request["id"] != null)
        return Request["id"].ToString();
    return "";
}
And change xid="123" to  <%GetID();%> :)
Thats it your done :D
Let me know if you have any questions ;-)