Categories
Dynamic PR website marketing

Dynamic Website PR Images

Dynamic PRWeb Backlinks Dynamic PR is a FREE service for website owners who want to show website PR images dynamically on their website. The website PR image shows the current google page rank for the given page. Dynamically display website PR images in your site NOW by including the html code in the text box below, no sign up necessary.

<img src="http://pr.web-backlinks.com/pr.php?domain=[DOMAIN]" />

Replace [DOMAIN] with the site you want to display the PR image for, for example:

<img src="http://pr.web-backlinks.com/pr.php?domain=google.com" />

For more information and details about conditions of use, please visit our dynamic PR home page at http://pr.web-backlinks.com

Categories
Apache PHP

Configuring PHP in Apache

To enable PHP in Apache you need to do the following.

You need to tell PHP the root directory of Apache ie. In PHP.INI change the doc_root variable so that it holds the root directory of Apache:

Change PHP.INI (Usually located in [DRIVE]:\PHP\) entry for doc_root:

doc_root = "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"

Add the following lines in HTTPD.CONF (Usually located in [DRIVE]:\Program Files\Apache Software Foundation\Apache2.2\conf\):

ScriptAlias /php/ "C:/Program Files/PHP/"
AddType application/x-httpd-php .php .php5
Action application/x-httpd-php "/php/php-cgi.exe"
SetEnv PHPRC "C:/Program Files/PHP"

DirectoryIndex index.html index.php

Remove deny all from the following entry in HTTPD.CONF:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

So that the new entry looks similar to:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
</Directory>

That’s it… Happy coding!

Categories
C# Programming

Convert XLS file to CSV file using C#

I stumbled upon this great article by Yuan Wang which allowed you to convert an XLS file into CSV in C# (Convert XLS into CSV). It was created and compiled using Visual Studio 2005. I copied the code and compiled it in VS 2008 and it compiled OK but when I ran it, I got the following exception:

C:\Documents and Settings\d205414\My Documents\Visual Studio 2008\Projects\XlsToCsv\XlsToCsv\obj\Release>XlsToCsv.exe
System.Data.OleDb.OleDbException: Could not find installable ISAM.
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString cons
tr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOpti
ons options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection o
wningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbC
onnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection ow
ningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection ou
terConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()
   at XlsToCsv.Program.convertExcelToCSV(String sourceFile, String worksheetName
, String targetFile) in C:\Documents and Settings\d205414\My Documents\Visual St
udio 2008\Projects\XlsToCsv\XlsToCsv\Program.cs:line 51

I made a few modifications to the source, to fix the exception but also allow the executable to accept parameters. Here’s the modified source code:

using System;
using System.IO;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;

