Zip a rar file

May 6, 2010 at 3:47 PM

There is a way for zip a rar file? when I try it i receive this error: filenotfoundexception

 

Thankyou

May 6, 2010 at 4:31 PM

I have found that the problem is the name of the file and not rar type.

The name is "S105_SRT_ESI_A01 (Pianta a +27.60 - )_23-04-2010.rar"

I must set any option for this file?

 

Coordinator
May 6, 2010 at 4:36 PM

I don't understand your question, but,...
DotNetZip does not read RAR files.

 

May 6, 2010 at 4:42 PM

I need to zip a file with this file name: S105_SRT_ESI_A01 (Pianta a +27.60 - )_23-04-2010.rar

When I try aI receive an exception.

There is any otion to set for this type of file name?

Coordinator
May 6, 2010 at 5:53 PM

Show me the code you use, and the full exception stacktrace.

May 7, 2010 at 8:23 AM
this is the code: 
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



        Dim curr_path, tmp_path As String
        
        curr_path = Directory.GetCurrentDirectory()
        tmp_path = curr_path & "\tmp"

        If Dir(tmp_path, vbDirectory) = "" Then
            MkDir(tmp_path)
        Else
            Directory.Delete(tmp_path, True)
            MkDir(tmp_path)
        End If


        Dim file_Target As String = tmp_path & "\allegati.zip"


        If File.Exists(file_Target) Then
            If (MessageBox.Show(String.Format("The file you have specified ({0}) already exists.  Do you want to overwrite this file?", _
                                              file_Target), "Confirmation is Required", _
                                              MessageBoxButtons.YesNo, MessageBoxIcon.Question) <> DialogResult.Yes) Then
                Return
            End If
            File.Delete(file_Target)
        End If
        Me._saveCanceled = False
        Me._nFilesCompleted = 0
        Me._totalBytesAfterCompress = 0
        Me._totalBytesBeforeCompress = 0

        ' Start Outlook.  
        ' If it is already running, you'll use the same instance...    
        Dim olApp As Outlook.Application
        olApp = CreateObject("Outlook.Application")

        ' Logon. Doesn't hurt if you are already running and logged on...    
        Dim olNs As Outlook.NameSpace
        olNs = olApp.GetNamespace("MAPI")
        olNs.Logon()

        Dim objOutlk
        Dim objMail

        Dim str_Attach As String
        Dim cont_mail As Integer = 1
        'Create a new message 
        'Dim fileDetail As IO.FileInfo
        str_Attach = ""
        If ListBox1.Items.Count > 0 Then

            If CheckBox1.Checked = False Then



                For Each O As Object In ListBox1.Items
                    objOutlk = CreateObject("Outlook.Application")
                    objMail = objOutlk.createitem(0)
                    If Text_A.Text <> "" Then objMail.To = Text_A.Text
                    If Text_cc.Text <> "" Then objMail.cc = Text_cc.Text
                    If Text_ccn.Text <> "" Then objMail.bcc = Text_ccn.Text

                    If Text_oggetto.Text <> "" Then objMail.subject = Text_oggetto.Text & " - " & cont_mail & "/" & ListBox1.Items.Count

                    If cont_mail > 1 Then
                        objMail.body = Text_oggetto.Text & " - " & cont_mail & "/" & ListBox1.Items.Count
                    Else
                        objMail.body = Rich_mess.Text
                    End If

                    str_Attach = O
                    objMail.attachments.add(str_Attach)
                    objMail.display()
                    cont_mail = cont_mail + 1
                Next
            Else ' spitta i file

                cont_mail = 1
                Dim zip1 As ZipFile = New ZipFile

                For Each O As Object In ListBox1.Items
                    ProgressBar1.Maximum = ListBox1.Items.Count



                    If File.Exists(O) Then zip1.AddFile(O, "Files")
                    If Directory.Exists(O) Then zip1.AddDirectory(O, "Files")

                    ProgressBar1.Value += 1

                Next

                zip1.MaxOutputSegmentSize() = Val(tx_splitsize.Text) * 1024 * 1024

                zip1.Save(file_Target)

                Dim a() As String
                a = Directory.GetFiles(tmp_path)


                Dim sortQuery = From word In a Order By word.Substring(word.Length - 3, 3) Select word


                For Each aa As Object In sortQuery

                    objOutlk = CreateObject("Outlook.Application")
                    objMail = objOutlk.createitem(0)
                    If Text_A.Text <> "" Then objMail.To = Text_A.Text
                    If Text_cc.Text <> "" Then objMail.cc = Text_cc.Text
                    If Text_ccn.Text <> "" Then objMail.bcc = Text_ccn.Text

                    'If Text_oggetto.Text <> "" Then objMail.subject = Text_oggetto.Text & " - " & cont_mail + 1 & "/" & a.Count '+ 1
                    objMail.subject = Text_oggetto.Text & " - " & cont_mail & "/" & a.Count '+ 1
                    If cont_mail > 1 Then
                        objMail.body = Text_oggetto.Text & " - " & cont_mail & "/" & a.Count '+ 1
                    Else
                        objMail.body = Rich_mess.Text
                    End If


                    str_Attach = aa

                    objMail.attachments.add(str_Attach)
                    objMail.display()
                    cont_mail = cont_mail + 1

                Next
            End If
            'Next







            'End If

        Else

            MsgBox("Devi allegare almeno un file")


     End If

        If Dir(tmp_path, vbDirectory) <> "" Then
            Directory.Delete(tmp_path, True)

        End If
        ProgressBar1.Value = 0
        'Clean up 
        objMail = Nothing
        objOutlk = Nothing
    End Sub

exception

System.IO.FileNotFoundException non è stata gestita
  FileName="D:\Visual basic\Automatic_Mail\Automatic_Mail\bin\Release\tmp\allegati.z01"
  Message="Impossibile trovare il file 'D:\Visual basic\Automatic_Mail\Automatic_Mail\bin\Release\tmp\allegati.z01'."
  Source="mscorlib"
  StackTrace:
       in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       in System.IO.File.Move(String sourceFileName, String destFileName)
       in Ionic.Zip.ZipSegmentedStream.TruncateBackward(UInt32 diskNumber, Int64 offset)
       in Ionic.Zip.ZipEntry.Write(Stream s)
       in Ionic.Zip.ZipFile.Save()
       in Ionic.Zip.ZipFile.Save(String fileName)
       in Automatic_Mail.Form1.Button1_Click(Object sender, EventArgs e) in D:\Visual basic\Automatic_Mail\Automatic_Mail\Form1.vb:riga 136
       in System.Windows.Forms.Control.OnClick(EventArgs e)
       in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       in System.Windows.Forms.Control.WndProc(Message& m)
       in System.Windows.Forms.ButtonBase.WndProc(Message& m)
       in System.Windows.Forms.Button.WndProc(Message& m)
       in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       in Automatic_Mail.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:riga 81
       in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       in System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 


Coordinator
May 7, 2010 at 3:35 PM

The problem you're having is related to the segmentation of the archive.

I don't know why it would fail.

First, what version of DotNetZip are you using?

Second, you need to employ a "Using" clause.  See any of the examples for how.  See the documentation for reasons why.  Don't skip the using clause.

Try that and tell me if it continues to fail.