DirectoryInfo file Attribute problem? RRS feed

  • Question

  • Hi

    We have an application to access the NAS network folder and list the folder(s) and file(s) present in NAS folder in our application. We have problem in getting file attributes value from NAS folder files when we run our application in Windows 8.1 & Windows 10 OS.

    We are using below code to retrieve file attribute value but some times we are getting attribute as 'Normal' and some times attribute as 'Zero'(0).
    DirectoryInfo info = new DirectoryInfo(FilePath);
    i.e info.Attribute is Zero(0) some time and info.Attribute is Normal some time. Why?

    In info.Attribute is Zero case info.Exists is false even though files are present. We are able to see files in Windows Explorer.

    In Windows 7, info.Attribute is always Normal but above problem is when we run our application in Windows 8.1 and 10 only.
    We have no idea why info.Attribute is Zero and we have not seen this type of attribure value in MSDN references.

    Kindly help us to resolve this issue.


    Monday, December 31, 2018 9:46 AM

All replies

  • Did you observe abnormalities if you access the folder “\\xxxx\shared\test” manually in File Explorer and check the file properties?

    Monday, December 31, 2018 10:13 AM
  • Thank you for your reply.

    We have not observed any abnormalities in Windows Explorer and file properties.

    Monday, December 31, 2018 11:07 AM
  • "Normal" is a special value in Win32. As discussed in the documentation it only applies if no other attributes are set. If any other attribute is set then "Normal" doesn't make sense.

    It is also important to note that directories don't support most of the attributes listed for file attributes because they are directories, not files. Normal, for example, is a file attribute - not a directory attribute. I wouldn't expect it to be set on a directory.

    In your example you're using DirectoryInfo but in the screenshot it is referencing a file. That doesn't make sense. You cannot use DirectoryInfo to get information about a file and vice versa. Are you trying to mix the concerns? To get information about a file (such as Normal) you'd use FileInfo. If you want directory information you use DirectoryInfo.


    Michael Taylor

    Monday, December 31, 2018 2:59 PM
  • Hi,

    Thank you for your reply.

    We are using DirectoryInfo for getting file(s) & folder(s) attributes. DirectoryInfo has Attributes property with "Gets or sets the attributes for the current file or directory."
    We feel there is no problem in using DirectoryInfo for both file(s) and folder(s).

    Our question was in Windows 7 we are able to get proper file attribute value but in Windows 8.1 and 10 file attibute value is zero from NAS folder.



    Wednesday, January 2, 2019 4:52 AM
  • What does FileInfo say for the same file against the same NAS?

    Michael Taylor

    Wednesday, January 2, 2019 6:05 AM
  • Thank you for your reply.

    We have tried FileInfo but the result is same as DirectoryInfo.

    Moreover just a doubt, will this issue related to SMB protocol versions??

    Wednesday, January 2, 2019 8:22 AM
  • Does it work if you apply the next workaround: if Attributes are zero, then retry the operation several times, maybe with some short delay?

    Wednesday, January 2, 2019 8:28 AM
  • You may try this code:

    <style type="text/css">@page { margin: 2cm } pre.cjk { font-family: "DejaVu Sans Mono", monospace } p { margin-bottom: 0.25cm; line-height: 120% } a:link { so-language: zxx } </style>
    using System;
    using System.IO;
    class Program
        static void Main()
            // Get Attributes for file.
            FileInfo info = new FileInfo("C:\\file.txt");
            FileAttributes attributes = info.Attributes;
            // Get Attributes for directory.
            info = new FileInfo("C:\\");
            attributes = info.Attributes;
    Hidden, System, Directory


    .Net Framework

    Wednesday, January 2, 2019 9:19 AM
  • Thank you.

    Same result even after retry the operation several times.

    i.e info.Attribute is Zero(0) some time and info.Attribute is Normal some time.

    Wednesday, January 2, 2019 10:26 AM
  • Thank you.

    I hope we have deviated from our original query.

    DirectoryInfo works fine in Windows 7 but different behavior only in Windows 8.1 and Windows 10.

    In Windows 7, info.Attribute is always Normal.

    In Windows 8.1 and Windows 10, info.Attribute is Zero(0) some time and info.Attribute is Normal some time from NAS folder.

    Wednesday, January 2, 2019 10:29 AM
  • What about Windows Explorer? Does it show the correct attributes? If it does then the issue is with the NAS and Windows. Alternatively you can use P/Invoke to call GetFileAttributes directly. If this call returns back the unexpected results then it is a NAS/Windows issue.

    Michael Taylor

    Wednesday, January 2, 2019 2:38 PM
  • Hi,

    Thank you for your reply.

    >What about Windows Explorer? Does it show the correct attributes?

    Windows Explorer shows Atrributes as blank. Please refer attached screenshot.

    >Alternatively you can use P/Invoke to call GetFileAttributes directly.

    We have tried P/Invoke GetFileAttributes but result is same, dwFileAttributes is Zero(0). Please refer attached screenshot.



    Thursday, January 3, 2019 5:57 AM
  • If Windows is showing nothing then you're going to get the same thing from .NET which is just calling to Windows. Sounds like an issue with NAS/Windows, not a .NET issue.

    Michael Taylor

    Thursday, January 3, 2019 2:56 PM
  • We have understood your point. Kindly refer below, after following the registry changes done in PC all file attributes are proper from NAS.

    In Win 10/8.1, SMB 2 client’s file metadata caching mechanism, after a file access (file enumeration), SMB protocol does not access the same file again for a timeout of 10 seconds. During this time period, information like file metadata is provided from the file info cache maintained by SMB client.

    Please refer the below related MSDN link.

    If possible please help us to explain how it is working fine in Windows 7 without changing any registries mentioned in the above link.

    Friday, January 4, 2019 4:09 AM
  • This is a question for TechNet as it is in reference to an OS component, not C# or .NET. I recommend you post over there.

    Michael Taylor

    Friday, January 4, 2019 6:00 AM
  • The current issue in our application is caused by pre-caching behavior of DirectoryInfo.Attributes.

    Please check the below link.

    In our code, we have called Directory.GetFiles() and then called DirectoryInfo.Attributes. Then attribute values are not freshly retrieved from NAS. The attribute value which is pre-cached during the call to Directory.GetFiles() is returned on Windows 10.

    Latest data is not received even after calling DirectoryInfo.Refresh().

    But this pre-caching behavior is not seen on Windows 7. It is fetching attributes freshly from NAS file.

    Why there is a difference in the behavior of DirectoryInfo.Attributes API on Windows 7 and Windows 10?

    Is it a bug in Windows 10 or any difference exists in the SMB 2.0 client file metadata caching mechanism on these OS?

    • Edited by sharp1257 Friday, January 4, 2019 10:14 AM
    Friday, January 4, 2019 9:32 AM
  • Hi All,

    Any response to the above query is much appreciated.

    Thank you very much,

    Monday, January 7, 2019 7:21 AM
  • Hi sharp1257,

    If the reply is helpful, could you please mark it as answer, it will beneficial to other communites who have the similar issue, if the issue still exists, please feel free let me know.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, January 8, 2019 1:30 AM
  • The issue still exists.

    There is a difference in the behavior of Directory.GetFiles() and DirectoryInfo.Attributes on Windows 7 when compared to Windows 10.

    On Windows 10, DirectoryInfo.Attributes is returning the pre cached value. but, on Windows 7, it is fetched from the file.


    Tuesday, January 8, 2019 1:38 AM