Form1.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. namespace CollectionTest
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void button2_Click(object sender, EventArgs e)
  19. {
  20. OpenFileDialog openFileDialog = new OpenFileDialog();
  21. openFileDialog.InitialDirectory = "c://";
  22. openFileDialog.Filter = "所有文件|*.*";
  23. openFileDialog.RestoreDirectory = true;
  24. openFileDialog.FilterIndex = 1;
  25. if (openFileDialog.ShowDialog() == DialogResult.OK)
  26. {
  27. textBox1.Text = openFileDialog.FileName;
  28. }
  29. }
  30. private void button1_Click(object sender, EventArgs e)
  31. {
  32. StartProcess(Environment.CurrentDirectory + "\\Core.ONH.Collection.Send.exe", new[] { textBox1.Text });
  33. }
  34. public bool StartProcess(string filename, string[] args)
  35. {
  36. try
  37. {
  38. string s = "";
  39. foreach (string arg in args)
  40. {
  41. s = s + arg + " ";
  42. }
  43. s = s.Trim();
  44. Process myprocess = new Process();
  45. ProcessStartInfo startInfo = new ProcessStartInfo(filename, s);
  46. myprocess.StartInfo = startInfo;
  47. myprocess.StartInfo.UseShellExecute = false;
  48. myprocess.Start();
  49. return true;
  50. }
  51. catch (Exception ex)
  52. {
  53. MessageBox.Show("启动应用程序时出错!原因:" + ex.Message);
  54. }
  55. return false;
  56. }
  57. }
  58. }