Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:59:40+00:00 2026-05-23T03:59:40+00:00

In this question I have searched for a simple solution to unblock files. Thanks

  • 0

In this question I have searched for a simple solution to unblock files.
Thanks to all the comments and answer, I have found a simple solution by PInvoking DeleteFile.

It works, but because I’ve never used file-operations through PInvoke (Win32), I don’t know if there are some pitfalls or if there is another method of calling DeleteFile to delete the alternate stream of a file.

What I also don’t know is if I have to wrap the call in a try/catch or if it is enough just to look the at the boolean result. In my tests, no exceptions were raised, but I don’t know what will happen in the real world.

public class FileUnblocker {

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

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

Does this code look reliable?

Update
I had posted an incomplete method (the unblock method didn’t concatenate the “Zone.Identifier” literal to the file name). I have corrected this now, sorry.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:59:41+00:00Added an answer on May 23, 2026 at 3:59 am

    Calling the native method will never raise an exception. If the file deletion fails, for whatever reason, the call to DeleteFile returns false.

    Your P/Invoke code is good. You are correctly using Unicode characters, setting SetLastError to true and the parameter marshalling is correct. To check for errors look for the value of the boolean return from DeleteFile. If it is false (i.e. the call failed) then call Marshal.GetLastWin32Error to find out the Win32 error code.

    The most obvious causes for the function to fail are:

    1. The file does not exist.
    2. The alternate stream is not present.
    3. The process does not have sufficient rights to delete the alternate stream.

    For 1 and 2 an error code of ERROR_FILE_NOT_FOUND will be returned. For 3 you will be given an error code of ERROR_ACCESS_DENIED.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched around for answers to this question, but not found anything quite on
I feel stupid asking this question, but I can not find a clear answer
Note: I've included all my console output as pastebin links to keep this question
I'm relatively new to scripting and apologize in advance for this painfully simple problem.
i'm attempting to create a table with an incremental ID. This isn't the simple
I know the title of this question is stupid, but I couldn't come up
Just need to confirm one thing that i have searched enough on How can
I have two tables: gallery and pictures: gallery id int (auto increment, primary key)
I am pretty new to django, but have many years experience coding in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.