Some computers may have security setup to not trust some files download from the web such as a form resource file in a VB.NET or C# project. If there are many files one must right click on each file in Windows Explorer and un-check mark of the web. If not done Visual Studio will complain and not compile the project.
The following code accepts a path to were these files exists and unmark all files in the root and underlying folders.
C# 9 .NET Core
VB.NETCode:/// <summary> /// Removed 'mark of the web' from all files in a folder recursively /// </summary> /// <param name="folderName">folder to perform the operation on</param> public static void UnblockFiles(string folderName) { if (!Directory.Exists(folderName)) { return; } var start = new ProcessStartInfo { FileName = "powershell.exe", Arguments = $"Get-ChildItem -Path '{folderName}' -Recurse | Unblock-File", CreateNoWindow = true }; using var process = Process.Start(start); }
Or simply open a PowerShell window and run the script in Arguments.Code:''' <summary> ''' Removed 'mark of the web' from all files in a folder recursively ''' </summary> ''' <param name="folderName">folder to perform the operation on</param> Public Sub UnblockFiles(folderName As String) If Not Directory.Exists(folderName) Then Return End If Dim start = New ProcessStartInfo With { .FileName = "powershell.exe", .Arguments = $"Get-ChildItem -Path '{folderName}' -Recurse | Unblock-File", .CreateNoWindow = True } Using process As Process = Process.Start(start) End Using End Sub




Reply With Quote
