public void SamePathOrUnder() { Assert.IsTrue(ProjectPath.SamePathOrUnder(@"C:\folder1\folder2\folder3", @"c:\folder1\.\folder2\junk\..\folder3")); Assert.IsTrue(ProjectPath.SamePathOrUnder(@"C:\folder1\folder2\", @"c:\folder1\.\folder2\junk\..\folder3")); Assert.IsTrue(ProjectPath.SamePathOrUnder(@"C:\folder1\folder2", @"c:\folder1\.\folder2\junk\..\folder3")); Assert.IsFalse(ProjectPath.SamePathOrUnder(@"C:\folder1\folder2", @"c:\folder1\.\folder22\junk\..\folder3")); Assert.IsFalse(ProjectPath.SamePathOrUnder(@"C:\folder1\folder2ile.tmp", @"D:\folder1\.\folder2\folder3\file.tmp")); Assert.IsFalse(ProjectPath.SamePathOrUnder(@"C:\", @"D:\")); Assert.IsTrue(ProjectPath.SamePathOrUnder(@"C:\", @"c:\")); Assert.IsTrue(ProjectPath.SamePathOrUnder(@"C:\", @"c:\bin\debug")); }
private void applicationBaseTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (applicationBaseTextBox.Text != String.Empty) { string applicationBase = null; try { applicationBase = Path.Combine(project.BasePath, applicationBaseTextBox.Text); DirectoryInfo info = new DirectoryInfo(applicationBase); } catch (Exception exception) { applicationBaseTextBox.SelectAll(); UserMessage.DisplayFailure(exception, "Invalid Entry"); e.Cancel = true; } if (!ProjectPath.SamePathOrUnder(project.BasePath, applicationBase)) { applicationBaseTextBox.SelectAll(); UserMessage.DisplayFailure("Path must be equal to or under the project base", "Invalid Entry"); e.Cancel = true; } else if (!Directory.Exists(applicationBase)) { if (UserMessage.Ask("The directory {0} does not exist. Do you want to create it?", "Project Editor") == DialogResult.Yes) { Directory.CreateDirectory(applicationBase); } else { e.Cancel = true; } } } }