Comeau Software Solutions

Making sense of technology since 2000.

Menu
  • Home / Updates
  • Services / Contact Us
  • Rogue C# Project Page
  • More Resources
    • Join Ocala’s Tech Community!
    • YouTube Channel
    • Personal Site
Menu

Weekend Links

Posted on April 22, 2012November 8, 2022 by Andrew Comeau

I’d planned to spend the weekend writing up a new programming article for the site but it got a little hi-jacked by another project I was working on. On Friday, I needed to figure out how to generate ZIP files from a website and just couldn’t put it down for the weekend. The situation is one where the site is generating multiple text files for download and I want the user to be able to download all the files as one ZIP file.

So, naturally I hit Google and started looking up code libraries, preferably free ones, and I was able to find a couple. Of the two I tried, I’m thinking I prefer DotNetZip which made it really simple to generate a ZIP file with the exact files I needed – like this simple:

using Ionic.Zip;

protected void ZipTest()
StreamWriter swFile;
ZipFile newZip = new ZipFile();

string zipFN;
string streamFN;
int fileNumber = 1;
for (int x = 1; x <= 3; x++)
{
streamFN = Server.MapPath("~/Output") + "\\" + fileNumber.ToString("0000") + ".txt";
swFile = new StreamWriter(streamFN);
swFile.WriteLine("File " + DateTime.Now.ToFileTime());
swFile.WriteLine("Created on " + DateTime.Now.ToString());
swFile.Flush();
swFile.Close();
 newZip.AddFile(streamFN, "");
fileNumber++;
}

zipFN = Server.MapPath("~/Output") + "\\ZipFile.zip";
newZip.Save(zipFN);
}

Most of this code has to do with generating the text files for testing. The items in Bold declare the new ZIP file object, add the new files to it as they’re created and then saves the ZIP file. It worked within 15 minutes after I downloaded it unlike the other product that kept creating invalid ZIPs and had me running around the Net researching regular expression syntax which ended up not working anyway. I can’t fully vouch for DotNetZip as I’ve only just started using it but so far, I’m happy.


As I said, I also ended up doing a bit of research on regular expressions which are used to define search patterns in text samples such as file names and text files, etc.. An example would be the following:

^FILE.+\.txt$

This example could be used to search a list of files for any file names starting with “FILE” and ending with “.txt”. Using the REGEX class in .NET, you can quickly find matches for patterns like this one in blocks of text.


My other bit of fun for the weekend was coming home on Friday and finding that my copy of Visual Studio 2010 Professional had been delivered. (I know. I’m such a geek.) I’ve used it professionally at a couple different companies now and finally decided to get it for home use since I didn’t want to be limited to the 2010 Express versions. Amazon.com seems to have dropped the price on it and I’m guessing that has something to do with Visual Studio 11 being in beta. I’ll have to check that out at some point but for now, I’m happy with 2010 which is proven and stable.


Available on Amazon.com


NETGEAR Nighthawk M6 Pro 5G mmWave WiFi 6E Mobile Hotspot Router
Fast, secure connections up to 8 Gbps. Unlocked international roaming in over 125 countries.

NetGear

ComeauSoftware.com provides learning resources, including tutorials and videos, to help you in understanding today's technology. Please check out our YouTube channel and bookmark this site to stay informed of upcoming projects.

Comeau Software Solutions also provides software consultation, including the development of data solutions, in Ocala, Florida. This includes help with Microsoft Access database projects and assistance in moving to other solutions when needed. Please contact us for more information on how we can help you with your project needs.

Available on Amazon.com


Fahrenheit 451: A Novel
“A masterpiece . . . A glorious American classic everyone should read: It’s life-changing if you read it as a teen, and still stunning when you reread it as an adult.” —Alice Hoffman, The Boston Globe

Ray Bradbury
  • Articles
  • C#
  • Careers
  • Commentary
  • Database Design
  • Databases
  • Hardware
  • How-to
  • Humor
  • Internet
  • Jobs
  • Linux
  • Microsoft Access
  • MySQL
  • Ocala I.T. Professionals
  • Personal
  • Personal Tech
  • Programming
  • Resources
  • Reviews
  • Rogue C# Series
  • Software
  • SQL
  • Uncategorized
  • Web Design
  • Writing
©2023 Comeau Software Solutions | Theme by SuperbThemes