Unblock File from Within .Net 4 C#

Unblock File from within .net 4 c#

It's stored in the :Zone.Identifier stream (more < c:\theapp.exe:Zone.Identifier) you need to use the native IO routines to manipulate them, here is a managed wrapper.

How to remove programmatically the security protection of a copied file in network directory?

Open this file for write yourfile.exe:Zone.Identifier and close it, so it gets emptyed.

Is there a way to automate unblocking of a .net assembly

This is a flag that is added to the assembly by the Explorer. I think the easiest way to overcome this problem would be to store your assembly as a compressed zip archive on the network location and then unzip it to the local path where you need it.

this file is blocked because it came from another computer - ajax permission issue

The NTFS file system attache to this file a flag as unsafe. You can use one utility from Sysinternals called Streams to remove this flag. You can download the Streams from:

http://technet.microsoft.com/en-us/sysinternals/bb897440.aspx

Then using the Process class you can run the streams -d <file.xml> command to remove this flag, after you have get the file. How to run it:

Process runcommd = new Process();

runcommd.StartInfo.FileName = "streams";
runcommd.StartInfo.Arguments = " -d \"fullpath\\file.xml\"";

runcommd.StartInfo.UseShellExecute = false;
runcommd.StartInfo.CreateNoWindow = false;

runcommd.StartInfo.RedirectStandardError = true;
runcommd.StartInfo.RedirectStandardOutput = true;
runcommd.StartInfo.RedirectStandardInput = true;

// now run it
runcommd.Start();

// be sure that we end
runcommd.StandardInput.Flush();
runcommd.StandardInput.Close();

The Streams are from MS site, so its official and credible source, and its just a utility that remove this flag from the file. I think that you can do your job.

Related:
https://superuser.com/questions/38476/this-file-came-from-another-computer-how-can-i-unblock-all-the-files-in-a

http://www.k9ivb.net/files/This%20file%20came%20from%20another%20computer%20and%20might%20be%20blocked.pdf

How can I unblock a file using C#?

You can try opening a FileStream with FileShare.ReadWrite flag. E.g:

new FileStream("myFile.dat", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);

The gives more than one process the ability to write to the file.



Related Topics



Leave a reply



Submit