/[AnywhereTS-MSSQL]/trunk/TSAdminTool/frmAddTFTP.cs
ViewVC logotype

Contents of /trunk/TSAdminTool/frmAddTFTP.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 180 - (show annotations) (download)
Mon Jul 16 12:58:43 2012 UTC (7 years, 7 months ago) by william
File size: 3054 byte(s)
folderbrowserdialog must be on a thread with ApartmentState.STA set

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.IO;
9 using System.Threading;
10
11 namespace AnywhereTS
12 {
13 public partial class frmAddTFTP : Form
14 {
15 public string inputstring; // The text in the input box
16 public frmAddTFTP()
17 {
18 InitializeComponent();
19 }
20
21 private void btnOk_Click(object sender, EventArgs e)
22 {
23 inputstring = textInput.Text.Trim();
24
25 // Check that user entered something
26 if (inputstring.Length == 0)
27 {
28 this.Cursor = Cursors.Default;
29 MessageBox.Show("You must specifiy a directory.");
30 textInput.Focus();
31 return;
32 }
33
34 // Check if path is relative
35 if (inputstring.StartsWith(".") || (inputstring.StartsWith(@"\") && !inputstring.StartsWith(@"\\")))
36 {
37 this.Cursor = Cursors.Default;
38 MessageBox.Show("Invalid path.");
39 using (log4net.NDC.Push(string.Format("path={0}", inputstring)))
40 {
41 Logging.ATSAdminLog.Warn("Invalid path.");
42 }
43 textInput.Focus();
44 return;
45 }
46
47 // Validate directory
48 if (!Directory.Exists(inputstring))
49 {
50 MessageBox.Show("Cannot find or access directory '" + inputstring + "' Please check spelling and rights!");
51
52 using (log4net.NDC.Push(string.Format("path={0}", inputstring)))
53 {
54 Logging.ATSAdminLog.Warn("Cannot find or access directory.");
55 }
56 textInput.SelectAll();
57 textInput.Focus();
58 return;
59 }
60
61 DialogResult = DialogResult.OK;
62 }
63
64
65 string tftp_path = string.Empty;
66 private void btnBrowse_Click(object sender, EventArgs e)
67 {
68 var t = new Thread(new ThreadStart(CreateFolderBrowser));
69 t.IsBackground = true;
70 t.SetApartmentState(ApartmentState.STA);
71 t.Start();
72 while (t.IsAlive) { Application.DoEvents(); }
73 textInput.Text = tftp_path;
74 textInput.Select();
75 }
76 private void CreateFolderBrowser()
77 {
78 folderBrowserDialog = new FolderBrowserDialog();
79 folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
80 DialogResult result = folderBrowserDialog.ShowDialog();
81 if (result != DialogResult.OK) return;
82 tftp_path = folderBrowserDialog.SelectedPath.Trim();
83 }
84
85 private void frmAddTFTP_Load(object sender, EventArgs e)
86 {
87 helpProvider.HelpNamespace = ATSGlobals.strHelpFilePath; // Initiate helpProvider
88 }
89 }
90 }

  ViewVC Help
Powered by ViewVC 1.1.22