By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Removing a file path from xml while zipping

maylortaylor
P: 72
I am trying to read a XML file that will find the location of certain files and then zip them into a directory also located in the XML file. However, as of now, I am copying the entire path of the file where I only want the file itself in the zip. Below is some of the code in question for reference.
Expand|Select|Wrap|Line Numbers
  1. ------ Declarations ------
  2. Sub main()
  3.  
  4.         Dim doc As New System.Xml.XmlDocument
  5.         doc.Load("C:\users\matt taylor\desktop\backup\backup.xml")
  6.         Dim nSource = doc.GetElementsByTagName("Source")
  7.         Dim nDestin = doc.GetElementsByTagName("Destination")
  8.  
  9. ------ outputting the innertext of the 'source' XML tag ----
  10. For Each item As System.Xml.XmlElement In nSource
  11.             Console.WriteLine(item.InnerText)
  12.             myLogger.Log(item.InnerText)
  13.         Next
  14.  
  15. ----- zipping ----
  16. Using zip As New ZipFile()
  17.             For Each item As System.Xml.XmlElement In nSource
  18.                 zip.AddFile(item.InnerText)
  19.             Next
  20.             For Each item As System.Xml.XmlElement In nDestin
  21.                 zip.Save(item.InnerText)
  22.             Next
  23.         End Using

>>>>>>> as you can see from my code, the zip is pulling directly from the inner text of the XML file (which is the full path name of where the file came from). How would I get my zip to just zip the file by itself (no directories)
Nov 20 '12 #1

✓ answered by Rabbit

If you look at the documentation for ionic.dll, the AddFile method has an optional second parameter that allows you to define the directory to use in the archive.
Expand|Select|Wrap|Line Numbers
  1. zip.AddItem(itemPath, "flat")

Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,383
The answer depends on which API you're using to do your zipping. You should read the documentation from whomever wrote the API.
Nov 20 '12 #2

maylortaylor
P: 72
I'm using Ionic.dll to do my zipping. I feel that i could easily correct this issue if just added a line or two of code that would remove the directory path after it has been added to the zip file index. But seeing as to how i'm only a week into VB, i'm limited on my knowledge.
Nov 20 '12 #3

Rabbit
Expert Mod 10K+
P: 12,383
If you look at the documentation for ionic.dll, the AddFile method has an optional second parameter that allows you to define the directory to use in the archive.
Expand|Select|Wrap|Line Numbers
  1. zip.AddItem(itemPath, "flat")
Nov 20 '12 #4

maylortaylor
P: 72
Thank you rabbit. That worked perfectly.
Nov 20 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.