Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. File Hiding

File Hiding

Scheduled Pinned Locked Moved C#
csharpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Prashant Gadhave
    wrote on last edited by
    #1

    Hi , I want to hide a file after creating it in C# by using File class and also to hide it .After creating it using File class's create method when I use File class's set attribute and set the attribute of file to hidden and readonly ,only readonly is getting set but the file is not getting hidden.What to do?

    J 1 Reply Last reply
    0
    • P Prashant Gadhave

      Hi , I want to hide a file after creating it in C# by using File class and also to hide it .After creating it using File class's create method when I use File class's set attribute and set the attribute of file to hidden and readonly ,only readonly is getting set but the file is not getting hidden.What to do?

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Prashant Gadhave wrote:

      What to do?

      Start by showing the code you are using to change the attributes as that is likely to be where you have made the mistake. Im guessing you've tried to set each attribute separately, not realising that it is a bitmask value - thus overwriting the hidden attribute with readonly. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

      T 1 Reply Last reply
      0
      • J J4amieC

        Prashant Gadhave wrote:

        What to do?

        Start by showing the code you are using to change the attributes as that is likely to be where you have made the mistake. Im guessing you've tried to set each attribute separately, not realising that it is a bitmask value - thus overwriting the hidden attribute with readonly. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

        T Offline
        T Offline
        Travis D Mathison
        wrote on last edited by
        #3

        What J4amieC said is probably exactly what's happening... If you want to set it all in one shot you can use:

        File.SetAttributes(@"C:\test.txt", FileAttributes.Hidden | FileAttributes.ReadOnly);

        If you want to add another attribute onto a file you need to add to the "existing" attributes, for example:

        FileAttributes attr = File.GetAttributes(@"C:\test.txt");
        File.SetAttributes(@"C:\test.txt", attr |= FileAttributes.Hidden);

        Hope that helps..

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups