Add string as file to subfolder

Nov 14, 2011 at 6:48 AM


I want to create an archive with a number of subfolders and add files to these folders.
I have found out how to do it with a physical file, which is quite easy, but I want to find out how to add a document from memory to a subfolder.

I have this example code:

            ZipFile zip;
            DataTable dt = GetDataFromDataSource();
            string testdata="";

            using (StringWriter sw = new StringWriter())
                testdata = sw.ToString();

            Response.ContentType = "application/zip";
            Response.AddHeader("content-disposition", "attachment;");
            using (zip = new ZipFile())
                zip.AddFile(@"C:\TestProjects\TestFiles\readme.txt", "Data");
                zip.AddEntry("Export.xml", testdata);

Here, the "testdata" XML document is added to the root of the archive as a file named Export.xml.

So, the question is, could someone please tell me,  how to add the "testdata" XML document to the Data folder as a file named Export.xml?
I'll be using this in an ASP.NET solution, where I have the data in memory, and I'll prefere to avoid the extra step of writing the data to physical files, as well as the cleanup afterwords.

Best Regards