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 7699339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:27:17+00:00 2026-05-31T22:27:17+00:00

Ok so I have an OpenFileDialog and I want to set the initial directory

  • 0

Ok so I have an OpenFileDialog and I want to set the initial directory to the users ‘Download’ folder. This is an internal application and, therefore, I am sure that the user will be using Windows 7.

var ofd = new OpenFileDialog();

//This doesn't work
ofd.InitialDirectory =
    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Downloads");

//This doesn't work either
ofd.InitialDirectory = @"%USERPROFILE%\Downloads";

ofd.Filter = "Zip Files|*.zip";

ofd.ShowDialog();

txtFooBar.Text = ofd.FileName;

I have tried the above so far and neither work. No Exception is thrown, it just doesn’t set the initial directory to the downloads folder.

Where am I going wrong?

Thanks

  • 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-05-31T22:27:18+00:00Added an answer on May 31, 2026 at 10:27 pm

    Maybe this could help: https://stackoverflow.com/a/1175250/333404

    UPDATE:

    Works for me:
    https://stackoverflow.com/a/3795159/333404

      private void Button_Click_1(object sender, RoutedEventArgs e) {
                var ofd = new OpenFileDialog();
                ofd.InitialDirectory = GetDownloadsPath();
                ofd.Filter = "Zip Files|*.zip";
                ofd.ShowDialog();
            }
    
            public static string GetDownloadsPath() {
                string path = null;
                if (Environment.OSVersion.Version.Major >= 6) {
                    IntPtr pathPtr;
                    int hr = SHGetKnownFolderPath(ref FolderDownloads, 0, IntPtr.Zero, out pathPtr);
                    if (hr == 0) {
                        path = Marshal.PtrToStringUni(pathPtr);
                        Marshal.FreeCoTaskMem(pathPtr);
                        return path;
                    }
                }
                path = Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                path = Path.Combine(path, "Downloads");
                return path;
            }
    
            private static Guid FolderDownloads = new Guid("374DE290-123F-4565-9164-39C4925E467B");
            [DllImport("shell32.dll", CharSet = CharSet.Auto)]
            private static extern int SHGetKnownFolderPath(ref Guid id, int flags, IntPtr token, out IntPtr path);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have an app, that you want to provide users ability to browse
I want to store images into sql using c# application. So I have this
I have an silverlight 4 application, and I want to upload recursively a local
I have a dynamically created Image control that is populated via a OpenFileDialog like:
I have a WinForm application, and I want to load a Bitmap(.bmp) in a
I'm working on an ASP.NET web application for our corporate intranet users. I have
I have this problem. I want to add image to listView. Exactly I want
I have added an open file dialog box to my client application so that
I have download the code for OpenFileDialog (File Upload function) from Silverlight tutorials website.
I am working on an application where I have an images folder relative to

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.