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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:45:36+00:00 2026-06-13T03:45:36+00:00

Here is a method from my program public partial class Form1 : Form {

  • 0

Here is a method from my program

public partial class Form1 : Form
{
    DirectoryInfo tempdirectory = new DirectoryInfo(@"\temp");
    const string DEFAULT_ADDRESS_TEXT = "<click load button to load a file>";

    private void Form1_Load(object sender, EventArgs e)
    {
        lblAddress.Text = DEFAULT_ADDRESS_TEXT;            
        if (Directory.Exists(tempdirectory.Name))
        {
            lblAddress.Text = tempdirectory.FullName;
            foreach (DirectoryInfo dir in tempdirectory.GetDirectories())
            {
                dir.Delete(true);
            }
            foreach (FileInfo file in tempdirectory.GetFiles())
            {
                file.Delete();
            }
        }
        Directory.CreateDirectory(tempdirectory.Name);
        lblAddress.Text = tempdirectory.Name;
    }
}

Program Run Location(PRL)–> G:\Users\\Documents\Visual Studio 2010\Projects\Comics Project\ZipEntryDemo2\ZipEntryDemo2\bin\Debug

In first run of the program a folder named temp gets created at the program location (PRL\temp).
After closing the application and running again the temp directory created at first step is not empty; rather the lblAddress shows the value G:\temp ; which actually doesn’t even exists.

Then I explicitly created a folder G:\temp and put some extra file and folder in it, for test purposes, the program now removes all files and folders from G:\temp and PRL\temp is still as it is with all contents.

Actually my program passes the location of the temp folder, i.e. PRL\temp to a method which extracts it’s contents in that folder. In every run contents always extracts in PRL\temp;
but G:\temp ‘s content is lost provided the folder exists.

One peculiar thing also is that when I was debugging at the first run since the temp directory doesn’t exist’s at PRL if condition statement doesn’t executes and program creates a folder at the correct location, i.e. PRL\temp.
It’s just that files and folders are checked for the wrong folder G:\temp

I am not getting any exception like folder already exists or of any kind till now.

I also noticed that if I change “\temp” to “temp”, now all things happens in the correct location, i.e. PRL\temp; and there is no G:\temp in middle. My program works fine. But I find it weird and would appreciate if someone could explain that. Thanks, and sorry if it’s a very silly question, this is some of my first experiences with IO.

The method which calls unzip methos is

    private void btnLoad_Click(object sender, EventArgs e)
    {
        OpenFileDialog f = new OpenFileDialog();
        f.Filter = "Zip Files(*.zip)|*.zip";
        f.Multiselect = false;
        if (f.ShowDialog() == DialogResult.OK)
        {
            unzip(f.FileName, tempdirectory.Name, 4096); 
        }
    }

Here tempDirectory.Name is passed to unzip function, it doesn’t get manipulated in that method. 4096 is buffer size, irrelevant.

  • 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-13T03:45:37+00:00Added an answer on June 13, 2026 at 3:45 am

    These are the kind of things that go wrong when you don’t specify a full path name. You got the first “temp” directory when you started out with specifying just plain temp, the second one when you changed it to \temp. Which is still not a full path name since it doesn’t specify the drive.

    This code is also very unlikely to survive on a machine other than your dev machine, you cannot arbitrary create directories in the root of the drive. UAC prevents creating directories and files like that. You’d need an installer to create such directories, only it has sufficient rights.

    Instead, a Windows program should use an appdata folder, you get the path to the appdata directory with Environment.GetFolderPath(). If these folders and files are truly temporary in nature, in other words you only need them for the life of the process or can do without them when you startup again, then you should use System.IO.Path.GetTempPath() to get the full path name of the user’s temporary directory.

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

Sidebar

Related Questions

here's the method: public static int chooseStrat () { String[] strats = new String[1]
I am trying to get some form data from POST method. Here's the code
Here's a piece of code from the xss_clean method of the Input_Core class of
Here's the method: public static String CPUcolor () { System.out.println (What color am I?)
I am having trouble getting my class to from program.cs to run in form.cs
I have a curious issue here In my ejbCreate() method from where i insert
     I have created a basic inheritance program using a polymorphic array. From the parent-class,
I have 3 classes: Form1, LoginForm and program. Program holds my main method that
Is it possible to invoke method A.F() from instance of B class except of
I am trying to call a C# method from java script ,I am new

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.