开发者

How to create a zip file which will open a url when a user unzips it?

开发者 https://www.devze.com 2023-03-23 21:35 出处:网络
I want to create a small application in VB.Net which will zip the file such that when user will unzip this file, a url will be opened in user\'s default browser.

I want to create a small application in VB.Net which will zip the file such that when user will unzip this file, a url will be opened in user's default browser.

Is there any way to create such files?

Thanks

EDIT

CAN WE OPEN ANY FILE INSIDE THE .ZIP ARCHIVE AFTER UNZIPPING IT ?

Actually,In my project, I am trying to build zip files which will open its help file (located at spec开发者_运维问答ific website) after extracting it. and This functionality is must for my project.


No. As far as I know, there is no way to open a URL while extracting in standard ZIP files.


You could look into creating a self-extracting archive, or a custom exe that will extract/uncompress embedded files and execute code. While this won't be your typical ".zip" file, it may still fit your requirements for this project. I don't have any resources off the top of my head, but a little Googling will probably turn up some examples.


No, there is no way to do this.


DotNetZip supports creation of a Self-extracting archive that can run any program after extraction. The program can be "open a file that was just extracted", or it can be "open any program on the machine" or it can be "run an EXE that was one of the extracted files", etc. This could be used to produce an SFX that opens a URL after extraction.

In VB.NET, the code to produce a self-extractor file that opens a URL is like this:

Using zip As New Ionic.Zip.ZipFile()

    zip.AddEntry("Entry1.txt", "This is the content")

    Dim opt As New Ionic.Zip.SelfExtractorSaveOptions()
    opt.Flavor = Ionic.Zip.SelfExtractorFlavor.WinFormsApplication
    opt.IconFile = "zippedFile.ico"
    opt.Description = "This is a self-extracting archive created by a vb.net app"
    opt.Copyright = "Copyright (c) 2011 Cheeso"
    opt.ProductVersion = "4.3.2"
    opt.ProductName = "SomethingFun"
    opt.SfxExeWindowTitle = "SomethingFun extractor"
    opt.PostExtractCommandLine = "http://news.google.com"  ' <<<-- your URL here
    zip.SaveSelfExtractor("SOverflow.exe", opt)
End Using

The above code produces an EXE called "SOverflow.exe", which depends on .NET 2.0. The property sheet available in Windows Explorer exposes some of the settings specified in the options above. It looks like this:

How to create a zip file which will open a url when a user unzips it?

When you run SOverflow.exe, it looks like this:

How to create a zip file which will open a url when a user unzips it?

When the user clicks "Extract", all the files get extracted, and afterwards, the command "http://news.google.com" is run, which pops that URL into the default browser.

This example shows a single entry in the archive, and an HTTP url for a command, but you could pack in numerous entries into the self-extracting archive, and run any arbitrary command.

The self-extractor (SOverflow.exe) is "openable" as a normal zip file - just rename it to SOverflow.zip and you can browse the contents in Windows Explorer, extract it in Winzip, etc. if you treat it as a zip file, you lose the self-extracting behavior, including the "run a command after extract" part.

DotNetZip is a free library.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号