Click here to Skip to main content
15,921,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to extract a zip file in vb.net whose format is .zip or .rar, it is giving me exception illegal character in path.

But when I try to extract the file using winrar it is extracted successfully.

After extracting I saw there are files whose names include illegal characters like . ? :

if these are illegal then how winrar is creating file with these names.

or

Is there any other way to extract file and folder which can extract all the files with illegal characters from the zip file?

What I have tried:

i tried two methods to extract the zip file
METHOD 1:
ZipFile.ExtractToDirectory(SaveLocation, ExtractLocation)


METHOD 2:
Private Sub UnRar(ByVal WorkingDirectory As String, ByVal filepath As String)

        ' Microsoft.Win32 and System.Diagnostics namespaces are imported
        'D:\KIS Folder\Educate\EmpowerLearn\PlayList\Files\AssessmentItems\Teachers\a0a88482-0300-423a-bc3e-39a30b281e9d
        Dim objRegKey As RegistryKey
        objRegKey = Registry.ClassesRoot.OpenSubKey("WinRAR\Shell\Open\Command")
        ' Windows 7 Registry entry for WinRAR Open Command

        Dim obj As Object = objRegKey.GetValue("")

        Dim objRarPath As String = obj.ToString()
        objRarPath = objRarPath.Substring(1, objRarPath.Length - 7)

        objRegKey.Close()

        Dim objArguments As String
        ' in the following format
        ' " X G:\Downloads\samplefile.rar G:\Downloads\sampleextractfolder\"
        objArguments = " X " & " " & filepath & " " + " " + WorkingDirectory

        Dim objStartInfo As New ProcessStartInfo()
        ' Set the UseShellExecute property of StartInfo object to FALSE
        ' Otherwise the we can get the following error message
        ' The Process object must have the UseShellExecute property set to false in order to use environment variables.
        objStartInfo.UseShellExecute = False
        objStartInfo.FileName = objRarPath
        objStartInfo.Arguments = objArguments
        objStartInfo.WindowStyle = ProcessWindowStyle.Hidden
        objStartInfo.WorkingDirectory = WorkingDirectory & "\"

        Dim objProcess As New Process()
        objProcess.StartInfo = objStartInfo
        objProcess.Start()

    End Sub
Posted
Updated 23-Dec-20 6:02am
Comments
Richard MacCutchan 23-Dec-20 7:22am    
You need to show the actual string that causes the exception to be thrown.

1 solution

 
Share this answer
 
Comments
MukulMohal 5-Jan-21 5:00am    
Yes tried this one also by converting this to vb.net but result is still same is any other way to extract a file which has special characters in the filename.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900