Unblock File from within .net 4 c#

Based on your input I have done the following code:

public class FileUnblocker {
    [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool DeleteFile(string name);

    public bool Unblock(string fileName) {
        return DeleteFile(fileName + ":Zone.Identifier");
    }
}

Thanks to Stuart Dunkeld, Alex K(+1) and Sven to show me the direction.

UPDATE
I have posted the code here for a feedback if it would work reliable in production environment. If someone want to use it, check out there.

Leave a Comment