2012-07-24 25 views
1

在顯示Windows.Forms.OpenFileDialog我怎麼能存儲數據路徑到名爲m_settings變量下面的C#類?C#:存儲從一個OpenFileDialog的數據路徑到一個變量?

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 = //<-- ? 
} 

回答

2

這應該做的伎倆:

m_settings = ofd.FileName; 

編輯:其實,現在我不知道,如果你想要的文件夾路徑。在這種情況下:

m_settings = Path.GetDirectoryName(ofd.FileName); 
相關問題