打开单个文件
效果
代码
cs
public async void OpenFunction()
{
// 获取默认数据库
var gdbPath = Project.Current.DefaultGeodatabasePath;
OpenItemDialog openItemDialog = new OpenItemDialog()
{
Title ="打开要素文件",
InitialLocation = gdbPath,
Filter = ItemFilters.FeatureClasses_All,
MultiSelect = false,
};
bool? ok = openItemDialog.ShowDialog();
if (!ok.HasValue || openItemDialog.Items.Count() == 0)
{
MessageBox.Show("打开文件失败");
return;
}
else
{
Item item = openItemDialog.Items.First();
ImputShpPath = item.Path;
}
}
ImputShpPath为最终选择文件的路径
打开多个文件
代码
cs
protected override void OnClick()
{
// 获取默认数据库
var gdbPath = Project.Current.DefaultGeodatabasePath;
OpenItemDialog openTheMultiFolder = new OpenItemDialog();
openTheMultiFolder.Title = "打开多个文件";
openTheMultiFolder.InitialLocation = gdbPath;
openTheMultiFolder.MultiSelect = true;
openTheMultiFolder.Filter = ItemFilters.FeatureClasses_All;
bool? ok = openTheMultiFolder.ShowDialog();
if (ok == true)
{
IEnumerable<Item> selectedItems = openTheMultiFolder.Items;
foreach (Item selectedItem in selectedItems)
MessageBox.Show(selectedItem.Path);
}
}
参考文献