简体   繁体   English

C#FilePath问题WinForms

[英]C# FilePath Problems WinForms

I am trying to output the file address of an item selected in a combobox. 我正在尝试输出在组合框中选择的项目的文件地址。 But i keep getting the Directory address of the project and not the item itself. 但是我一直在获取项目的目录地址,而不是项目本身。 Please help. 请帮忙。 Here is my Code: 这是我的代码:

private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
    {
        if (availableSoftDropBox.SelectedItem.Equals("Choose Your Own..."))
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
                txtFlashFile.Text = openFileDialog1.FileName;

        }
         else
        {



         string fileName;
         fileName = Path.GetFullPath((string)availableSoftDropBox.SelectedItem);
        string fullPath = @"C:\Program Files (x86)\yeet-n . master\yeet- 
                         master\src\yeet\System\Products\" + (fileName);


         txtFlashFile.Text = fullPath;

I'm not quite sure what you want to achieve, but using FileInfo instead of Path.GetFullPath might help. 我不太确定要实现什么,但是使用FileInfo代替Path.GetFullPath可能会有所帮助。

   private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
   {
      const string fullPath = @"C:\Program Files (x86)\yeet-n . master\yeet- 
                     master\src\yeet\System\Products\";
      string selection = (string)availableSoftDropBox.SelectedItem;
      var fileInfo = new FileInfo(fullPath + selection);
      string text = fileInfo.FullName;

      if (selection.Equals("Choose Your Own..."))
      {
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
            text = openFileDialog1.FileName;
         } 
      } 

      txtFlashFile.Text = text;           
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM