Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8009823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:33:31+00:00 2026-06-04T18:33:31+00:00

In my program, I need to force the user to select the save folder.

  • 0

In my program, I need to force the user to select the save folder. I’m doing this by setting the SelectedPath to be MyComputer.

My problem is the OK button is not initially disabled.

Behaviour:

  • “My Computer” is selected (light shade of grey) but the OK button is enabled.
  • Clicking on “My Computer” (selection now shaded dark blue) still has the OK button selected.
  • If I select say Desktop and then re-select “My Computer”, the OK button only then gets disabled.

I’ve tried playing around with both the SelectedPath and RootFolder, along with Environment.SpecialFolder.MyComputer and Environment.GetPath() to no avail.

How can I disable the OK button when the SelectedPath is not a valid folder?

EDIT:
This is running on Windows XP, .Net 4.0, developed in Visual Studio 2010 Professional.

EDIT #2: Full example code added.

using System;
using System.Windows.Forms;

using System;
using System.Windows.Forms;

namespace FolderBrowser
{
    public class Form1 : Form
    {
        private System.ComponentModel.IContainer components;
        private System.Windows.Forms.Button button1;

        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();

            this.button1.Location = new System.Drawing.Point(10, 10);
            this.button1.Text = "Open FolderBrowserDialog";
            this.button1.Click += new System.EventHandler(this.SelectSaveFolderItem_Click);

            this.Controls.Add(this.button1);
            this.ResumeLayout(false);
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void SelectSaveFolderItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
            fbd.ShowDialog();
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:33:33+00:00Added an answer on June 4, 2026 at 6:33 pm

    Ref: MSDN: Disable a button in a folder browser dialog

    In the above msdn thread a user wished to disable the accept button in folder browser dialog when a directory didn’t exist. I feel this relates to your question:
    How can I disable the OK button when the SelectedPath is not a valid folder?

    The solution in that thread is to use a Timer event to disable the OK Button after the dialog is shown. I converted the VB.Net code to C# for you:

    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    public class Form1
    {
        [DllImport("user32.dll", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    
        private static extern Int32 FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll", EntryPoint = "FindWindowExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    
        private static extern Int32 FindWindowEx(Int32 hWnd1, Int32 hWnd2, string lpsz1, string lpsz2);
        [DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    
        private static extern Int32 EnableWindow(Int32 hwnd, Int32 fEnable);
    
    
        private void Button1_Click(System.Object sender, System.EventArgs e)
        {
            Timer1.Enabled = true;
    
            FolderBrowserDialog fld = new FolderBrowserDialog();
    
            fld.ShowDialog(this);
    
        }
    
    
        private void Timer1_Tick(System.Object sender, System.EventArgs e)
        {
            Int32 hwndMainWindow = default(Int32);
    
            hwndMainWindow = FindWindow("#32770".Trim(), Constants.vbNullString);
            // '#32770 (Dialog)#32770 (Dialog)
    
    
            if (hwndMainWindow) {
                Int32 hwndBtn = default(Int32);
    
                hwndBtn = FindWindowEx(hwndMainWindow, IntPtr.Zero, "Button", "OK");
    
    
                if (hwndBtn) {
                    EnableWindow(hwndBtn, 0);
    
                }
    
            }
    
            Timer1.Enabled = false;
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a program that uses brute-force method to find out how
I am writing a program to try to solve a math problem. I need
I need to force Xen virtual machine to run a program. Thus, I'm looking
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
I have a WPF user control for which I need to force rendering in
This program will have an infinite canvas (ie as long as the user scrolls,
In my program I need to programmatically configure an ApplicationContext. Specifically, I have a
In my program I need a way to click on an Image control, the
For my program I need to generate valid infix expressions with customizable complexity. The
For a part of a program i need the following 2 methods. The first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.