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

  • Home
  • SEARCH
  • 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 8241577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:52:34+00:00 2026-06-07T20:52:34+00:00

I made a program in C# and was using a hardcoded reference to the

  • 0

I made a program in C# and was using a hardcoded reference to the Program Files directory whilst making the program. I’d now like to remove the hardcoded reference.

I have been recommended this method from Eric on stackoverflow in a recent topic. However, I wasn’t able to understand how to run the code from a button_click:

Eric said:

string programFilesFolder = 
    Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)

Continuing that example you could do something like this

string pathToFile = 
    Path.Combine(programFilesFolder, @"TEST\ok.txt");

if (File.Exists(pathToFile)) 
    File.Delete(pathToFile);

To be 100% honest with you all, I am newish to c# and am still learning…

Can someone please give an example on how to invoke the code above from a button_click? I am going to be doing this to more than one file using the same button.

I did ask this question in a comment on the other thread, but I think they all moved on.

  • 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-07T20:52:38+00:00Added an answer on June 7, 2026 at 8:52 pm

    Assuming that you want to make a Windows Forms application to do this:

    http://msdn.microsoft.com/en-us/library/z9w2f38k(v=vs.90).aspx

    That will show an example of how to do a Windows Forms example where you can drag a button onto a canvas and then have a click action on the button.

    In the example it says to put

    MessageBox.Show ("Hello, World!")
    

    but you could put the code to delete the file there instead and it will delete whatever you want to delete on the click of the button.

    string programFilesFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
    string pathToFile = Path.Combine(programFilesFolder, @"TEST\ok.txt");
    File.Delete(pathToFile);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have made a program in C using the gcc compiler. Right now it
I'm making an communication program using Lync. I have made it call another lync
i have made a small opengl program using the d programming language. what i
I have made a registration program. Making use of mysql database. Can I still
I'm using a makefile to compile a program made of many .c files, and
I made this small Java program using eclipse IDE. I have set the workspace
I've been using my Activity class to access my DB which made my program
I made a program for RDF by using jena in java... I have to
I have made a chat program with using Winsock2.h and the lib file ws2_32.lib.
I have a program made up of several .h and .c files and a

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.