-2

I have this code that works fine on the local drive:

file.Attributes |= FileAttributes.Hidden;

I've also tried:

System.IO.SetAttributes(file.FullName, FileAttributes.Hidden);

Any suggestions to get set the hidden attribute on the file, for files on a networked drive?

Note: I can set directories to hidden on a networked drive.

Note2: I tried right clicking the file in the directory and setting Hidden, it doesn't stay marked.

PS: I'm using Windows 8 if that makes any difference.

Chuck Savage
  • 11,775
  • 6
  • 49
  • 69
  • [MSDN File.SetAttributes Method](https://msdn.microsoft.com/en-us/library/system.io.file.setattributes%28v=vs.110%29.aspx) here's a good place to start.. – MethodMan May 08 '15 at 18:35
  • 2
    If you can't change the attribute by right-clicking in Explorer and doing so in properties, you don't have the rights to modify the file, and you clearly can't do it in code either. Talk to your network administrator about changing your access rights to the network drive. – Ken White May 08 '15 at 18:36
  • @KenWhite So it is possible to set files to hidden on networked drives, with the correct permissions? – Chuck Savage May 08 '15 at 18:40
  • @KenWhite I am the admin... Any idea how I give myself those permissions? – Chuck Savage May 08 '15 at 18:41
  • Yes, it is. I just tested from the Windows command prompt using `attrib +h MyFile.txt` on a network folder, and the file was successfully marked as hidden. (`attrib -h MyFile.txt` removed it again.) My test was on Win7 64-bit on a Windows Server 2012 network folder, though; I don't have a Win8 system. – Ken White May 08 '15 at 18:44

1 Answers1

0

Figured it out, not sure if it is specific to my type of network drive (Drobo), but if I have the file start with a period . it works.

This isn't an answer, but a workaround...

Chuck Savage
  • 11,775
  • 6
  • 49
  • 69