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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:58:47+00:00 2026-05-28T04:58:47+00:00

I have had some problems earlier which caused my program to crash in all

  • 0

I have had some problems earlier which caused my program to crash in all Windows OS because I did not create a new file/directory for my file. Then I have assured that I have created file/folder before initializing ect. Now my program works in Windows XP but it doesn’t work in Windows 7. By saying that it works I mean that it creates a file/folder needed for my program. By not working I mean that the file/folder isn’t created in windows 7.

Could this code be the cause of the crash under Windows 7? If so, how could I fix it?

    private static string dir = Environment.GetFolderPath
        (Environment.SpecialFolder.ProgramFiles) + @"\folder\";
    private static string file = dir + @"\Settings.txt";
    private string text;

    public void CheckFileStatus()
    {
        if (!Directory.Exists(dir))
        {
            DirectoryInfo directory = Directory.CreateDirectory(dir);
        }
        if (!File.Exists(file))
        {
            using (FileStream fileStream = File.Create(file))
            {
            }
        }
    }
  • 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-28T04:58:47+00:00Added an answer on May 28, 2026 at 4:58 am

    The program files directory in Windows 7 can only be written to with elevated privileges. Are you running your code as an administrator? It’s also bad practice to write to the program files folder. You should be using the %appdata% folder.

    Take a look here to see the various special folders. You will likely want to use either System.Environment.SpecialFolder.ApplicationData or System.Environment.SpecialFolder.CommonApplicationData. This will allow you to write data without needing elevated privileges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have had a hard disk failure which resulted in some files of a
I'm sure that all of us have had to deal with telecommuters at some
I had some good insight to an earlier post regarding this, but I have
I'm quite new to Linq and have had some problems updating my dabase. I
Are there any gotchas in JDK 6 which did not exist in earlier versions?
I have recently had some problems that I think might be helped by debugging
I began taking up Heroku again, but have had some problems trying to get
I have a little problem. I had some JComboBox to a JDialog but they
In my limited experience, I've been on several projects that have had some sort
Here is a question that I have had for some time but never actually

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.