Download and import a zip file from Internet  
Author Message
Raulsassaa





PostPosted: .NET Framework Networking and Communication, Download and import a zip file from Internet Top

Does anyone know the best way to download (it would be rather peeping since I dont need to save it) a zip file from Internet, and using it to import to my webapp


.NET Development1  
 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, Download and import a zip file from Internet Top

you can use the WebClient/FTPWebRequest/FTPWebResponse classes to get directory listing....

this is new in .NET 2.0

http://msdn2.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx

http://msdn2.microsoft.com/en-us/library/system.net.ftpwebresponse.aspx

 

a quick small example to get directory listing:

 

NetworkCredential theCredentials = new NetworkCredential("username", "password");

FtpWebRequest theRequest = (FtpWebRequest)WebRequest.Create("ftp://blah.com");

theRequest.Credentials = theCredentials;

theRequest.Method = WebRequestMethods.Ftp.ListDirectory;

 

FtpWebResponse theResponse = (FtpWebResponse)theRequest.GetResponse();

 

StreamReader theReader = new StreamReader(theResponse.GetResponseStream())

string[] theFilesListing = theReader.ReadToEnd().Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);

 

this will hook up to the ftp site, get the listing of the directory and store each entry in a string[] array which you can loop through and check what you want

 

does this help/give you some guidence Be sure to import the System.IO and System.Net namespace



 
 
Raulsassaa





PostPosted: .NET Framework Networking and Communication, Download and import a zip file from Internet Top

Well, but how to deal with the zip issue

 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, Download and import a zip file from Internet Top

what issue exactly

 
 
Raulsassaa





PostPosted: .NET Framework Networking and Communication, Download and import a zip file from Internet Top

The file is zipped in the webserver. I would have to read it inside the zip format.

 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, Download and import a zip file from Internet Top

nothing much you can do about that but download it and extract it. Take a look at the WebClient DownloadFile method

http://msdn2.microsoft.com/en-us/library/xz398a3f.aspx



 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, Download and import a zip file from Internet Top

The file is zipped in the webserver. I would have to read it inside the zip format.

There are 2 classes supported by .Net to Zip/Unzip files in System.IO.Compression namespace!

  1. GZipStream
  2. DeflateStream

Mostly files are compressed using GZipStream So I think you should give it a try to unzip your file. You should know what was the extenstion of the file before Encryption an u need to create the file with the same extension.

I hope this will help!

Best Regards,



 
 
Jorg Jooss - MSFT





PostPosted: .NET Framework Networking and Communication, Download and import a zip file from Internet Top

Note that these classes won't work with ZIP files created by tools like WinZIP, PKZIP, InfoZIP etc. (what most users consider a "ZIP file").

There's no built-in support for this ZIP format in the .NET framework, but you can implement a workaround using J# and its Java runtime. There are also both open source and commercial third party components available for working with ZIP files.