You can create this FileAttributes type to go in your class and be used with the alternative signature if you wish (or you can use the System.IO.FileAttributes as displayed in the below example):
This method works for Alternate Data Streams, also great when used with the Unicode header \\?\ to change the attributes of files who have paths to long to be dealt with via the shell.
Tips & Tricks:
Please add some!
Sample Code:
Using the "alternative" method above you can make calls like so:
public static void SetFileAttributes(String path, FileAttributes dwFileAttributeFlags)
{
if (!SetFileAttributesW(UnicodeHeader + path, dwFileAttributeFlags))
{
throw (Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()));
}
}
In the above example I have specified the W (Unicode) version of the function as opposed to the A (ANSI) version of the function and so I don't think I needed to specify the CharSet to be Unicode however I have done so for illustration purpose to show how you would force the non W version of the function to work with unicode (long) file paths.
1/6/2010 5:46:18 AM - ian.harris2@iinet.net.au-124.168.219.202
The file attributes used by file-handling functions, such as those of shlwapi.dll.
8/12/2012 5:26:10 AM - -203.161.81.161
Click to read this page
4/6/2008 2:23:14 PM - hlidftvbgb-88.114.46.202
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).