Recently, the customer asked to export a tree directory into a folder structure and provide download function. At the beginning, it felt that the function was easier to implement and the basic functions were completed in the shortest time. After publishing it to the server, it was found that the directory directly exported (with ntko documents and attachments) in this application and then compressed, and the program was stuck! Later I thought about doing a window service, but the time given by the customer was too short, so I couldn’t write a console program to generate an exe file, and then call this exe file, so that the pressure on this program can be alleviated!
Write a test project below
Pass the path of a folder to be compressed on the call exe side, and then get the path under the console for compression. After the compression is completed, return to the compressed folder path or return a successful or not state
1. Return path
string path = @"E:\test project\201303\TestWindowsService\ca\bin\Debug\";
string fileName = path;
Process p = new Process();
= false;
= true;
= fileName;
= true;
= @"D:\zhai\aaa\placement help";//The parameters are separated by spaces. If a parameter is empty, you can pass in ""
();
();
//This example can return a file path after the compression is successful
string output = ();
this. = output;
Code under console:
static void Main(string[] args)
{
//Receive the path of the file to be compressed
string url = "";
//Return to the compressed file path
string retUrl = "";
if (!(args[0]))
{
url = args[0];
}
//The dll of a compressed file is referenced here;
using (ZipFile zf = new ZipFile())
{
(url);
(@"D:\zhai\aaa\"+("yyyyMMddHHmmss")+".zip");
retUrl = @"D:\zhai\aaa\"+("yyyyMMddHHmmss")+".zip";
}
(retUrl);
}
2. Return to a status
//Process myProcess = new Process();
//string fileName = path;
//string para = "Hello 30 degrees north latitude!";
//ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(fileName, para);
// = myProcessStartInfo;
//();
//while (!)
//{
// ();
//}
//int returnValue = ;
Under the console
static int Main(string[] args)
{
int i=0;
if (!(args[0]))
{
url = args[0];
}
if(url)
{
i=1;
}
return i;
}