Results 1 to 7 of 7

Thread: [RESOLVED] [1.0/1.1] Creating a hidden folder.

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Resolved [RESOLVED] [1.0/1.1] Creating a hidden folder.

    Hi. Does anyone know what is the setting to hide a folder when it is created? I know how to create a normal folder and then go back and change the properties to hidden. But is there any way this could be done when the program created it?

    Jennifer.

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [1.0/1.1] Creating a hidden folder.

    Working with files in C#

    The above link shows you all you need to know

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [1.0/1.1] Creating a hidden folder.

    There is no way with managed code. You can either create a directory o, in .NET 2.0, create a directory with specific security. There is no way to apply attributes as you create the directory. Given that the application of attributes would happen milliseconds after the creation the way you're doing it now, I don't really see the issue.

    That said, there may be a way to do what you want with unmanaged code. I'd suggest getting the API Guide and looking at the available functions grouped by functionality, then look at the I/O related group(s) to see if there's a function that looks like it might be useful.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Creating a hidden folder.

    I got it to work with this:

    if(!Directory.Exists(@"c:\folder\"))
    {
    DirectoryInfo DInfor = Directory.CreateDirectory(@"c:\folder\");

    DInfor.Attributes = FileAttributes.Directory | FileAttributes.Hidden;

    }

    Thanks for the help.

    Jennifer

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [1.0/1.1] Creating a hidden folder.

    But that's doing exactly what you said you could already do: create the folder and then set the hidden attribute.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [RESOLVED] [1.0/1.1] Creating a hidden folder.

    Sorry for the misunderstanding. What I meant was I know how to create a folder from a program and then manually right click on the folder and check the hidden attribute. I wanted to know how to hide the folder without doing it manually i.e. from within the program.

    Jennifer.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [1.0/1.1] Creating a hidden folder.

    Hopefully that demonstrates why it's important to state clearly what you mean rather than assuming that we know. If you say this:
    I know how to create a normal folder and then go back and change the properties to hidden.
    in a programming forum then people will assume you mean programmatically. Had you made it plain that the actual problem was that you just didn't know how to make a folder hidden then I could have provided the solution straight away and saved you a few days. The creation of the directory was a red herring, because setting attributes is done on existing directories, whether you just created them or not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width