namespace XlsToCsv
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string sourceFile, worksheetName, targetFile, skipHeader;
                sourceFile = args[0]; worksheetName = "Sheet1"; targetFile = args[1]; skipHeader = args[2];
                convertExcelToCSV(sourceFile, worksheetName, targetFile, skipHeader);
            }
            catch
            {
                Console.WriteLine("USAGE: XlsToCsv [XLS File] [CSV File] [Skip Header? Yes/No]");
            }
        }

        static void convertExcelToCSV(string sourceFile, string worksheetName, string targetFile, string skipHeader)
        {
            string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=" + sourceFile + ";" + @"Extended Properties=""Excel 8.0;HDR=" + skipHeader + @";IMEX=1""";

            OleDbConnection conn = null;
            StreamWriter wrtr = null;
            OleDbCommand cmd = null;
            OleDbDataAdapter da = null;

            try
            {

                conn = new OleDbConnection(strConn);
                conn.Open();

                cmd = new OleDbCommand("SELECT * FROM [" + worksheetName + "$]", conn);
                cmd.CommandType = CommandType.Text;
                wrtr = new StreamWriter(targetFile);

                da = new OleDbDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);

                for (int x = 0; x < dt.Rows.Count; x++)
                {
                    string rowString = "";
                    for (int y = 0; y < dt.Columns.Count; y++)
                    {
                        rowString += "\"" + dt.Rows[x][y].ToString() + "\",";
                    }
                    wrtr.WriteLine(rowString);

                }

                Console.WriteLine("File converted successfully.");

            }
            catch
            {
                // Console.WriteLine(exc.ToString());
                Console.WriteLine("USAGE: XlsToCsv [XLS File] [CSV File] [Skip Header? Yes/No]");
                Console.ReadLine();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
                conn.Dispose();
                cmd.Dispose();
                da.Dispose();
                wrtr.Close();
                wrtr.Dispose();
            }
        }
    }
}

Save the C# code and compile in Visual Studio 2008 (I used express edition myself).

To execute, call the following in command prompt:

USAGE: XlsToCsv [XLS File] [CSV File] [Skip Header? Yes/No]

eg.

XlsToCsv source.XLS output.CSV No

Categories
Useful Scripts vbscript

VBScript to Save Web File to Computer

This post is an extension from the URL2File script that I posted previously. While the URL2File script allowed you to save web pages to a local file, the following VbScript will allow you to save a binary file on the web to a local file.

This VbScript requires Windows script hosting which you can download from:

http://www.microsoft.com/downloads/details.aspx?FamilyID=47809025-D896-482E-A0D6-524E7E844D81&displaylang=en

Save the following code as save2file.vbs:

'Wscript.Arguments(0) - Website  URL
'Wscript.Arguments(1) - Full File Path

Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2

'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary

'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write BinaryGetURL(Wscript.Arguments(0))

'Save binary data To disk
BinaryStream.SaveToFile Wscript.Arguments(1), adSaveCreateOverWrite
Function BinaryGetURL(URL)
  'Create an Http object, use any of the four objects
  Dim Http
'  Set Http = CreateObject("Microsoft.XMLHTTP")
'  Set Http = CreateObject("MSXML2.ServerXMLHTTP")
  Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
'  Set Http = CreateObject("WinHttp.WinHttpRequest")

  'Send request To URL
  Http.Open "GET", URL, False
  Http.Send
  'Get response data As a string
  BinaryGetURL = Http.ResponseBody
End Function

To run the script in a command prompt session:

save2file.vbs [URL] [FULL OUTPUT FILE PATH]
eg. save2file.vbs http://localhost/test.XLS c:\temp\test.XLS

Categories
Oracle PL/SQL

HTTP Post from Oracle PL/SQL

I recently needed to execute a HTTP post from an ApEx application to another web page running as some sort of a service. For added security the web page service only accepted POST requests and one of the parameters passed is a secret password (not encrypted but secure enough for an Intranet application).

Anyway the requirement was to post the request using PL/SQL to the web service, and receive the response. I visited the oracle page on UTL_HTTP for a bit of reference and came up with the following code:


set serveroutput on;
exec dbms_output.enable(1000000000);
set escape '\'

DECLARE
  req   UTL_HTTP.REQ;
  resp  UTL_HTTP.RESP;
  value VARCHAR2(1024);  -- URL to post to
  v_url VARCHAR2(200) := 'http://T97040476TA9000/core_dmt/withdraw_job.php';
  -- Post Parameters
  v_param VARCHAR2(500) := 'pwd=password123\&core_id=12223\&type=PK\&reason=Test reason';
  v_param_length NUMBER := length(v_param);
BEGIN
  -- Set up proxy servers if required
  --  UTL_HTTP.SET_PROXY('proxy.my-company.com', 'corp.my-company.com');
  req := UTL_HTTP.BEGIN_REQUEST (url=> v_url, method => 'POST');
  --  UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
  UTL_HTTP.SET_HEADER (r      =>  req,
                       name   =>  'Content-Type',
                       value  =>  'application/x-www-form-urlencoded');
  UTL_HTTP.SET_HEADER (r      =>   req,
                       name   =>   'Content-Length',
                       value  =>   v_param_length);
  UTL_HTTP.WRITE_TEXT (r      =>   req,
                       data   =>   v_param);  resp := UTL_HTTP.GET_RESPONSE(req);
  LOOP
    UTL_HTTP.READ_LINE(resp, value, TRUE);
    DBMS_OUTPUT.PUT_LINE(value);
  END LOOP;
  UTL_HTTP.END_RESPONSE(resp);
EXCEPTION
  WHEN UTL_HTTP.END_OF_BODY THEN
    UTL_HTTP.END_RESPONSE(resp);
END;
/

The only thing you need to change to make the code work for you are the v_url and the v_param values to reflect the url of your service and the parameters it expects.

Happy Coding!

Categories
dynamic web thumbnails

FREE Website Thumbnails

Web BacklinksWant to show web thumbnail preview in your site dynamically? Then Web Backlinks Website Thumbnail Service may be able to help you.

Web Backlinks Website Thumbnail Service is a FREE service for website owners who want to show website thumbnail previews on their website. If a website thumbnail is accessed but does not exist on our servers then the request is automatically queued for processing and is made available within 24 hours. Dynamically generate website thumbnails in your site NOW, no sign up necessary.

Visit http://webthumb.web-backlinks.com/ for more details.