I am developing wpf application in C#. I am able to run the following exe files
public static void GenerateCsvFile(string fileName)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = @"C:\ndfd\degrib\bin\degrib.exe";
startInfo.Arguments = fileName + " -C -msg 1 -Csv";
process.StartInfo = startInfo;
process.Start();
System.Diagnostics.Process process1 = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo1 = new System.Diagnostics.ProcessStartInfo();
startInfo1.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo1.FileName = @"C:\ndfd\degrib\bin\degrib.exe";
startInfo1.Arguments = fileName + " -C -msg all -nMet -Csv";
process1.StartInfo = startInfo1;
process1.Start();
}
The above code generate the csv files for me successfully. But .csv files are generated at different location depending on the fileName. means .csv files are generated within different folder each time. Can I force the exe to generate the .csv file in specific folder ? Can you please provide me any code or link through which I can resolve the above issue ?
Edit: The user selects the zip file and sumbit the form. The App.ApplicationPath is hard coded path. The following is my code
private void ShowPointsButton_Click(object sender, RoutedEventArgs e)
{
ZipHelper.UnZip(FileNameTextBox.Text, App.ApplicationPath, safeFileName, 9999999);
}
public static void UnZip(string SrcFile, string DstFile, string safeFileName, int bufferSize)
{
//ICSharpCode.SharpZipLib.Zip.UseZip64.Off;
FileStream fileStreamIn = new FileStream(SrcFile, FileMode.Open, FileAccess.Read);
ZipInputStream zipInStream = new ZipInputStream(fileStreamIn); ;
//if (SrcFile.Contains(".bz2"))
//{
//BZip2InputStream zipInStream = new BZip2InputStream(fileStreamIn);
//}
//else
//{
// zipInStream = new ZipInputStream(fileStreamIn);
//}
string rootDirectory = string.Empty;
if (safeFileName.Contains(".zip"))
{
rootDirectory = safeFileName.Replace(".zip", string.Empty);
}
else
{
rootDirectory = safeFileName;
}
Directory.CreateDirectory(App.ApplicationPath + rootDirectory);
while (true)
{
ZipEntry entry = zipInStream.GetNextEntry();
if (entry == null)
break;
if (entry.Name.Contains("/"))
{
string[] folders = entry.Name.Split('/');
string lastElement = folders[folders.Length - 1];
var folderList = new List<string>(folders);
folderList.RemoveAt(folders.Length - 1);
folders = folderList.ToArray();
//string folderPath = "";
//foreach (string str in folders)
//{
//folderPath = folderPath + @"\" + str;
//string blackslash = folderPath.Substring(0, 1);
//if (blackslash == "\\")
//{
// folderPath = folderPath.Remove(0, 1);
//}
//if (!Directory.Exists(App.ApplicationPath + rootDirectory + "/" + folderPath))
//{
// Directory.CreateDirectory(App.ApplicationPath + rootDirectory + "/" + folderPath);
//}
//}
if (!string.IsNullOrEmpty(lastElement))
{
//folderPath = folderPath + @"\" + lastElement;
//string blackslash = folderPath.Substring(0, 1);
//if (blackslash == "\\")
//{
// folderPath = folderPath.Remove(0, 1);
//}
WriteToFile(DstFile + rootDirectory + @"\" + lastElement, bufferSize, zipInStream, rootDirectory, entry);
}
}
else
{
WriteToFile(DstFile + rootDirectory + @"\" + entry.Name, bufferSize, zipInStream, rootDirectory, entry);
}
}
zipInStream.Close();
fileStreamIn.Close();
}
private static void WriteToFile(string DstFile, int bufferSize, ZipInputStream zipInStream, string rootDirectory, ZipEntry entry)
{
WriteFileContents(DstFile, bufferSize, zipInStream);
if (DstFile.Contains(".grb"))
{
Utility.GenerateCsvFile(DstFile);
}
//if(DstFile.Contains(".csv"))
//{
// WriteFileContents(@"D:\Documents" + rootDirectory + @"\" + entry.Name, bufferSize, zipInStream);
//}
}
private static void WriteFileContents(string DstFile, int bufferSize, ZipInputStream zipInStream)
{
FileStream fileStreamOut = new FileStream(DstFile, FileMode.OpenOrCreate, FileAccess.Write);
int size;
byte[] buffer = new byte[bufferSize];
do
{
size = zipInStream.Read(buffer, 0, buffer.Length);
fileStreamOut.Write(buffer, 0, size);
} while (size > 0);
fileStreamOut.Close();
}
In the above code see at line Utility.GenerateCsvFile(DstFile); I want to generate the .csv files at location 'DstFile'. In short, the folder in which I am unzipping my files, in the same folder I want .exe to write .csv file. For example consider there is D:/XYZ folder in which I am unzipping my zip files. In this folder there is test.grib file. I want to run exe for test.grib and produce .csv files. I want these .csv files to be written to XYZ folder.