NameSpace doesn't like zip file in ASP

Author Message
amallen9867

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 3/17/2008
  • Status: offline
NameSpace doesn't like zip file in ASP Monday, March 17, 2008 4:20 AM (permalink)
0

I have a vbscript that creates an empty zip file and then loads a couple of files into it for eventual download. As a stand-alone vbscript it works fine but when I add the code to an ASP page the code chokes on the NameSpace object. So I can create the empty zip file but I can't add any files to it.

Here's the code:
Dim zipFile, objFSO, objTxt, objApp
zipFile = "D:\ArcIMS\Output\SavedMapImages\aaa.zip" 'The path and name of your zip file

'Create an empty ZIP file
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTxt = objFSO.OpenTextFile(zipFile, 2, True)
objTxt.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, Chr(0))
objTxt.Close

'Copy the files into the ZIP file
Set objApp = Server.CreateObject("Shell.Application")
objApp.NameSpace(zipFile).CopyHere("D:\ArcIMS\Output\SavedMapImages\aaa.png ")
objApp.NameSpace(zipFile).CopyHere("D:\ArcIMS\Output\SavedMapImages\aaa.pgw ")

It's the NameSpace object in the last two lines that throw errors. And it's the zip file itself that causes the error; I don't get an error if I use a basic folder path.

Does anybody have a solution?

Thanks,

amallen
 
#1
    webber123456

    • Total Posts : 58
    • Scores: 0
    • Reward points : 0
    • Joined: 9/20/2007
    • Status: offline
    RE: NameSpace doesn't like zip file in ASP Tuesday, March 18, 2008 4:17 AM (permalink)
    0
    I doubt you can call the shell object from ASP because of security reasons.
     
    #2
      amallen9867

      • Total Posts : 4
      • Scores: 0
      • Reward points : 0
      • Joined: 3/17/2008
      • Status: offline
      RE: NameSpace doesn't like zip file in ASP Tuesday, March 18, 2008 4:47 AM (permalink)
      0
      webber123456 (or anyone else),

      Could I call a VBScript file from the VBScript within the ASP file to execute the code that adds files to the zip file? Might that get around the security issue?

      If not, do you have any suggestions how I might add files to an empty zip file via ASP? That's my end goal.

      Thanks,

      amallen9867
       
      #3
        TNO

        • Total Posts : 2094
        • Scores: 36
        • Reward points : 0
        • Joined: 12/18/2004
        • Location: Earth
        • Status: offline
        RE: NameSpace doesn't like zip file in ASP Wednesday, March 19, 2008 8:02 AM (permalink)
        0
        In my experience, its always been safest to keep files in relative locations instead of complete paths on the server. Also, any time you are doing something with file locations, try to use MapPath
        To iterate is human, to recurse divine. -- L. Peter Deutsch
         
        #4
          amallen9867

          • Total Posts : 4
          • Scores: 0
          • Reward points : 0
          • Joined: 3/17/2008
          • Status: offline
          RE: NameSpace doesn't like zip file in ASP Wednesday, March 19, 2008 8:47 AM (permalink)
          0
          Good advice above. I will keep that in mind for the final version.

          Now for the big question(s): How do I add files to an empty zip file using vbscript in an ASP page? Can I do so using MapPath? Any other way?

          amallen9867
           
          #5
            TNO

            • Total Posts : 2094
            • Scores: 36
            • Reward points : 0
            • Joined: 12/18/2004
            • Location: Earth
            • Status: offline
            RE: NameSpace doesn't like zip file in ASP Wednesday, March 19, 2008 10:59 AM (permalink)
            0
            Perhaps this: http://classicasp.aspfaq.com/general/how-do-i-zip/unzip-files-from-asp.html

            If the application is local you don't have to worry about <path> variables and all that crap. (referring to the pkzip)
            To iterate is human, to recurse divine. -- L. Peter Deutsch
             
            #6
              amallen9867

              • Total Posts : 4
              • Scores: 0
              • Reward points : 0
              • Joined: 3/17/2008
              • Status: offline
              RE: NameSpace doesn't like zip file in ASP Friday, April 18, 2008 2:46 AM (permalink)
              0
              Thanks for the above posts. I ended up using XZip as my zip utility (http://xstandard.com/en/documentation/xzip/). Just install the dll somewhere and register it using regsvr32.

              Below is a code snippet for anyone interested. It's a working copy (but it does work!). I still have to clean it up using relative paths and MapPath.

                  'Initialize stuff for zip file
                  Dim folderPath, zipFilePath, fsoZipFile, fsoTxtFile, objZip
                  folderPath = "D:\wherever\" 'The path to the files to be zipped
                  zipFilePath = folderPath + "myzipfile.zip" 'The path and name of the zip file

                  'Create an empty ZIP file
                  Set fsoZipFile = Server.CreateObject("Scripting.FileSystemObject")
                  Set fsoTxtFile = fsoZipFile.OpenTextFile(zipFilePath, 2, True)
                  fsoTxtFile.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, Chr(0))
                  fsoTxtFile.Close

                  'Copy files into the ZIP file
                  Set objZip = Server.CreateObject("XStandard.Zip")
                  objZip.Pack folderPath + "filename.png", zipFilePath
                  objZip.Pack folderPath  + "filename.pgw", zipFilePath

              amallen9867
               
              #7

                Online Bookmarks Sharing: Share/Bookmark

                Jump to:

                Current active users

                There are 0 members and 1 guests.

                Icon Legend and Permission

                • New Messages
                • No New Messages
                • Hot Topic w/ New Messages
                • Hot Topic w/o New Messages
                • Locked w/ New Messages
                • Locked w/o New Messages
                • Read Message
                • Post New Thread
                • Reply to message
                • Post New Poll
                • Submit Vote
                • Post reward post
                • Delete my own posts
                • Delete my own threads
                • Rate post

                2000-2012 ASPPlayground.NET Forum Version 3.9