Thursday, September 23, 2010

Enable xp_cmdshell

---- To allow advanced options to be changed.
EXEC sp_configure ‘show advanced options’, 1
GO

—- To update the currently configured value for advanced options.
RECONFIGURE
GO

—- To enable the feature.
EXEC sp_configure ‘xp_cmdshell’, 1
GO

—- To update the currently configured value for this feature.
RECONFIGURE
GO

SOURCE

Sunday, June 20, 2010

[Article] How to hide the smarty template files

The first and easiest approach is to put your template directory outside of the root directory (www in wamp, htdocs in xampp). However several hosting providers do not allow this.

You can also specify a .htaccess file, as this:
<Files ~ "\.(tpl|inc|cfg)$">
order deny,allow
deny from all
</files>

(thanks for scuzzy from Smarty forum for this code)

Other way is to give a name to your template file or template directory that cannot be guessed (like a hash code). However all of these have weaknesses. What if you can't specify an access file and your provider haven't blocked the directory listing (in the latter case you could also use a blank index.php).

At last I present the best solution. Create every template file with the following structure:

<!--{if $does_not_exist}-->
<?php
die("You can't access the tamplete file");
?>
{else}
<html>
<body>
Hello, {$name}!
</body>
</html>
{/if}


And save it with a .php extension, instead of a .tpl. If someone tries to access this file directly, he will only see the "You can't access the template file" string. Viewing the source he will also see the "<!--{if $does_not_exist}-->" comment, but that won't hurt anyone. The code works like this: the template engine will check for the variable, and because it wont find the variable specified (hopefully) it wont execute the php snippet. If accessed directly, the Smarty snippet wont be parsed, hence the first PHP code will hide the rest of the file returning with a message. Works as a charm.

EDIT: You could also try to play with the idea, for example, moving the comment inside the PHP, but even like this some wierd comments will appear:

<?php
//{if $does_not_exist}
die("You can't access the tamplete file");
?>
{else}
<html>
<body>
Hello, {$name}!
</body>
</html>
{/if}

Thursday, May 27, 2010

Not a nullale type - C# 2008

Complete error:
Cannot convert null to 'myNameServer.myStructName' because it is a non-nullable value type

Use class instead of struct.

(temporary solution only, hopefully this post will be edited)

Enums in C#

correct usage:

class myClass
{
public enum myEnumType {Value1, Value2};
public myEnumType myEnumVariable;
}

class myOtherClass
{
public myFunction()
{
myClass foo = new myClass();
foo.myEnumVariable = myClass.myEnumType.Value1;
}
}

Monday, May 17, 2010

Number only text box - C# Express Edition

private void txt_FieldName_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
e.KeyChar = '\0';
}

Monday, April 12, 2010

DTS in SQL Studio 2008

Download here

1. Download and isntall the latest Microsoft SQL Server 2005 Backward Compatibility Components (It is for 2008 also)
2. Download and install the latest Microsoft SQL Server 2000 DTS Designer Components
3. Try right-clicking on a DTS package and select Open. If you still get the error, follow these steps:
a) Copy the files, SEMSFC.DLL, SQLGUI.DLL, and SQLSVC.DLL, from the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn folder to the %ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE folder.
b) Copy the files, SEMSFC.RLL, SQLGUI.RLL, and SQLSVC.RLL, from the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\1033 folder to the %ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Resources\1033 folder.
(Reference: http://msdn.microsoft.com/en-us/library/ms143755.aspx )