Can you pls help me, how to create a new web page in SharePoint and also i want to do javascript validation also in that page is it's possible pls guide me.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Security;
using System.Diagnostics;
using System.Collections;
using System.Threading;
using System.Reflection;
using System.Windows.Forms;
namespace e_FTP
{
#region Documentation
// Author : Santosh
// Date Started :
// Date Completed :
// Rev 001
// Requester : Natalie, KH Lim
// Description : Program to move files from source to target using FTP. The Target information and
// other details are found in the Souce configuration file 'toftp.XXXX'.
// Local Application
// : 1) Get the Source server detail from system config file.
// : 2) Use the Source server details to login and get the first toftp.XXXX from the Source directory.
// : 3) Open the toftp.xxxx and get the information to FTP from Source to Target.
// Source FTP
// : 3) Use the list of files in the toftp.XXXX and check the files exists else log email, exit and
// continue with next toftp.XXXX.
// : 4) If files exists, use the toftp.xxxx details to download the file in the Source directory to
// the local directory and get the size of the local file.
// : 5) Check the local file size is equal or greater than the source file size.
// : 6) If fail download or size wrong, keep the information and continue with next file in the toftp.XXXX.
// : 7) If any of the file missing move all local files to fail dir log, email with the error information
// for all missing files and exit to next toftp.XXXX.
// : 8) When all the files are downloaded successfully to local.
// : 9) Sent success email to email as per list in System.config.
// FTP to Target
// : 7) Delete all the files with same file name in target directory and replace. For 'repacef'
// if file exists log, email and exit.
// : 8) Upload the file from Local to Target server and check the target and local size to be same.
// : 9) If fail upload or size wrong, Delete target files, log, email and move all local files with
// Times Stamp to fail dir. Exit and continue with next toftp.XXXX.
// : 10) Upon successfull ftp to target, the Source toftp.XXXX will be rename to done.toftp.XXXX,
// The local toftp.XXXX and Local files will be Times Stamped and moved to the Success directory.
// : 11) Sent success email to email as per list in System.config.
// : 12) Repeat till all toFTP files in the Source is serviced.
// Local Application
// : 13) For above Source and target operations, if have email ID in notify in toftp.XXXX, sent
// emails to email ID for success and fail.
// : 14) Hosekeeping
// a) Keep the Success and Fail dir files for set period.
// b) Keep the log file consistent.
#endregion
#region Test Plan
// Testing Plan: For Source FTP
// 1. Test the Source FTP with wrong IP Address
// - Log into the Log file and send error email. Exit the application.
// 2. Test the Source FTP with wrong UserID and Password
// - Log into the Log file and send error email. Exit the application.
// 3. Test the Source FTP with the wrong source directory
// - Log into the Log file and send error email. Exit the application.
// 4. Test the Source FTP with no file exists in the source directory
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 5. Test the downloading file from Source to Local directory if Local
// file size and Source file size is not the same.
// - Log into the Log file and send error email.Put the file to the fail directory.
// - Go for next toftp.xxxx.
// 6. Test the downloading file from Source to Local directory under normal condition.
// - Log to log file.
// Testing Plan: For Target FTP
// 1. Test the Target FTP with wrong IP Address
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 2. Test the Target FTP with wrong UserID and Password
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 3. Test the Target FTP with the wrong source directory
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 4. Test the Target FTP with no file exists in the source directory
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 5. Test the Target FTP with write permission removed.
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 6. Test the uploading file from Local to Target directory if Local
// file size and Target file size is not the same.
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 7. Test the Target FTP with normal condition.
// - Log to log file
#endregion
class Program
{
static void Main(string[] args)
{
string RunningProcess = Process.GetCurrentProcess().ProcessName;
Process[] processes = Process.GetProcessesByName(RunningProcess);
if (processes.Length > 1)
{
//Console.WriteLine("One instance is already running");
Environment.Exit(1);
}
////Process current = Process.GetCurrentProcess();
////foreach (Process process in Process.GetProcessesByName(current.ProcessName))
////{
//// if (process.Id == current.Id)
//// {
//// Console.WriteLine("One Instance is already running");
//// }
////}
//define the local variables
string ip_address = string.Empty; // IP Address of the Source file
string user_id = string.Empty; // User ID of the Source file
string password = string.Empty; // Password of the Source file
string source_dir = string.Empty; // Directory of the Source file
string local_dir = string.Empty; // Local Directory to put the Source file
string success_dir = string.Empty; // Success Directory to put the file uploaded successfully
string fail_dir = string.Empty; // Fail Directory to put the fail file
string sub = string.Empty; // The reporting server database name
string content = string.Empty; // The content prepared to send the email
string success_email = string.Empty; // Success email to send after successfully upload
string fails_email = string.Empty; // Fail email to send on any fail during upload or download
string return_val = string.Empty; // The value returned from different methods
string notify = string.Empty; // The additional email from toftp.xxxx file
string log_file = string.Empty; // The location of the Log File
int backup_days; // To keep the backup of the file for some days
long logfile_size; // The size of the log file to maintain constant
string pass_key = string.Empty; // The security key to access the web service method for email
string msgLog = string.Empty; // The log file message
string server = string.Empty; // The server from where the application is running
string apps_name = string.Empty; // The name of the application
string subject = string.Empty; // To keep the subject while sending the email
string config_file = string.Empty; // The location of the configuration file
string sfile_name = string.Empty; // The name of the Source file
string ddir = string.Empty; // The directory of the Target FTP server
string dfilename = string.Empty; // Name of the file to upload to Target FTP server
string duserid = string.Empty; // User ID to Login the Target FTP server
string dpassword = string.Empty; // Password to Login the Target FTP server
string dipaddress = string.Empty; // IP Address to Login to Tareger FTP server
string replacef = string.Empty; // replacef is to verify whether the file has to be override or not
string succ_email = string.Empty; // The success email with notify email
string fail_email = string.Empty; // The fail email with notify email
char d = 'd';
char u = 'u';
string myIP = string.Empty;
// Get the Source server detail from system config file.
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
config_file = System.IO.Path.GetFullPath("Config.txt");
using (StreamReader reader = new StreamReader(config_file))
{
ip_address = reader.ReadLine().Trim();
user_id = reader.ReadLine().Trim();
password = reader.ReadLine().Trim();
source_dir = reader.ReadLine().Trim();
local_dir = reader.ReadLine().Trim();
success_dir = reader.ReadLine().Trim();
fail_dir = reader.ReadLine().Trim();
backup_days = int.Parse(reader.ReadLine().Trim());
logfile_size = long.Parse(reader.ReadLine().Trim());
sub = reader.ReadLine().Trim();
success_email = reader.ReadLine().Trim();
fails_email = reader.ReadLine().Trim();
log_file = reader.ReadLine().Trim();
pass_key = reader.ReadLine().Trim();
server = reader.ReadLine().Trim();
apps_name = reader.ReadLine().Trim();
reader.Close();
}
// Create an object of the Class which contains all Common Functions
Modules mod = new Modules();
Program pr = new Program();
// Create an instance of the WebService to send the email
e_FTP.iistest.Service email_service = new e_FTP.iistest.Service();
// Get the IP Address of the Machine
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
myIP = addr[addr.Length - 1].ToString();
// Use the Source server details to login and get the first Source file from first toftp.XXXX
// from the Source configuration file.
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
string[] toftp_file = mod.LoginAndGettoftpFile(ip_address, user_id, password,
source_dir, log_file, success_email, fails_email, sub, pass_key, logfile_size);
if (toftp_file == null)
{
// Log to Log file and send the fail email and exit from the application
mod.LogToLogFile(log_file, "No 'toftp.xxxx' file exists in the source FTP!",logfile_size);
subject = "CRITICAL FTP JOB FAILED - " + "No toftp_file file exists!" + " " + sub;
content = mod.ContentFromFile(source_dir, "", "", "", "", "",log_file);
content += "Source IPAddress = " + ip_address + "<br />";
content += "User ID = " + user_id + "<br />";
email_service.SendMail("ReportingServer@s.carsems.com.my", fails_email, subject, content, "", pass_key);
Environment.Exit(1);
}
long get_size = 0;
ArrayList al = null;
for (int i = 0; i < toftp_file.Length; i++)
{
if (toftp_file[i].ToString().Trim().StartsWith("toftp"))
{
msgLog = string.Empty;
// Get the source file name,notify and check for exists of source file
al = mod.CheckForSourceFileExists(ip_address, user_id, password, source_dir, toftp_file[i].ToString().Trim(), local_dir,
log_file, sub, fails_email, pass_key, logfile_size, fail_dir, success_dir);
if (al == null)
{
msgLog = " ";
}
else
{
sfile_name = al[0].ToString().Trim();
ddir = al[1].ToString().Trim();
dfilename = al[2].ToString().Trim();
duserid = al[3].ToString().Trim();
dpassword = al[4].ToString().Trim();
dipaddress = al[5].ToString().Trim();
notify = al[6].ToString().Trim();
replacef = al[7].ToString().Trim();
// Check the fileName file exists in the Success directory
return_val = mod.ChecktoftpfileInSuccessDir(success_dir,sfile_name, toftp_file[i].Trim(), ip_address, user_id, password,
source_dir, log_file, logfile_size);
if (return_val != "Y")
{
if (notify != "")
{
succ_email = success_email + "," + notify.Trim();
fail_email = fails_email + "," + notify.Trim();
}
else
{
succ_email = success_email;
fail_email = fails_email;
}
// Download the file from Source directory to Local directory and get the size of the local file
get_size = mod.FTPDownloadAndGetLength(ip_address, user_id, password, source_dir, sfile_name, local_dir, sub,
toftp_file[i].ToString().Trim(), log_file, fail_email, pass_key, logfile_size, fail_dir);
if (get_size != 0)
{
//Check the Size of the source and local file
return_val = mod.CheckFileSize(local_dir, sfile_name, get_size, toftp_file[i].ToString().Trim(),
sub, source_dir, log_file, fail_email, pass_key, "", "", "", "", fail_dir, d, logfile_size);
if (return_val == "N")
{
msgLog = " ";
}
}
else
{
msgLog = " ";
}
if (msgLog == "" && get_size != 0)
{
// Log to log file on successful Upload
mod.LogToLogFile(log_file, toftp_file[i].ToString().Trim() + " Downloaded Successfully!" + " ,Source IP= " +
ip_address + " ,Local IP = " + myIP, logfile_size);
// Upload the file from Local to Target server and check the target and local size to be same.
get_size = 0;
// Check for the replacef
if (replacef != "")
{
// Delete the existing file in the Target FTP server
return_val = mod.DeleteExistingFilesInTargetFTP(dipaddress, duserid, dpassword, ddir, dfilename,
toftp_file[i], sub, fail_email, pass_key, source_dir, log_file, local_dir, fail_dir, sfile_name, sub, logfile_size);
if (return_val == "N")
{
get_size = mod.FTPUploadAndGetLength(dipaddress, duserid, dpassword, ddir, dfilename,
local_dir, sfile_name, sub, toftp_file[i], log_file, fail_email, pass_key, source_dir,
fail_dir, logfile_size);
}
if (get_size != 0)
{
//Check the Size of the source file and destination file
return_val = mod.CheckFileSize(local_dir, sfile_name, get_size, toftp_file[i], sub, source_dir,
log_file, fail_email, pass_key, ddir, duserid, dipaddress, dfilename, fail_dir,
u, logfile_size);
if (return_val == "N")
{
msgLog = " ";
}
}
}
else
{
// Check for the file exists, if file exists prompt the error
return_val = mod.CheckForTargetFileExists(dipaddress, duserid, dpassword, ddir,
toftp_file[i].Trim(), local_dir, dfilename,
log_file, fail_email, fail_dir, sub, pass_key, logfile_size);
if (return_val == "N")
{
// Upload the file to the Customer FTP server
get_size = mod.FTPUploadAndGetLength(dipaddress, duserid, dpassword, ddir, dfilename,
local_dir, sfile_name, sub, toftp_file[i], log_file, fail_email, pass_key, source_dir, fail_dir, logfile_size);
if (get_size != 0)
{
//Check the Size of the source file and destination file
return_val = mod.CheckFileSize(local_dir, sfile_name, get_size, toftp_file[i], sub, source_dir, log_file,
fail_email, pass_key, ddir, duserid, dipaddress, dfilename, fail_dir, u, logfile_size);
if (return_val == "N")
{
msgLog = " ";
}
}
}
else
{
msgLog = " ";
}
}
if (msgLog != " " && get_size != 0)
{
// Send email on successful Upload
subject = "FTP done- " + toftp_file[i] + " " + sub;
content = mod.ContentFromFile(source_dir, toftp_file[i], ddir, dfilename, duserid, dipaddress, log_file);
content += "<br />" + "File " + sfile_name + " Uploaded Successfully!";
email_service.SendMail("ReportingServer@s.carsems.com.my", succ_email, subject, content, "", pass_key);
// Log to log file on successful Upload
mod.LogToLogFile(log_file, toftp_file[i] + " Uploaded Successfully! " + "Local IP = " + myIP +
" Coutomer IP = " + dipaddress, logfile_size);
mod.RenameSourceConfigFile(ip_address, user_id, password, source_dir, toftp_file[i], log_file, logfile_size);
// Time Stamp and Move the files FTP to success backup directory.
mod.copyDirectory(log_file, local_dir, success_dir, dfilename, logfile_size);
}
}
}
}
succ_email = string.Empty;
fail_email = string.Empty;
}
}
// Delete the older files after X days for Success and Fail backup dir
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
mod.DeleteSuccessFilesAfterXDays(log_file, success_dir, backup_days,logfile_size);
mod.DeleteSuccessFilesAfterXDays(log_file, fail_dir, backup_days,logfile_size);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
namespace e_FTP
{
#region Documentation
//Author : Santosh
//Date Started :
//Date Completed :
//Requester : Natalie, KH Lim
//Description : Reusable modules to be called by main program.
// : 1. Login to the Source FTP server,Check for toftp.xxxx file and take the directory into an
// array.
// : 2. Get the toftp.xxxx file, check for the Source file exists and get the Target FTP details.
// : 3. Get the source file and check for the file exists in the Source FTP.
// : 4. Download 1 file from Source to Local and get the length of the file in the Source.
// : 5. Check the local file size is equal or greater than the source file size and return with
// "Y" or "N".
// : 6. Delete the existing file from Target before Uploading the new file.
// : 7. Upload the file to FTP server and get the length of the file.
// : 8. Pass the Log file location and the error message to log to the log file.
// : 9. Times Stamp and move all files from local to success back up.
// : 10. Rename the Source file name to done.toftp.xxxx after successfully uploaded.
// : 11. Cut X no.of lines if log file size exceeds from a certain size.
// : 12. Delete the file after X days.
// : 13. Make the content of the email to send for success or failure.
#endregion
class Modules
{
public string root_filename = string.Empty;
public string sfile_name = string.Empty;
public string ddir_name = string.Empty;
public string dfile_name = string.Empty;
public string user_name = string.Empty;
public string password = string.Empty;
public string ip_address = string.Empty;
public string notify = string.Empty;
public string replacef = string.Empty;
public string checksize = string.Empty;
public long file_size;
string result = string.Empty;
bool ifexists = false;
string str_add = string.Empty;
ArrayList al = null;
// Create an instance of the WebService to send the email
e_FTP.iistest.Service email_service = new e_FTP.iistest.Service();
// 1. Login to the Source FTP server,Check for toftp.xxxx file and take the directory into an array.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string[] LoginAndGettoftpFile(string _sourceipadresss, string _sourceuserid, string _sourcepassword,
string _sourcepath, string _logfile, string _succemail, string _failemail,
string _sub, string _passkey, long _logfilesize)
{
string[] toftp_files = null;
string toftpfiles = string.Empty;
try
{
reqFTP = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + _sourceipadresss + "/" + _sourcepath));
reqFTP.Credentials = new NetworkCredential(_sourceuserid, _sourcepassword);
reqFTP.UseBinary = true;
reqFTP.KeepAlive = true;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
response = (FtpWebResponse)reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string all_files = reader.ReadToEnd();
all_files = all_files.Replace('\r', ' ');
all_files = all_files.Replace('\n', ',');
toftp_files = all_files.Split(',');
for (int i = 0; i < toftp_files.Length; i++)
{
if (toftp_files[i].ToString().StartsWith("toftp"))
{
toftpfiles += toftp_files[i] + ",";
}
if (toftp_files[i].Contains('/') && toftp_files[i].Contains("toftp") && !toftp_files[i].Contains("done"))
{
int indexof_toftp = toftp_files[i].IndexOf("toftp");
toftpfiles += toftp_files[i].Remove(0, indexof_toftp) + ",";
}
}
if (toftpfiles != "")
{
toftpfiles = toftpfiles.TrimEnd().Remove(toftpfiles.Length - 1);
toftp_files = toftpfiles.Split(',');
}
else
{
toftp_files = null;
}
response.Close();
reqFTP.Abort();
}
catch (Exception ex)
{
// Log to Log file and send the fail email and exit from the application
LogToLogFile(_logfile, ex.Message, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _sourceipadresss + " " + _sub;
string content = ContentFromFile(_sourcepath, "", "","", _sourceuserid, _sourceipadresss,_logfile);
content += ex.Message;
string email_reply = email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
Environment.Exit(1);
}
return toftp_files;
}
// Check the toftp.xxxx file exists in the Success Directory
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string ChecktoftpfileInSuccessDir(string _filepath,string _sfilename,string _toftpfile,string _ipaddress,string _userid,
string _password, string _sourcedir, string _logfile, long _logfilesize)
{
//string toftp_exists = string.Empty;
string file_name = string.Empty;
try
{
DirectoryInfo dirInfo = new DirectoryInfo(_filepath);
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo fi in files)
{
if (fi.Name.Contains(_sfilename.Trim()))
{
file_name = "Y";
// Rename the toftp.xxxx to done.toftp.xxxx
RenameSourceConfigFile(_ipaddress, _userid, _password, _sourcedir, _toftpfile, _logfile, _logfilesize);
// Log to the log file
LogToLogFile(_logfile, "File " + _toftpfile + " already FTPed to customer", _logfilesize);
}
}
if (file_name != "Y")
{
file_name = "N";
}
}
catch (Exception ex)
{
// Log to the log file
LogToLogFile(_logfile, ex.Message, _logfilesize);
}
return file_name;
}
// 2. Get the toftp.xxxx file, check for the Source file exists and get the Target FTP details.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public ArrayList CheckForSourceFileExists(string _sipadresss, string _suserid,string _spassword,
string _sdir, string _toftpfile, string _localfile,
string _logfile,string _sub, string _failemail, string _passkey,
long _logfilesize,string _faildir,string _succdir)
{
al = new ArrayList();
string ret_val = string.Empty;
try
{
reqFTP = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + _sipadresss + "/" + _sdir + "/" + _toftpfile));
reqFTP.Credentials = new NetworkCredential(_suserid, _spassword);
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
FileStream outputStream = new FileStream(_localfile + _toftpfile, FileMode.Create);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
reqFTP.Abort();
response.Close();
// Use toftp.xxxx to get the Source file Name
outputStream = new FileStream(_localfile + "/" + _toftpfile, FileMode.Open);
StreamReader _reader = new StreamReader(outputStream);
string FTPFileInfo = _reader.ReadToEnd();
string[] arr_FileInfo = FTPFileInfo.Split('-', '=');
// Get the Source file name from the Source config file
al = GetSourceFileInfo(arr_FileInfo);
string sfile_name = al[0].ToString();
_reader.Close();
if (al[6].ToString() != "")
{
_failemail = _failemail + "," + al[6].ToString();
}
// Check for the Source file exists
ret_val = CheckForDestFileExists(_sipadresss, _suserid, _spassword, _sdir, sfile_name, _logfile, _toftpfile,
_sub, _localfile, al[1].ToString(), al[2].ToString(),al[3].ToString(),
al[5].ToString(), _failemail, _passkey, _logfilesize,_faildir);
if (ret_val == "N")
{
// Move the file to success directory
copyDirectory(_logfile, _localfile, _faildir, _toftpfile, _logfilesize);
al = null;
}
else
{
// Move the file to success directory
//File.Copy(_src + _sfilename, _dest + dfile_name, false);
copyDirectory(_logfile, _localfile, _succdir, _toftpfile, _logfilesize);
}
}
catch (Exception ex)
{
al = null;
}
return al;
}
public ArrayList GetSourceFileInfo(string[] sconfig_info)
{
al = new ArrayList();
sfile_name = string.Empty;
ddir_name = string.Empty;
dfile_name = string.Empty;
user_name = string.Empty;
password = string.Empty;
ip_address = string.Empty;
notify = string.Empty;
replacef = string.Empty;
checksize = string.Empty;
try
{
for (int i = 0; i < sconfig_info.Length; i++)
{
switch (sconfig_info[i].ToString().Trim())
{
case "sfile":
sfile_name = sconfig_info[i + 1].ToString().Trim();
break;
case "ddir":
ddir_name = sconfig_info[i + 1].ToString().Trim().Remove(0, 1);
break;
case "dfile":
dfile_name = sconfig_info[i + 1].ToString().Trim();
break;
case "user":
user_name = sconfig_info[i + 1].ToString().Trim();
break;
case "pass":
password = sconfig_info[i + 1].ToString().Trim();
break;
case "ip":
ip_address = sconfig_info[i + 1].ToString().Trim();
break;
case "notify":
if (sconfig_info[i + 1].ToString().Trim().Contains("@"))
{
notify = sconfig_info[i + 1].ToString().Trim();
}
else
{
notify = "";
}
break;
case "replacef":
replacef = sconfig_info[i].ToString().Trim();
break;
case "checksize":
checksize = sconfig_info[i].ToString().Trim();
break;
default:
break;
}
}
al.Add(sfile_name);
al.Add(ddir_name);
al.Add(dfile_name);
al.Add(user_name);
al.Add(password);
al.Add(ip_address);
al.Add(notify);
al.Add(replacef);
al.Add(checksize);
}
catch (Exception ex)
{
al = null;
}
return al;
}
kumarpgp
Member
282 Points
118 Posts
Create a new Page in SharePoint and Javascript
May 17, 2011 02:28 PM|LINK
Hi All,
Can you pls help me, how to create a new web page in SharePoint and also i want to do javascript validation also in that page is it's possible pls guide me.
Thanks & Regards
Kumar
shabirhakim1
Star
13496 Points
2145 Posts
Re: Create a new Page in SharePoint and Javascript
May 17, 2011 04:08 PM|LINK
Hi
Just see if below link can help you
Add aspx page to SharePoint 2007 « Tech Treasure
Peter pi - M...
Star
12871 Points
1786 Posts
Re: Create a new Page in SharePoint and Javascript
May 23, 2011 09:58 AM|LINK
Hi,
About javascript validation in web page, you could refer to the following link.
http://www.c-sharpcorner.com/UploadFile/purankaushal/103222006013805AM/1.aspx?ArticleID=10c0cce3-e00f-4dad-9ddb-df0c669afd6c
Best regards,
Peter
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
kumarpgp
Member
282 Points
118 Posts
Re: Create a new Page in SharePoint and Javascript
Nov 06, 2012 10:40 PM|LINK
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Security;
using System.Diagnostics;
using System.Collections;
using System.Threading;
using System.Reflection;
using System.Windows.Forms;
namespace e_FTP
{
#region Documentation
// Author : Santosh
// Date Started :
// Date Completed :
// Rev 001
// Requester : Natalie, KH Lim
// Description : Program to move files from source to target using FTP. The Target information and
// other details are found in the Souce configuration file 'toftp.XXXX'.
// Local Application
// : 1) Get the Source server detail from system config file.
// : 2) Use the Source server details to login and get the first toftp.XXXX from the Source directory.
// : 3) Open the toftp.xxxx and get the information to FTP from Source to Target.
// Source FTP
// : 3) Use the list of files in the toftp.XXXX and check the files exists else log email, exit and
// continue with next toftp.XXXX.
// : 4) If files exists, use the toftp.xxxx details to download the file in the Source directory to
// the local directory and get the size of the local file.
// : 5) Check the local file size is equal or greater than the source file size.
// : 6) If fail download or size wrong, keep the information and continue with next file in the toftp.XXXX.
// : 7) If any of the file missing move all local files to fail dir log, email with the error information
// for all missing files and exit to next toftp.XXXX.
// : 8) When all the files are downloaded successfully to local.
// : 9) Sent success email to email as per list in System.config.
// FTP to Target
// : 7) Delete all the files with same file name in target directory and replace. For 'repacef'
// if file exists log, email and exit.
// : 8) Upload the file from Local to Target server and check the target and local size to be same.
// : 9) If fail upload or size wrong, Delete target files, log, email and move all local files with
// Times Stamp to fail dir. Exit and continue with next toftp.XXXX.
// : 10) Upon successfull ftp to target, the Source toftp.XXXX will be rename to done.toftp.XXXX,
// The local toftp.XXXX and Local files will be Times Stamped and moved to the Success directory.
// : 11) Sent success email to email as per list in System.config.
// : 12) Repeat till all toFTP files in the Source is serviced.
// Local Application
// : 13) For above Source and target operations, if have email ID in notify in toftp.XXXX, sent
// emails to email ID for success and fail.
// : 14) Hosekeeping
// a) Keep the Success and Fail dir files for set period.
// b) Keep the log file consistent.
#endregion
#region Test Plan
// Testing Plan: For Source FTP
// 1. Test the Source FTP with wrong IP Address
// - Log into the Log file and send error email. Exit the application.
// 2. Test the Source FTP with wrong UserID and Password
// - Log into the Log file and send error email. Exit the application.
// 3. Test the Source FTP with the wrong source directory
// - Log into the Log file and send error email. Exit the application.
// 4. Test the Source FTP with no file exists in the source directory
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 5. Test the downloading file from Source to Local directory if Local
// file size and Source file size is not the same.
// - Log into the Log file and send error email.Put the file to the fail directory.
// - Go for next toftp.xxxx.
// 6. Test the downloading file from Source to Local directory under normal condition.
// - Log to log file.
// Testing Plan: For Target FTP
// 1. Test the Target FTP with wrong IP Address
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 2. Test the Target FTP with wrong UserID and Password
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 3. Test the Target FTP with the wrong source directory
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 4. Test the Target FTP with no file exists in the source directory
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 5. Test the Target FTP with write permission removed.
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 6. Test the uploading file from Local to Target directory if Local
// file size and Target file size is not the same.
// - Log into the Log file and send error email.Go for next toftp.xxxx
// 7. Test the Target FTP with normal condition.
// - Log to log file
#endregion
class Program
{
static void Main(string[] args)
{
string RunningProcess = Process.GetCurrentProcess().ProcessName;
Process[] processes = Process.GetProcessesByName(RunningProcess);
if (processes.Length > 1)
{
//Console.WriteLine("One instance is already running");
Environment.Exit(1);
}
////Process current = Process.GetCurrentProcess();
////foreach (Process process in Process.GetProcessesByName(current.ProcessName))
////{
//// if (process.Id == current.Id)
//// {
//// Console.WriteLine("One Instance is already running");
//// }
////}
//define the local variables
string ip_address = string.Empty; // IP Address of the Source file
string user_id = string.Empty; // User ID of the Source file
string password = string.Empty; // Password of the Source file
string source_dir = string.Empty; // Directory of the Source file
string local_dir = string.Empty; // Local Directory to put the Source file
string success_dir = string.Empty; // Success Directory to put the file uploaded successfully
string fail_dir = string.Empty; // Fail Directory to put the fail file
string sub = string.Empty; // The reporting server database name
string content = string.Empty; // The content prepared to send the email
string success_email = string.Empty; // Success email to send after successfully upload
string fails_email = string.Empty; // Fail email to send on any fail during upload or download
string return_val = string.Empty; // The value returned from different methods
string notify = string.Empty; // The additional email from toftp.xxxx file
string log_file = string.Empty; // The location of the Log File
int backup_days; // To keep the backup of the file for some days
long logfile_size; // The size of the log file to maintain constant
string pass_key = string.Empty; // The security key to access the web service method for email
string msgLog = string.Empty; // The log file message
string server = string.Empty; // The server from where the application is running
string apps_name = string.Empty; // The name of the application
string subject = string.Empty; // To keep the subject while sending the email
string config_file = string.Empty; // The location of the configuration file
string sfile_name = string.Empty; // The name of the Source file
string ddir = string.Empty; // The directory of the Target FTP server
string dfilename = string.Empty; // Name of the file to upload to Target FTP server
string duserid = string.Empty; // User ID to Login the Target FTP server
string dpassword = string.Empty; // Password to Login the Target FTP server
string dipaddress = string.Empty; // IP Address to Login to Tareger FTP server
string replacef = string.Empty; // replacef is to verify whether the file has to be override or not
string succ_email = string.Empty; // The success email with notify email
string fail_email = string.Empty; // The fail email with notify email
char d = 'd';
char u = 'u';
string myIP = string.Empty;
// Get the Source server detail from system config file.
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
config_file = System.IO.Path.GetFullPath("Config.txt");
using (StreamReader reader = new StreamReader(config_file))
{
ip_address = reader.ReadLine().Trim();
user_id = reader.ReadLine().Trim();
password = reader.ReadLine().Trim();
source_dir = reader.ReadLine().Trim();
local_dir = reader.ReadLine().Trim();
success_dir = reader.ReadLine().Trim();
fail_dir = reader.ReadLine().Trim();
backup_days = int.Parse(reader.ReadLine().Trim());
logfile_size = long.Parse(reader.ReadLine().Trim());
sub = reader.ReadLine().Trim();
success_email = reader.ReadLine().Trim();
fails_email = reader.ReadLine().Trim();
log_file = reader.ReadLine().Trim();
pass_key = reader.ReadLine().Trim();
server = reader.ReadLine().Trim();
apps_name = reader.ReadLine().Trim();
reader.Close();
}
// Create an object of the Class which contains all Common Functions
Modules mod = new Modules();
Program pr = new Program();
// Create an instance of the WebService to send the email
e_FTP.iistest.Service email_service = new e_FTP.iistest.Service();
// Get the IP Address of the Machine
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
myIP = addr[addr.Length - 1].ToString();
// Use the Source server details to login and get the first Source file from first toftp.XXXX
// from the Source configuration file.
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
string[] toftp_file = mod.LoginAndGettoftpFile(ip_address, user_id, password,
source_dir, log_file, success_email, fails_email, sub, pass_key, logfile_size);
if (toftp_file == null)
{
// Log to Log file and send the fail email and exit from the application
mod.LogToLogFile(log_file, "No 'toftp.xxxx' file exists in the source FTP!",logfile_size);
subject = "CRITICAL FTP JOB FAILED - " + "No toftp_file file exists!" + " " + sub;
content = mod.ContentFromFile(source_dir, "", "", "", "", "",log_file);
content += "Source IPAddress = " + ip_address + "<br />";
content += "User ID = " + user_id + "<br />";
email_service.SendMail("ReportingServer@s.carsems.com.my", fails_email, subject, content, "", pass_key);
Environment.Exit(1);
}
long get_size = 0;
ArrayList al = null;
for (int i = 0; i < toftp_file.Length; i++)
{
if (toftp_file[i].ToString().Trim().StartsWith("toftp"))
{
msgLog = string.Empty;
// Get the source file name,notify and check for exists of source file
al = mod.CheckForSourceFileExists(ip_address, user_id, password, source_dir, toftp_file[i].ToString().Trim(), local_dir,
log_file, sub, fails_email, pass_key, logfile_size, fail_dir, success_dir);
if (al == null)
{
msgLog = " ";
}
else
{
sfile_name = al[0].ToString().Trim();
ddir = al[1].ToString().Trim();
dfilename = al[2].ToString().Trim();
duserid = al[3].ToString().Trim();
dpassword = al[4].ToString().Trim();
dipaddress = al[5].ToString().Trim();
notify = al[6].ToString().Trim();
replacef = al[7].ToString().Trim();
// Check the fileName file exists in the Success directory
return_val = mod.ChecktoftpfileInSuccessDir(success_dir,sfile_name, toftp_file[i].Trim(), ip_address, user_id, password,
source_dir, log_file, logfile_size);
if (return_val != "Y")
{
if (notify != "")
{
succ_email = success_email + "," + notify.Trim();
fail_email = fails_email + "," + notify.Trim();
}
else
{
succ_email = success_email;
fail_email = fails_email;
}
// Download the file from Source directory to Local directory and get the size of the local file
get_size = mod.FTPDownloadAndGetLength(ip_address, user_id, password, source_dir, sfile_name, local_dir, sub,
toftp_file[i].ToString().Trim(), log_file, fail_email, pass_key, logfile_size, fail_dir);
if (get_size != 0)
{
//Check the Size of the source and local file
return_val = mod.CheckFileSize(local_dir, sfile_name, get_size, toftp_file[i].ToString().Trim(),
sub, source_dir, log_file, fail_email, pass_key, "", "", "", "", fail_dir, d, logfile_size);
if (return_val == "N")
{
msgLog = " ";
}
}
else
{
msgLog = " ";
}
if (msgLog == "" && get_size != 0)
{
// Log to log file on successful Upload
mod.LogToLogFile(log_file, toftp_file[i].ToString().Trim() + " Downloaded Successfully!" + " ,Source IP= " +
ip_address + " ,Local IP = " + myIP, logfile_size);
// Upload the file from Local to Target server and check the target and local size to be same.
get_size = 0;
// Check for the replacef
if (replacef != "")
{
// Delete the existing file in the Target FTP server
return_val = mod.DeleteExistingFilesInTargetFTP(dipaddress, duserid, dpassword, ddir, dfilename,
toftp_file[i], sub, fail_email, pass_key, source_dir, log_file, local_dir, fail_dir, sfile_name, sub, logfile_size);
if (return_val == "N")
{
get_size = mod.FTPUploadAndGetLength(dipaddress, duserid, dpassword, ddir, dfilename,
local_dir, sfile_name, sub, toftp_file[i], log_file, fail_email, pass_key, source_dir,
fail_dir, logfile_size);
}
if (get_size != 0)
{
//Check the Size of the source file and destination file
return_val = mod.CheckFileSize(local_dir, sfile_name, get_size, toftp_file[i], sub, source_dir,
log_file, fail_email, pass_key, ddir, duserid, dipaddress, dfilename, fail_dir,
u, logfile_size);
if (return_val == "N")
{
msgLog = " ";
}
}
}
else
{
// Check for the file exists, if file exists prompt the error
return_val = mod.CheckForTargetFileExists(dipaddress, duserid, dpassword, ddir,
toftp_file[i].Trim(), local_dir, dfilename,
log_file, fail_email, fail_dir, sub, pass_key, logfile_size);
if (return_val == "N")
{
// Upload the file to the Customer FTP server
get_size = mod.FTPUploadAndGetLength(dipaddress, duserid, dpassword, ddir, dfilename,
local_dir, sfile_name, sub, toftp_file[i], log_file, fail_email, pass_key, source_dir, fail_dir, logfile_size);
if (get_size != 0)
{
//Check the Size of the source file and destination file
return_val = mod.CheckFileSize(local_dir, sfile_name, get_size, toftp_file[i], sub, source_dir, log_file,
fail_email, pass_key, ddir, duserid, dipaddress, dfilename, fail_dir, u, logfile_size);
if (return_val == "N")
{
msgLog = " ";
}
}
}
else
{
msgLog = " ";
}
}
if (msgLog != " " && get_size != 0)
{
// Send email on successful Upload
subject = "FTP done- " + toftp_file[i] + " " + sub;
content = mod.ContentFromFile(source_dir, toftp_file[i], ddir, dfilename, duserid, dipaddress, log_file);
content += "<br />" + "File " + sfile_name + " Uploaded Successfully!";
email_service.SendMail("ReportingServer@s.carsems.com.my", succ_email, subject, content, "", pass_key);
// Log to log file on successful Upload
mod.LogToLogFile(log_file, toftp_file[i] + " Uploaded Successfully! " + "Local IP = " + myIP +
" Coutomer IP = " + dipaddress, logfile_size);
mod.RenameSourceConfigFile(ip_address, user_id, password, source_dir, toftp_file[i], log_file, logfile_size);
// Time Stamp and Move the files FTP to success backup directory.
mod.copyDirectory(log_file, local_dir, success_dir, dfilename, logfile_size);
}
}
}
}
succ_email = string.Empty;
fail_email = string.Empty;
}
}
// Delete the older files after X days for Success and Fail backup dir
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
mod.DeleteSuccessFilesAfterXDays(log_file, success_dir, backup_days,logfile_size);
mod.DeleteSuccessFilesAfterXDays(log_file, fail_dir, backup_days,logfile_size);
}
}
}
//-------------------------------------------------------Ramkumar------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
namespace e_FTP
{
#region Documentation
//Author : Santosh
//Date Started :
//Date Completed :
//Requester : Natalie, KH Lim
//Description : Reusable modules to be called by main program.
// : 1. Login to the Source FTP server,Check for toftp.xxxx file and take the directory into an
// array.
// : 2. Get the toftp.xxxx file, check for the Source file exists and get the Target FTP details.
// : 3. Get the source file and check for the file exists in the Source FTP.
// : 4. Download 1 file from Source to Local and get the length of the file in the Source.
// : 5. Check the local file size is equal or greater than the source file size and return with
// "Y" or "N".
// : 6. Delete the existing file from Target before Uploading the new file.
// : 7. Upload the file to FTP server and get the length of the file.
// : 8. Pass the Log file location and the error message to log to the log file.
// : 9. Times Stamp and move all files from local to success back up.
// : 10. Rename the Source file name to done.toftp.xxxx after successfully uploaded.
// : 11. Cut X no.of lines if log file size exceeds from a certain size.
// : 12. Delete the file after X days.
// : 13. Make the content of the email to send for success or failure.
#endregion
class Modules
{
public string root_filename = string.Empty;
public string sfile_name = string.Empty;
public string ddir_name = string.Empty;
public string dfile_name = string.Empty;
public string user_name = string.Empty;
public string password = string.Empty;
public string ip_address = string.Empty;
public string notify = string.Empty;
public string replacef = string.Empty;
public string checksize = string.Empty;
public long file_size;
string result = string.Empty;
bool ifexists = false;
string str_add = string.Empty;
ArrayList al = null;
FtpWebRequest reqFTP = null;
FtpWebResponse response = null;
// Create an instance of the WebService to send the email
e_FTP.iistest.Service email_service = new e_FTP.iistest.Service();
// 1. Login to the Source FTP server,Check for toftp.xxxx file and take the directory into an array.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string[] LoginAndGettoftpFile(string _sourceipadresss, string _sourceuserid, string _sourcepassword,
string _sourcepath, string _logfile, string _succemail, string _failemail,
string _sub, string _passkey, long _logfilesize)
{
string[] toftp_files = null;
string toftpfiles = string.Empty;
try
{
reqFTP = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + _sourceipadresss + "/" + _sourcepath));
reqFTP.Credentials = new NetworkCredential(_sourceuserid, _sourcepassword);
reqFTP.UseBinary = true;
reqFTP.KeepAlive = true;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
response = (FtpWebResponse)reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string all_files = reader.ReadToEnd();
all_files = all_files.Replace('\r', ' ');
all_files = all_files.Replace('\n', ',');
toftp_files = all_files.Split(',');
for (int i = 0; i < toftp_files.Length; i++)
{
if (toftp_files[i].ToString().StartsWith("toftp"))
{
toftpfiles += toftp_files[i] + ",";
}
if (toftp_files[i].Contains('/') && toftp_files[i].Contains("toftp") && !toftp_files[i].Contains("done"))
{
int indexof_toftp = toftp_files[i].IndexOf("toftp");
toftpfiles += toftp_files[i].Remove(0, indexof_toftp) + ",";
}
}
if (toftpfiles != "")
{
toftpfiles = toftpfiles.TrimEnd().Remove(toftpfiles.Length - 1);
toftp_files = toftpfiles.Split(',');
}
else
{
toftp_files = null;
}
response.Close();
reqFTP.Abort();
}
catch (Exception ex)
{
// Log to Log file and send the fail email and exit from the application
LogToLogFile(_logfile, ex.Message, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _sourceipadresss + " " + _sub;
string content = ContentFromFile(_sourcepath, "", "","", _sourceuserid, _sourceipadresss,_logfile);
content += ex.Message;
string email_reply = email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
Environment.Exit(1);
}
return toftp_files;
}
// Check the toftp.xxxx file exists in the Success Directory
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string ChecktoftpfileInSuccessDir(string _filepath,string _sfilename,string _toftpfile,string _ipaddress,string _userid,
string _password, string _sourcedir, string _logfile, long _logfilesize)
{
//string toftp_exists = string.Empty;
string file_name = string.Empty;
try
{
DirectoryInfo dirInfo = new DirectoryInfo(_filepath);
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo fi in files)
{
if (fi.Name.Contains(_sfilename.Trim()))
{
file_name = "Y";
// Rename the toftp.xxxx to done.toftp.xxxx
RenameSourceConfigFile(_ipaddress, _userid, _password, _sourcedir, _toftpfile, _logfile, _logfilesize);
// Log to the log file
LogToLogFile(_logfile, "File " + _toftpfile + " already FTPed to customer", _logfilesize);
}
}
if (file_name != "Y")
{
file_name = "N";
}
}
catch (Exception ex)
{
// Log to the log file
LogToLogFile(_logfile, ex.Message, _logfilesize);
}
return file_name;
}
// 2. Get the toftp.xxxx file, check for the Source file exists and get the Target FTP details.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public ArrayList CheckForSourceFileExists(string _sipadresss, string _suserid,string _spassword,
string _sdir, string _toftpfile, string _localfile,
string _logfile,string _sub, string _failemail, string _passkey,
long _logfilesize,string _faildir,string _succdir)
{
al = new ArrayList();
string ret_val = string.Empty;
try
{
reqFTP = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + _sipadresss + "/" + _sdir + "/" + _toftpfile));
reqFTP.Credentials = new NetworkCredential(_suserid, _spassword);
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
FileStream outputStream = new FileStream(_localfile + _toftpfile, FileMode.Create);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
reqFTP.Abort();
response.Close();
// Use toftp.xxxx to get the Source file Name
outputStream = new FileStream(_localfile + "/" + _toftpfile, FileMode.Open);
StreamReader _reader = new StreamReader(outputStream);
string FTPFileInfo = _reader.ReadToEnd();
string[] arr_FileInfo = FTPFileInfo.Split('-', '=');
// Get the Source file name from the Source config file
al = GetSourceFileInfo(arr_FileInfo);
string sfile_name = al[0].ToString();
_reader.Close();
if (al[6].ToString() != "")
{
_failemail = _failemail + "," + al[6].ToString();
}
// Check for the Source file exists
ret_val = CheckForDestFileExists(_sipadresss, _suserid, _spassword, _sdir, sfile_name, _logfile, _toftpfile,
_sub, _localfile, al[1].ToString(), al[2].ToString(),al[3].ToString(),
al[5].ToString(), _failemail, _passkey, _logfilesize,_faildir);
if (ret_val == "N")
{
// Move the file to success directory
copyDirectory(_logfile, _localfile, _faildir, _toftpfile, _logfilesize);
al = null;
}
else
{
// Move the file to success directory
//File.Copy(_src + _sfilename, _dest + dfile_name, false);
copyDirectory(_logfile, _localfile, _succdir, _toftpfile, _logfilesize);
}
}
catch (Exception ex)
{
al = null;
}
return al;
}
public ArrayList GetSourceFileInfo(string[] sconfig_info)
{
al = new ArrayList();
sfile_name = string.Empty;
ddir_name = string.Empty;
dfile_name = string.Empty;
user_name = string.Empty;
password = string.Empty;
ip_address = string.Empty;
notify = string.Empty;
replacef = string.Empty;
checksize = string.Empty;
try
{
for (int i = 0; i < sconfig_info.Length; i++)
{
switch (sconfig_info[i].ToString().Trim())
{
case "sfile":
sfile_name = sconfig_info[i + 1].ToString().Trim();
break;
case "ddir":
ddir_name = sconfig_info[i + 1].ToString().Trim().Remove(0, 1);
break;
case "dfile":
dfile_name = sconfig_info[i + 1].ToString().Trim();
break;
case "user":
user_name = sconfig_info[i + 1].ToString().Trim();
break;
case "pass":
password = sconfig_info[i + 1].ToString().Trim();
break;
case "ip":
ip_address = sconfig_info[i + 1].ToString().Trim();
break;
case "notify":
if (sconfig_info[i + 1].ToString().Trim().Contains("@"))
{
notify = sconfig_info[i + 1].ToString().Trim();
}
else
{
notify = "";
}
break;
case "replacef":
replacef = sconfig_info[i].ToString().Trim();
break;
case "checksize":
checksize = sconfig_info[i].ToString().Trim();
break;
default:
break;
}
}
al.Add(sfile_name);
al.Add(ddir_name);
al.Add(dfile_name);
al.Add(user_name);
al.Add(password);
al.Add(ip_address);
al.Add(notify);
al.Add(replacef);
al.Add(checksize);
}
catch (Exception ex)
{
al = null;
}
return al;
}
// 3. Get the source file and check for the file exists in the Source FTP.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string CheckForDestFileExists(string _sipadresss, string _suserid, string _spassword, string _sdir,
string _sfilename, string _logfile, string _cofigfilename, string _sub,
string _localdir,string _ddir, string _dfilename, string _dusername,
string _dipaddress, string _failemail, string _passkey, long _logfilesize,
string _faildir)
{
string retval = string.Empty;
try
{
reqFTP = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + _sipadresss + "/" + _sdir + "/" +
_sfilename));
reqFTP.Credentials = new NetworkCredential(_suserid, _spassword);
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;
response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();
reqFTP.Abort();
retval = "Y";
}
catch (Exception ex)
{
// Log to Log file and send the fail email
LogToLogFile(_logfile, ex.Message + "IP Address = " + _sipadresss + " File Name = " +_sfilename, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _cofigfilename + " " + _sub;
string content = ContentFromFile(_sdir,_cofigfilename,_ddir,_dfilename,_dusername,_dipaddress,_logfile);
content += ex.Message;
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
copyDirectory(_logfile, _localdir, _faildir, _sfilename, _logfilesize);
retval = "N";
}
return retval;
}
// 4. Download 1 file from Source to Local and get the length of the file in the Source.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public long FTPDownloadAndGetLength(string _sipaddress, string _suserid, string _spassword,string _sdir,
string _sfilename, string _localdir, string _sub, string _cofigfilename,
string _logfile, string _failemail, string _passkey, long _logfilesize,
string _faildir)
{
long get_slength = 0;
FileStream outputStream = null;
try
{
outputStream = new FileStream(_localdir + "/" + _sfilename, FileMode.Create);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + _sipaddress + "/" + _sdir + "/"+ _sfilename));
reqFTP.Credentials = new NetworkCredential(_suserid, _spassword);
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = false;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
//Get the length of the file
get_slength = GetFileSize(_sipaddress, _suserid, _spassword, _sdir, _sfilename, _localdir,
_sfilename, _sub, _cofigfilename, _logfile, _failemail, _passkey,
_sdir, _faildir, _logfilesize);
}
catch (Exception ex)
{
outputStream.Close();
// Log to Log file and send the fail email and exit from the application
LogToLogFile(_logfile,"Download Error: " + ex.Message + " IP Address = " + _sipaddress, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _cofigfilename + " " + _sub;
string content = ContentFromFile(_sdir,_cofigfilename,_localdir,_sfilename,_suserid,_sipaddress,_logfile);
content += ex.Message;
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
copyDirectory(_logfile, _localdir, _faildir, _sfilename, _logfilesize);
get_slength = 0;
}
return get_slength;
}
// 5. Check the local file size is equal or greater than the source file size and return with "Y" or "N".
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string CheckFileSize(string _lfilepath, string _sfilename, long _dfilesize, string _cofigfilename,
string _sub, string _sdir, string _logfile, string _failemail, string _passkey,
string _ddir,string _duserid, string _dipaddress, string _dfilename,
string _faildir, char _d, long _logfilesize)
{
string retval = string.Empty;
string content = string.Empty;
string errmsg = string.Empty;
try
{
DirectoryInfo dirInfo = new DirectoryInfo(_lfilepath);
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo fi in files)
{
if (fi.Name == _sfilename)
{
if (_d == 'd')
{
if (fi.Length >= _dfilesize)
{
retval = "Y";
break;
}
else
{
errmsg = "File Size is not the same! Local filesize = " + fi.Length + " " + "and" + " " +
"Source filesize = " + _dfilesize;
}
}
else
{
if (fi.Length <= _dfilesize)
{
retval = "Y";
break;
}
else
{
content = ContentFromFile(_sdir,_cofigfilename,_ddir,_dfilename,_duserid,_dipaddress,_logfile);
errmsg = "File Size is not the same! Local filesize = " + fi.Length + "and" + " " +
"Target filesize = " + _dfilesize;
content = content + "<br />" + errmsg;
}
}
}
}
if (errmsg != "")
{
//Send fail email. Log to file.
LogToLogFile(_logfile, errmsg, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _cofigfilename + " " + _sub;
content = ContentFromFile(_sdir, _cofigfilename, _ddir, _dfilename, _duserid, _dipaddress,_logfile);
content += errmsg;
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
// Time Stamp and Move the files FTP to success backup directory.
copyDirectory(_logfile, _lfilepath, _faildir, _sfilename, _logfilesize);
retval = "N";
}
}
catch (Exception ex)
{
content = string.Empty;
// Log to Log file and send the fail email and exit from the application
LogToLogFile(_logfile, ex.Message, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _cofigfilename + " " + _sub;
if (_dipaddress == "")
{
content = ContentFromFile(_sdir, _cofigfilename, "", "", "", "", _logfile);
content += ex.Message;
}
else
{
content = ContentFromFile(_sdir, _cofigfilename, _ddir, _dfilename, _duserid, _dipaddress, _logfile);
content += ex.Message;
}
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
// Time Stamp and Move the files FTP to success backup directory.
copyDirectory(_logfile, _lfilepath, _faildir, _sfilename, _logfilesize);
retval = "N";
}
return retval;
}
// 6. Delete the existing file from Target before Uploading the new file.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string DeleteExistingFilesInTargetFTP(string _dipaddress, string _duserid, string _dpassword,
string _ddir, string _dfilename, string _configfilename,
string _servername, string _failemail,string _passkey,
string _sdir, string _logfile, string _localdir,
string _faildir,string _sfilename, string _sub, long _logfilesize)
{
string ret_val = string.Empty;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + _dipaddress + "/" + _ddir + "/" +
_dfilename));
reqFTP.Credentials = new NetworkCredential(_duserid, _dpassword);
reqFTP.UsePassive = true;
reqFTP.UseBinary = true;
reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
response = (FtpWebResponse)reqFTP.GetResponse();
ret_val = "N";
response.Close();
reqFTP.Abort();
}
catch (Exception ex)
{
if (ex.Message == "The remote server returned an error: (550) File unavailable (e.g., file not found, no access).")
{
ret_val = "N";
}
else
{
//Send fail email. Log to file.
LogToLogFile(_logfile, ex.Message + " IP Address = " + _dipaddress, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _configfilename + " " + _sub;
string content = ContentFromFile(_sdir, _configfilename, _ddir, _dfilename, _duserid, _dipaddress,_logfile);
content += ex.Message;
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
// Time Stamp and Move the files FTP to success backup directory.
copyDirectory(_logfile, _localdir, _faildir, _sfilename, _logfilesize);
ret_val = "Y";
}
}
return ret_val;
}
// 7. Upload the file to FTP server and get the length of the file.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public long FTPUploadAndGetLength(string _dipaddress, string _duserid, string _dpassword,string _ddir,
string _dfilename, string _localpath, string _localfilename, string _sub,
string _cofigfilename, string _logfile, string _failemail, string _passkey,
string _sdir,string _faildir, long _logfilesize)
{
long get_tlength = 0;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + _dipaddress + "/" + _ddir + "/" +
_dfilename));
reqFTP.Credentials = new NetworkCredential(_duserid, _dpassword);
reqFTP.UsePassive = true;
reqFTP.UseBinary = false;
//reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
response = (FtpWebResponse)reqFTP.GetResponse();
FileStream stream = File.OpenRead(_localpath + _localfilename);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
Stream reqStream = reqFTP.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
response.Close();
reqFTP.Abort();
//Get the length of the file
get_tlength = GetFileSize(_dipaddress,_duserid,_dpassword,_ddir,_dfilename,_localpath,
_localfilename, _sub,_cofigfilename,_logfile,_failemail,_passkey,
_sdir,_faildir,_logfilesize);
}
catch (Exception ex)
{
// Log to Log file and send the fail email and exit from the application
LogToLogFile(_logfile, ex.Message + " IP Address = " + _dipaddress, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _cofigfilename + " " + _sub;
string content = ContentFromFile(_sdir,_cofigfilename,_ddir,_dfilename,_duserid,_dipaddress,_logfile);
content += ex.Message;
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
// Time Stamp and Move the files FTP to success backup directory.
copyDirectory(_logfile, _localpath, _faildir, _localfilename, _logfilesize);
get_tlength = 0;
}
return get_tlength;
}
//Get the size of the Uploaded file to the customer side
public long GetFileSize(string _dipaddress, string _duserid, string _dpassword,string _ddir,string _dfilename,
string _localpath, string _localfilename, string _sub,string _cofigfilename,
string _logfile, string _failemail, string _passkey, string _sdir, string _faildir,
long _logfilesize)
{
long get_tlength = 0;
try
{
reqFTP = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + _dipaddress + "/" + _ddir + "/" + _dfilename));
reqFTP.Credentials = new NetworkCredential(_duserid, _dpassword);
reqFTP.UsePassive = true;
reqFTP.UseBinary = false;
reqFTP.KeepAlive = false;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;
response = (FtpWebResponse)reqFTP.GetResponse();
get_tlength = response.ContentLength;
response.Close();
reqFTP.Abort();
}
catch (Exception ex)
{
// Log to Log file and send the fail email and exit from the application
LogToLogFile(_logfile, ex.Message, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _cofigfilename + " " + _sub;
string content = ContentFromFile(_sdir, _cofigfilename, _ddir, _dfilename, _duserid, _dipaddress,_logfile);
content += ex.Message;
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
// Time Stamp and Move the files FTP to success backup directory.
copyDirectory(_logfile, _localpath, _faildir, _localfilename, _logfilesize);
get_tlength = 0;
}
return get_tlength;
}
// Check if file exists in the customer FTP server
public string CheckForTargetFileExists(string _dipadresss, string _duserid, string _dpassword,string _ddir,
string _localfilename,string _localdir,string _dfilename,
string _logfile, string _failemail,string _faildir, string _sub,
string _passkey, long _logfilesize)
{
//string[] toftp_files = null;
string file_exists = string.Empty;
try
{
reqFTP = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + _dipadresss + "/" + _ddir));
reqFTP.Credentials = new NetworkCredential(_duserid, _dpassword);
reqFTP.UseBinary = true;
reqFTP.KeepAlive = false;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
response = (FtpWebResponse)reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string toftpfiles = reader.ReadToEnd();
if (toftpfiles.Contains(_dfilename))
{
file_exists = "Y";
LogToLogFile(_logfile, _dfilename + " already exists in the target " + _dipadresss, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _localfilename + " " + _sub;
string content = ContentFromFile(_localdir,_localfilename,_ddir,_dfilename,_duserid,_dipadresss,_logfile);
content += _dfilename + " already exists in the target ";
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
// Move the Local file to the Fail directory
copyDirectory(_logfile, _localdir, _faildir, _dfilename, _logfilesize);
}
else
{
file_exists = "N";
}
response.Close();
reqFTP.Abort();
}
catch (Exception ex)
{
if (ex.Message == "The remote server returned an error: (550) File unavailable (e.g., file not found, no access).")
{
file_exists = "N";
}
else
{
// Log to Log file and send the fail email and exit from the application
LogToLogFile(_logfile, ex.Message, _logfilesize);
string subject = "CRITICAL FTP JOB FAILED - " + _localfilename + " " + _sub;
string content = ContentFromFile(_localdir, _localfilename, _ddir, _dfilename, _duserid, _dipadresss, _logfile);
content += ex.Message;
email_service.SendMail("ReportingServer@s.carsems.com.my", _failemail, subject, content, "", _passkey);
file_exists = "Y";
}
}
return file_exists;
}
// 8. Pass the Log file location and the error message to log to the log file.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string LogToLogFile(string _logfile, string _errmsg, long _logfilesize)
{
string retval = string.Empty;
try
{
int count = 0;
string new_line = string.Empty;
string pre_line = string.Empty;
string storelines = string.Empty;
if (System.IO.File.Exists(_logfile))
{
StreamReader sr = new StreamReader(_logfile);
while ((pre_line = sr.ReadLine()) != null)
{
if (count == _logfilesize - 1)
{
sr.Close();
// Cut one line from the log file
storelines = string.Empty;
sr = new StreamReader(_logfile);
for (int i = 0; i < _logfilesize-1; i++)
{
storelines += sr.ReadLine() + "\r\n";
}
sr.Close();
StreamWriter strw = new StreamWriter(_logfile);
strw.WriteLine(storelines);
strw.Close();
sr.Close();
break;
}
else
{
storelines += pre_line + "\r\n";
count = count + 1;
}
}
sr.Close();
storelines = DateTime.Now.ToString() + " " + _errmsg + "\r\n" + storelines;
StreamWriter _stwr = new StreamWriter(_logfile);
_stwr.Write(storelines);
_stwr.Close();
retval = "Y";
}
else
{
StreamWriter _stwr = new StreamWriter(_logfile);
_stwr.Write(DateTime.Now.ToString() + " " + _errmsg + "\r\n");
_stwr.Close();
retval = "Y";
}
}
catch (Exception ex)
{
retval = ex.Message;
}
return retval;
}
// 9. Times Stamp and move all files from local to success back up.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public void copyDirectory(string _logfile, string _src, string _dest, string _sfilename,long _logfilesize)
{
try
{
String[] Files;
string dfilename = string.Empty;
if (_dest[_dest.Length - 1] != Path.DirectorySeparatorChar)
_dest += Path.DirectorySeparatorChar;
if (!Directory.Exists(_dest)) Directory.CreateDirectory(_dest);
Files = Directory.GetFileSystemEntries(_src);
if (_sfilename != "")
{
dfile_name = _sfilename + "_" + DateTime.Today.ToString("yyyy-MM-dd") + "_" +
DateTime.Now.ToString("hh.mm tt");
File.Copy(_src + _sfilename, _dest + dfile_name, false);
//delete the files from the source directory
DirectoryInfo dirInfo = new DirectoryInfo(_src);
FileInfo[] fi_info = dirInfo.GetFiles();
foreach (FileInfo fi in fi_info)
{
fi.Delete();
}
}
}
catch (Exception ex)
{
LogToLogFile(_logfile, ex.Message, _logfilesize);
}
}
// 10. Rename the Source file name to done.toftp.xxxx after successfully uploaded
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public void RenameSourceConfigFile(string _sipaddress, string _suserid, string _spassword, string _sdir,
string _sfilename, string _logfile, long _logfilesize)
{
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + _sipaddress + "/" + _sdir + "/" + _sfilename));
reqFTP.Credentials = new NetworkCredential(_suserid, _spassword);
reqFTP.UsePassive = true;
//reqFTP.UseBinary = true;
reqFTP.Method = WebRequestMethods.Ftp.Rename;
reqFTP.RenameTo = "done." + _sfilename;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();
reqFTP.Abort();
}
catch (Exception ex)
{
// Log to log file
LogToLogFile(_logfile, "Cannot rename the Source file " + _sfilename + " " + ex.Message, _logfilesize);
}
}
// 11. Cut X no.of lines if log file size exceeds from a certain size.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public void CutLinesFromLogFile(string _logfile, long _logfilesize, int _linestocut)
{
try
{
FileInfo fl = new FileInfo(_logfile);
bool filesize = false;
string line = "";
ArrayList storelines = new ArrayList();
if (fl.Length > _logfilesize)
{
filesize = true;
}
StreamReader sr = new StreamReader(_logfile);
if (filesize == true)
{
for (int i = 0; i < _logfilesize - _linestocut; i++)
{
line += sr.ReadLine() + "\r\n";
}
sr.Close();
StreamWriter strw = new StreamWriter(_logfile);
strw.WriteLine(line);
strw.Close();
sr.Close();
}
sr.Close();
}
catch (Exception ex)
{
LogToLogFile(_logfile, ex.Message, _logfilesize);
}
}
// 12. Delete the file after X days
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public void DeleteSuccessFilesAfterXDays(string _logfile, string _filepath, double _backupdays, long _logfilesize)
{
try
{
DirectoryInfo dirInfo = new DirectoryInfo(_filepath);
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo fi in files)
{
if (fi.CreationTime < DateTime.Now.AddDays(-_backupdays))
{
fi.Delete();
}
}
}
catch (Exception ex)
{
LogToLogFile(_logfile, ex.Message, _logfilesize);
}
}
// 13. Make the content of the email to send for success or failure
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public string ContentFromFile(string _sourcedir, string _sfilename, string _ddir, string _dfilename,
string _username,string _ipaddress, string _logfileloc)
{
string full_msg = string.Empty;
string content_fromfile = "source dir =" + _sourcedir + "<br />";
string content_fromtarget = string.Empty;
content_fromfile += "source file =" + _sfilename + "<br />";
content_fromfile += "dest dir =" + _ddir + "<br />";
content_fromfile += "dest file =" + _dfilename + "<br />";
content_fromfile += "user =" + _username + "<br />";
content_fromfile += "password = ******" + "<br />";
content_fromfile += "ip =" + _ipaddress + "<br />";
content_fromfile += "logfile =" + _logfileloc + "<br />";
return content_fromfile;
}
}
}