Get all file name, file creation date include subdirectory C#


String[] allfiles = Directory.GetFiles(@"C:\Users\agung\Downloads\Test", "*.*",
 System.IO.SearchOption.AllDirectories);
 Console.WriteLine(allfiles.Length);
 for (int i = 0; i < allfiles.Length;i++ )
 {
 Console.WriteLine(allfiles[i]);
 FileInfo TheFile = new FileInfo(allfiles[i]);
 //Console.WriteLine(TheFile.CreationTime.ToString());
 if (TheFile.CreationTime.ToString().Equals("28/02/2014 8:09:53"))
 {
 Console.WriteLine("Masuk");
 // Console.WriteLine(TheFile.CreationTime);
 }
 }

CREATE BATCH FILE BACKUP MYSQL

echo off
set hour=%time:~0,2%
if “%hour:~0,1%” == ” ” set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if “%min:~0,1%” == ” ” set min=0%min:~1,1%
echo min=%min%

set year=%date:~-4%
echo year=%year%
set month=%date:~4,2%
if “%month:~0,1%” == ” ” set month=0%month:~1,1%
echo month=%month%
set day=%date:~7,2%
if “%day:~0,1%” == ” ” set day=0%day:~1,1%
echo day=%day%

set datetimef=%year%%month%%day%_
echo datetimef=%datetimef%
echo datetimef=%datetimef%

mysqldump pintar -uroot -pYOUR_MYSQL_PASSWORD > %datetimef%pintar.sql
mysqldump dona -uroot -pYOUR_MYSQL_PASSWORD > %datetimef%dona.sql
mysqldump ps -uroot -pYOUR_MYSQL_PASSWORD > %datetimef%ps.sql
mysqldump meetmon -uroot -pYOUR_MYSQL_PASSWORD > %datetimef%meetmon.sql
mysqldump corporateagenda -uroot -pYOUR_MYSQL_PASSWORD > %datetimef%canda.sql

mysqldump pintar -uroot -pYOUR_MYSQL_PASSWORD > Z:\MYSQL86\%datetimef%pintar.sql
mysqldump dona -uroot -pYOUR_MYSQL_PASSWORD > Z:\MYSQL86\%datetimef%dona.sql
mysqldump ps -uroot -pYOUR_MYSQL_PASSWORD > Z:\MYSQL86\%datetimef%ps.sql
mysqldump meetmon -uroot -pYOUR_MYSQL_PASSWORD > Z:\MYSQL86\%datetimef%meetmon.sql
mysqldump corporateagenda -uroot -pYOUR_MYSQL_PASSWORD > Z:\MYSQL86\%datetimef%canda.sql

CodeIgniter MSSQL (SQLSRV)

After struggling for a day, manage to configure CodeIgniter with MSSQL using sqlsrv drivers. Please note that I’m not using mssql or odbc drivers. I have not tried with those two drivers yet.

Before I go forward following is my environment
CodeIgniter – 2.1.3
XAMPP – PHP (5.4.7), Apache (2.4)
MSSQL  – MS SQL Express edition 2008 R2
SQL Drivers :  php_pdo_sqlsrv_54_ts.dll,php_sqlsrv_54_ts.dll [Download it from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=20098%5D Download SQLSRV30.EXE instead version 2 SQLSRV20.EXE

Following are the steps to configure

  •  Download the SQL drivers from the above link
  •  Copy  php_pdo_sqlsrv_54_ts.dll,php_sqlsrv_54_ts.dll and paste it in the php extension folder [php/ext/]
  •  Configure php.ini
    – Add the following lines into php.ini
    extension=php_pdo_sqlsrv_54_ts.dll
    extension=php_sqlsrv_54_ts.dll
  • Configure  – CodeIgniter
    – Open the file database.php [application/config/database.php]
    – Configure the Database settings accordingly. Following is example that suites my environment
    $active_group = 'default';
    $active_record = TRUE;
    $db['default']['hostname'] = 'WIN-VM2P2F1SHSN\MANJU';//Use the SQL Server instance instead with port
    $db['default']['username'] = 'sa'; //DB Username
    $db['default']['password'] = 'pass1234'; //DB Password
    $db['default']['database'] = 'db_radius'; //DB Name
    $db['default']['dbdriver'] = 'sqlsrv'; //Drivers
    $db['default']['dbprefix'] = '';
    $db['default']['pconnect'] = FALSE;
    $db['default']['db_debug'] = TRUE;
    $db['default']['cache_on'] = FALSE;
    $db['default']['cachedir'] = '';
    $db['default']['char_set'] = 'utf8';
    $db['default']['dbcollat'] = 'utf8_general_ci';
    $db['default']['swap_pre'] = '';
    $db['default']['autoinit'] = TRUE;
    $db['default']['stricton'] = FALSE;
  •  Restart the web server and test the following code with your database settings just to make sure connection is working
    <?php
    $serverName = "WIN-VM2P2F1SHSN\MANJU"; //serverName\instanceName
    $connectionInfo = array( "Database"=>"db_radius", "UID"=>"sa", "PWD"=>"pass1234");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn ) {
    echo "Connection established.<br />";
    }else{
    echo "Connection could not be established.<br />";
    echo "<pre>";
    print_r(sqlsrv_errors());
    echo "</pre>";
    }
    ?>
  • I have attached entire codeIgniter source code. Please configure and change the parameters accordingly to make it work Download
  • Note that for some operating systems you might need to install Microsoft SQL Server 2012 Native Client. Please check here for more info http://php.net/manual/en/sqlsrv.requirements.php

