1

在以下显示的 c# 类中Windows.Forms.OpenFileDialog,我如何将数据路径存储到名为的变量中m_settings

private SomeKindOfData m_settings;
public void ShowSettingsGui()
{
    System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
    ofd.Multiselect = true;
    ofd.Filter = "Data Sources (*.ini)|*.ini*|All Files|*.*";
    if (ofd.ShowDialog() == DialogResult.OK)
    {
        string[] filePath = ofd.FileNames;
        string[] safeFilePath = ofd.SafeFileNames;
    }
        m_settings = //<-- ?
}
4

1 回答 1

2

这应该可以解决问题:

m_settings = ofd.FileName;

编辑:实际上,现在我不确定您是否想要文件夹路径。在这种情况下:

m_settings = Path.GetDirectoryName(ofd.FileName);
于 2012-07-24T00:08:31.760 回答