SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Adding file to a Zip without Full Path

Last post 05-26-2008 12:49 PM by Ggalla1779. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 04-22-2008 1:53 PM

    Adding file to a Zip without Full Path

    Hi all

     I have created a wee routine that adds a file to an existing zip...however I it adds the full path. I need for them to be just on the top level..as when I ship these files the other side processes them on mainframe and they cant cope with the full path...it throws file to long error

    I saw from an old post thatPath.GetFileName might work but this just cause the source zip file not to be found... can anyone advise me how to fix this??

     

    Public Function AddtoZip(ByVal source As String, ByVal myFile As String) As Boolean

    '*** Source file to add

    If (Not (File.Exists(source))) Then

    Return False

    End If

    Dim mySourceZip As String

    mySourceZip = Path.GetFileName(source)

    Try

    'Dim myZip As ZipFile = New ZipFile(source)

    Dim myZip As ZipFile = New ZipFile(mySourceZip)

    myZip.BeginUpdate()

    myZip.Add(myFile)

    myZip.CommitUpdate()

    myZip.Close()

    Catch

    Return False

    End Try

    Return True

    End Function


    cheers George
  • 04-23-2008 2:35 PM In reply to

    Re: Adding file to a Zip without Full Path

    After mucking about with the routine I can get it to add my file into the Zip without a path, however its using the same name as the zip file.

     Can anyone lep with last bit?

     

    Dim myZip As ZipFile = New ZipFile(source)
              
                myZip.BeginUpdate()

                'This add the file but with current zipped name
                myZip.NameTransform = New ZipNameTransform(myFile)
                myZip.Add(myFile)

               
                myZip.CommitUpdate()
                myZip.Close()


    cheers George
  • 04-28-2008 1:39 PM In reply to

    Re: Adding file to a Zip without Full Path

    Can anyone help with this??


    cheers George
  • 05-17-2008 5:38 AM In reply to

    • wgrams
    • Not Ranked
    • Joined on 05-16-2008
    • Posts 2

    Re: Adding file to a Zip without Full Path

    ZipFile zf = ZipFile.Create(zipFilePath);

    zf.BeginUpdate();

    zf.NameTransform = new ZipNameTransform(fileToBeZippedPath.Substring(0, fileToBeZippedPath.LastIndexOf("\\")));

    zf.Add(fileToBeZippedPath);

    zf.CommitUpdate();

     

    The kicker is that the BeginUpdate() and CommitUpdate() have to be run for *each* file that you wish to not have its full path included.

  • 05-19-2008 12:08 PM In reply to

    Re: Adding file to a Zip without Full Path

     

    Thanks...I will give that a try...I am adding to an existing zip file dont know if that matters

     cheers George


    cheers George
  • 05-19-2008 5:15 PM In reply to

    • wgrams
    • Not Ranked
    • Joined on 05-16-2008
    • Posts 2

    Re: Adding file to a Zip without Full Path

    It shouldn't matter. Just use the code that begins with the "BeginUpdate()"

  • 05-26-2008 12:49 PM In reply to

    Re: Adding file to a Zip without Full Path

    On the trans form you seem to use \\, my path doesnt tend to have that ie "c:\zip\DemoZip.zip"

     Is this passing the file name or the path to the filename into transform?


    cheers George
Page 1 of 1 (7 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.