-3

I am attempting to compare a variable "windir" to the root folder from a browser dialog. At the moment the error I am getting is "Cannot implicitly convert type System.Environment.SpecialFolder to string". Anything I try makes it worse. Below is my code. The issue is with btn4. It is not a syntax issue. == does not work.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using System.IO;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Windows.Shell;

namespace Client_Backup
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : System.Windows.Window
    {
        private string windir;
        public MainWindow()
        {
            InitializeComponent();
            windir = System.IO.Path.GetPathRoot(Environment.SystemDirectory);
            //tb2.Text = windir;
        }

        private void btn2_Click(object sender, RoutedEventArgs e)
        {
            for (int i = LB1.SelectedItems.Count - 1; i >= 0; i--)
            {
                LB1.Items.Remove(LB1.SelectedItems[i]);
            }
        }

        private void btn1_Click(object sender, RoutedEventArgs e)
        {
            if (new FolderBrowserDialog().ShowDialog() == System.Windows.Forms.DialogResult.OK)
                LB1.Items.Add(new FolderBrowserDialog().SelectedPath);
        }

        private void btn3_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btn4_Click(object sender, RoutedEventArgs e)
        {
            //tb2.Text = windir;
            FolderBrowserDialog folderselect = new FolderBrowserDialog();
            if (folderselect.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (windir = folderselect.RootFolder)
                {
                    tb2.Text = "you have selected the system drive for a backup destination. please select a different drive.";
                }
                tb1.Text = (folderselect.SelectedPath);
            }
        }


        private void tb1_TextChanged(object sender, TextChangedEventArgs e)
        {
            tb1.Background = Brushes.FloralWhite;
        }

        private void btn5_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btn6_Click(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)

                this.WindowState = WindowState.Normal;
            else
                this.WindowState = WindowState.Maximized;
        }

        private void btn7_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void rectangle1_MouseDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }

        private void Cbx2Changed(object sender, RoutedEventArgs e)
        {
            if (cbx2.IsChecked == true)
            {
                LB1.IsEnabled = false;
                btn1.IsEnabled = false;
                btn2.IsEnabled = false;
            }
            else
            {
                LB1.IsEnabled = true;
                btn1.IsEnabled = true;
                btn2.IsEnabled = true;
            }
        }

        private void Cbx1Changed(object sender, RoutedEventArgs e)
        {

        }

    }
}

I tried to do a ToString but that didn't work. I'm just stuck.

  • maybe [this](https://stackoverflow.com/a/8451550/4935162)? or [this](https://stackoverflow.com/a/72040338/4935162)? – Yarin_007 Jul 04 '23 at 18:48
  • _windir = folderselect.RootFolder_ this is an assignment, not a comparison. In C# you use the == operator to compare two values. You should really have a big warning in your compiler output – Steve Jul 04 '23 at 19:33

1 Answers1

1

There is a typo in the line "if (windir = folderselect.RootFolder)". Should it be "if (windir == folderselect.RootFolder)" ?

JMS
  • 11
  • 3
  • Thanks but I tried that already. It says that the == isn't allowed. – Brian Waldron Jul 04 '23 at 20:10
  • 2
    @BrianWaldron You will likely be frustrated on this site if you think everyone is a * idiot. Not every answer will be a good one (particularly from someone with 11 rep). If you ask a question with a syntax error in it, expect folks' eyes to be drawn to that error and to call it out. To answer the explicit question you ask (I'm a * idiot, so I'm not going to bother with your source), if you want to convert an _Enumerated Type_ instance (like a `Environment.SpecialFolder`) to a string, use the standard `ToString()` override. Relax, and welcome to Stackoverflow. – Flydog57 Jul 04 '23 at 22:34
  • The funny thing is, it wasn't a syntax error... I'm not calling everyone an idiot just the person who was arrogant enough to think that was the issue when it was something completely different... – Brian Waldron Jul 06 '23 at 14:52