using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace seasharpwinapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
bool status = StartUploadProcess();
if (status)
{
MessageBox.Show("Upload successful");
}
else
{
MessageBox.Show("Upload failed");
}
}
private bool StartUploadProcess()
{
try
{
Process P = new Process();
P.EnableRaisingEvents = true;
P.Exited += P_Exited;
P.StartInfo.FileName = @"C:\\Temp\\Upload.cmd";
P.StartInfo.Arguments = "C:\\Temp\\UploadScript.txt" + " " + "File1";
P.Start();
return true;
}
catch (Exception x)
{
MessageBox.Show(string.Format("Error while uploading. {0} \r\n {1}", x.Message, x.InnerException.ToString()));
return false;
}
}
private void P_Exited(object sender, System.EventArgs e)
{
try
{
System.IO.File.Delete("C:\\Temp\\UploadFiles\\File1");
}
catch (Exception x)
{
MessageBox.Show(string.Format("There was a problem deleting the file located in {0}. {1}", "C:\\Temp\\UploadFile\\File1", x.Message));
}
try
{
System.IO.File.Delete("C:\\Temp\\UploadScript.txt");
}
catch (Exception x)
{
MessageBox.Show(string.Format("There was a problem deleting the file located in {0}. {1}", "C:\\Temp\\UploadScript.txt",x.Message));
}
}
}
}
|