Codeigniter Send mail

1. Setting di config.php:
$config[‘mail’][‘protocol’] = ‘smtp’; $config[‘mail’][‘smtp_host’] = ‘ssl://smtp.googlemail.com’; $config[‘mail’][‘smtp_port’] = ‘465’; $config[‘mail’][‘smtp_user’] = ‘m.rifqi.rosyid@gmail.com’; $config[‘mail’][‘smtp_pass’] = ‘rifiqi123’; $config[‘mail’][‘mailtype’] = ‘html’; $config[‘mail’][‘starttls’] = true; $config[‘mail’][‘newline’] = “\r\n”;
2. Buat method untuk mengirim email:
private function sendEmailNotification($username, $email){ $this->load->library(’email’, $this->config->item(‘mail’)); $this->email->from(‘admin@pasbandara.com’, ‘Petugas Verificator’); $this->email->to($email); $this->email->subject(‘Notifikasi Permohonan Pas Bandara’); $content = “Salam ” . $username . “,\n\n”; $content .= “Proses pendaftaran account untuk pembuatan Pas Bandara sudah disetujui.\n\n”; $content .= “Untuk mengajukan permohonan pembuatan Pas Bandara, silakan login dengan account yang telah aktif. \n\n”; $content .= “Terimakasih,\n”; $content .= “Kepala Administrasi Bandara”; $this->email->message($content); $this->email->send(); echo $this->email->print_debugger(); }

PHP Manual Send Mail

Kali ini saya akan sedikit share mengenai langkah-langkah mengirim email dengan phpmailer menggunakan SMTP Google. Beberapa hari ini memang lagi dibuat pusing dengan yang satu ini. Sempat googling kesana kemari tapi tidak ada yang berhasil, alhamdulillah mungkin Allah mengerti sy sudah cape’ (hehehe), akhirnya ketemu blog na Mr.Zee, sekalian aj sy share ke sobat sekalian.

 

  • Sebelumnya siapkan dulu “phpmailer” na, bisa download di sini
  • Kemudian extract ke document root sobat. Ubah nama foldernya menjadi “phpmailer” (tanpa kutip)
  • Setelah itu kita buat skrip untuk kirim emailnya. Buka text editor sobat (notepad pun jadi), lalu copas baris-baris kode berikut:
<?php
include('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
//$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "localhost"; // SMTP server
//IsSMTP(); // send via SMTP
$mail->Host     = "ssl://smtp.gmail.com"; // SMTP server Gmail
$mail->Mailer   = "smtp";
$mail->SMTPAuth = true; // turn on SMTP authentication

$mail->Username = "username@gmail.com"; // 
$mail->Password = "password"; // SMTP password
$webmaster_email = "username@domain.com"; //Reply to this email ID
$email = "emailtujuan@domain.com"; // Recipients email ID
$name = "namapenerima"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "namapengirim";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"namawebmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Ini adalah Email HTML";
$mail->Body = "Ini adalah email contoh"; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body 
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
  • Edit kode di atas sesuai data sobat
  • Simpan di document root dengan nama mail.php
  • Jadi sekarang di dalam document root kita sudah ada file mail.php dan folder phpmailer
  • Eits,, jangan langsung dieksekusi ya! (hehehe), masih ada beberapa konfigurasi lagi yang harus dirubah.
  • Buka file class.smtp.php yang berada di dalam direktori phpmailer
  • Cari baris berikut //connect to the smtp server
  • Lalu tambahkan baris-baris kode berikut tepat di bawahnya
     $host = “ssl://smtp.gmail.com”;
$port = 465;
  • Simpan hasil konfigurasi.
Langkah terakhir saatnya pengujian. Buka browser sobat lalu ketikkan alamat URL server lokasi file mail.php yang sudah kita buat. misalnya (localhost/platinum/mail.php). Jika berhasil maka akan tampil pesan “Message has ben sent” pada layar.
Telah dicoba dan berhasil O_O thx to Mr.Zee

Acces database Sql server LAN / from another machine

The following article explains how to allow SQL Server Express to accept remote connections over TCP/IP for port 1433. By default, when SQL Server Express is installed it gerates a random port to listen on. In addition, SQL Server Express only listens for connection on localhost. Using the SQL Server Configuration Manager, you will need to tell SQL Server Express to use port 1433.

To allow SQL Server Express to accept remote connections, please follow these steps:

1) Log into your server through Remote Desktop Connection (instructions for connecting to your server through RDC can be found here).

2) Click StartProgramsMicrosoft SQL Server 2005/2008/2012 and select SQL Server Configuration Manager.

3) Select SQL Server Network Configuration

4) Double click on Protocols for SQLEXPRESS

5) Right click TCP/IP and select Properties

6) Scroll down to IPAll make sure TCP Dynamic Ports is blank and that TCP Port is set to 1433.

7) Click OK

8) Make sure that port: 1433 is enable on your VDS firewall (instructions for enabling firewall ports can be foundhere).

9) Mixed mode authentication must also be enabled for remote connections (instructions for enabling firewall ports can be found here).

10) Make sure that the SQL Browser is enabled and running.