WordPress block trackback
All those annoying sites trackback all kind of spam …
You want to stop that?
Easy,
Turn off trackback and ping back from Admin
Settings -> Discussion ->
uncheck : Allow link notifications from other blogs (pingbacks and trackbacks.) .
After this, to prevent the ping/trackback for existing posts, run this sql command:
or … the hard way, edit all posts and disable pingback
MSSQL Change Table Column name
to change a column name in MSSQL, run this query:
SQL Table Ownership Change
To change sql table owner from a name to dbo, use this sql:
SELECT @crtOwner= 'currentOwner_ToChange', @newOwner = 'dbo'
, @SQL = '
IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES
WHERE
QUOTENAME(TABLE_SCHEMA)+''.''+QUOTENAME(TABLE_NAME) = ''?''
AND TABLE_SCHEMA = ''' + @crtOwner+ '''
)
EXECUTE sp_changeobjectowner ''?'', ''' + @newOwner + ''''
EXECUTE sp_MSforeachtable @SQL
For stored procs, execute this stored proc to get the sqls required for changing the owner.
Then copy the resulted sqls and run them in a new query.
SELECT @crtOwner= 'currentOwner_ToChange', @newOwner = 'dbo'
SELECT 'EXECUTE sp_changeobjectowner '''+QUOTENAME(a.SPECIFIC_SCHEMA)+
'.'+QUOTENAME(a.ROUTINE_NAME)+
''','''+@newOwner+''''
FROM
INFORMATION_SCHEMA.ROUTINES a
WHERE
a.ROUTINE_TYPE = 'PROCEDURE'
AND a.SPECIFIC_SCHEMA = @crtOwner
AND
OBJECTPROPERTY(OBJECT_ID(QUOTENAME(a.SPECIFIC_SCHEMA)+'.'+QUOTENAME(a.ROUTINE_NAME)), 'IsMSShipped') = 0
for views:
SELECT
@crtOwner = 'currentOwner_ToChange', @newOwner = 'dbo'
SELECT 'EXECUTE sp_changeobjectowner '''+QUOTENAME(a.TABLE_SCHEMA)+'.'+QUOTENAME(a.TABLE_NAME)+''','''+@newOwner+''''
FROM
INFORMATION_SCHEMA.VIEWS a
WHERE
a.TABLE_SCHEMA = @crtOwner
AND
OBJECTPROPERTY(OBJECT_ID(QUOTENAME(a.TABLE_SCHEMA)+'.'+QUOTENAME(a.TABLE_NAME)), 'IsMSShipped') = 0
MSSQL function to return the date part from a datetime
in MSSQL, to return only the date part from a datetime ,
use this function:
AS
BEGIN
DECLARE @Today AS DATETIME
SET @Today = DATEDIFF(dd, 0, @dt)
RETURN @Today
END
An alternative approach:
This provides quick support to convert the date in any format. The table which suggest the date formats are displayed on MSDN:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
Some claims that using CONVERT is slower than using DATE functions, i made some tests and find out that it is approximately the same thing.
For a loop with 2 million iterations, the elapsed time for first approach was: 8186 ms, for the second approach was: 8253 ms.
ASP.NET IIS Error display as garbage
Recently got into the situation that my .NET application displayed garbage instead of the error. Not to pleasant to work like this.
�`I�%&/m�{J�J��t��`$ؐ@������iG#)�*��eVe]f@�흼��{���{���;�N’���?\fdl��J�ɞ!���?~|?”��Ey�’)=��y6����h���ly���,-��E;Oϫ:��’Y�o��N��Y�����]i�h���tRͮ�_|^-���lQ�>�ɼ�e��C��*/.��eU/�R>j����|q8�ʪ~4)����_�zpW�����b��V�G���ջ_��z������w�_�� �7�݃U����,
After some researches, discovered that my app was using Telerik compression, thus the displayed ascii instead of the actual error.
What i did, was to comment the line that added the compression in Web.config (on the dev machine only, since on the production will still be needed)
This key (or other key that adds a compression) may appear more times in web.config, i removed it from the system.webServer node, and finally got the error display correctly.
ASP.NET Export GridView data to Excel
The easiest way in asp.net to export the data from a grid view to excel, is to render the control as html and save the file.
Excel knows how to open a html file and display it correctly. The only drawback to this method is that only one sheet will be available.
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving then
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
this.grdData.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
GridView RenderControl
When trying to render a gridview as html,
you may encounter the following errors:
1. Control of type ‘GridView’ must be placed inside a form tag with runat=server.
This error occurs because the GridView is already placed in a form (usually the one from the master page)
To fix this, either override the function VerifyRenderingInServerForm like this:
{
// Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time
return;
}
or remove the grid control before rendering it, and add them back after render
int GridIndex = 0;
if (parent != null)
{
GridIndex = parent.Controls.IndexOf(grid);
parent.Controls.Remove(grid);
}
grid.RenderControl(hw);
if (parent != null)
{
parent.Controls.AddAt(GridIndex, grid);
}
Another alternative to avoid the override is to do this:
grid.HeaderRow.RenderControl(hw);
foreach (GridViewRow row in grid.Rows)
{
row.RenderControl(hw);
}
grid.FooterRow.RenderControl(hw);
grid.RenderEndTag(hw);
2. asp.net RegisterForEventValidation can only be called during Render()
in this case, add in the aspx page, in the page tag, the directive: EnableEventValidation =”false”
Like this:
In this case, if you run on a framework >= 3.5, you also need in web.config, the entry: httpRuntime requestValidationMode=”2.0″, in the system.web tag, like this:
............
<system.web>
............
<httpRuntime requestValidationMode="2.0"/>
</system.web>
</configuration>
align 3 divs, 2 fixed sides and the middle div auto size
How to align 3 divs using only css, from which 2 have fixed sides and the middle one will auto fit.
<html>
<head>
<style type="text/css">
body { min-width: 630px; }
#header { background-color:brown; }
#mainContent { width:1000px; margin:0px auto; }
#container { padding-left: 200px; padding-right: 190px; }
#container .column { position: relative; float: left; }
#center { padding: 10px 20px; width: 100%; background-color:green; }
#left { width: 180px; padding: 0 10px; right: 240px; margin-left: -100%; background-color:blue; }
#right { width: 130px; padding: 0 10px; margin-right: -190px; background-color:red; }
#footer { clear: both; background-color:brown; }
/*** IE Fix ***/
* html #left { left: 150px; }
</style>
</head>
<body>
<div id="mainContent">
<div id="header">header</div>
<div id="container">
<div id="center" class="column">mid container</div>
<div id="left" class="column">left side</div>
<div id="right" class="column">right side</div>
</div>
<div id="footer">footer</div>
</div>
</body>
</html>
PHP – Create a hierarchical menu based on the category level
Having an array of categories as a tree (parent->childs relations), retrieved in the desired order, i.e.:
category1
|—subcategory 1_1
|——subcategory 1_1_1
|——subcategory 1_1_2
category2
|—subcategory2
category 3
To display them in the above order, using ul and li tags:
foreach($objCategoriesList->Records as $recordItem)
{
if ($recordItem->Level > $prevLevel) echo '<ul><li>';
else if ($recordItem->Level == $prevLevel) echo '</li><li>';
else if ($recordItem->Level < $prevLevel)
{
for ($levIndex = $recordItem->Level; $levIndex < $prevLevel; $levIndex++)
{
echo '</li></ul>';
}
echo '</li><li>';
}
echo '<a href="categories.php?cat=' .$recordItem->UrlKey.'">' .$recordItem->Name .'</a>';
$prevLevel = $recordItem->Level;
}
echo '</li></ul>';
If there are also articles to be added:
$selectedClass = '';
if ($currentCategory != null)
{
$arrTreeList = $objCategoriesMap->GetTreeList($currentCategory->CategoryId);
if ($arrTreeList != null)
{
$currentCategoryStart = false;
foreach($arrTreeList as $recordItem)
{
if ($currentCategory->CategoryId == $recordItem->CategoryId) $selectedClass = 'class="selected"';
else $selectedClass = '';
if ($recordItem->Level <= $currentCategory->Level && $currentCategoryStart)
{
include("blocks/articles_list_nav.php");
$currentCategoryStart = false;
}
if ($recordItem->Level > $prevLevel) echo '<ul><li>';
else if ($recordItem->Level == $prevLevel) echo '</li><li>';
else if ($recordItem->Level < $prevLevel)
{
for ($levIndex = $recordItem->Level; $levIndex < $prevLevel; $levIndex++)
{
echo '</li></ul>';
}
echo '</li><li>';
}
$prevLevel = $recordItem->Level;
if ($currentCategory->CategoryId == $recordItem->CategoryId)
$currentCategoryStart = true;
echo '<a '.$selectedClass. ' href="link_' .$recordItem->UrlKey .'.html">' .$recordItem->Name .'</a>';
}
echo '</li></ul>';
}
}
Htaccess file for redirect
– some servers will require this option enabled
#Options +FollowSymlinks
– if the apache server has mod_rewrite enabled
<IfModule mod_rewrite.c>
– redirect 301 all files that are found in the folder : /home/viewcity/ , to the specified url (using regular expressions)
RedirectMatch 301 /home/viewcity/(.+)$ http://www.meteovremea.com/meteo-vremea-in-$1.html
RewriteEngine On
– if the REQUEST_URI does not start with /google91849e903c5ce132.html , then will apply the rules
RewriteCond %{REQUEST_URI} !^/google91849e903c5ce132.html
– all files that starts with getforecast will be processed trough the file forecast.php
RewriteRule ^getforecast(.+)$ forecast.php?str=$1 [L]
– all files that starts with getpartforecast/ will be processed trough the file forecast_partners.php
RewriteRule ^getpartforecast/(.+)$ forecast_partners.php?str=$1 [L]
– all files that starts with city_details_ and ends in .html will be processed trough the file city_details.php
RewriteRule ^city_details_(.+)\.html$ /city_details.php?pl=$1 [L]
</IfModule>