首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#:将OpenFileDialog中的数据路径存储到变量中?

C#:将OpenFileDialog中的数据路径存储到变量中?
EN

Stack Overflow用户
提问于 2012-07-24 08:07:33
回答 1查看 1.2K关注 0票数 1

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

代码语言:javascript
复制
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 = //<-- ?
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-24 08:08:32

这应该能起到作用:

代码语言:javascript
复制
m_settings = ofd.FileName;

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

代码语言:javascript
复制
m_settings = Path.GetDirectoryName(ofd.FileName);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11622330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档