Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

assign .zip file to link

Posted on 2012-03-21
12
Medium Priority
?
357 Views
Last Modified: 2012-04-05
Hello Experts,

I created an ASP.NET application that retrieves a list of printers on a certain network subnet which works fine. I have it setup so when the user clicks on a link it calls a .bat file to execute (install the printer via cmd line). However this will not work with FireFox, Opera, and a few other because of known security risks.

So what I would like to do now is include the .bat file inside of a .zip folder so that when the user clicks on the link that points to \\backup\printerdrivers\HP-LaserJet4250.zip that it will prompt the user to either "Open" or "Save" the file to their desktop. Is this possible and if so how.

I'm using ASP.NET 4.0 and C#.

Thanks in advance!!!
0
Comment
Question by:asp_net2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 37751271
what's the difference between linking the bat file and zip? it'll be the same sort of linkage.
just zip your bat file and point to it. you'll be prompted to save it and then do whatever you like
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 37751287
The first thing you will have to do is create the .zip file.  This should help;

http://www.gutgames.com/post/Creating-a-Zip-File-in-C.aspx

Check out DotNetZip, http://dotnetzip.codeplex.com/

You can use GZipStream too;

http://forums.asp.net/t/1086292.aspx


public static void Compress(FileInfo fi)
    {
        // Get the stream of the source file.
        using (FileStream inFile = fi.OpenRead())
        {
            // Prevent compressing hidden and already compressed files.
            if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden)
                    != FileAttributes.Hidden & fi.Extension != ".gz")
            {
                // Create the compressed file.
                using (FileStream outFile = File.Create(fi.FullName + ".gz"))
                {
                    using (GZipStream Compress = new GZipStream(outFile,
                            CompressionMode.Compress))
                    {
                        // Copy the source file into the compression stream.
                        byte[] buffer = new byte[4096];
                        int numRead;
                        while ((numRead = inFile.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            Compress.Write(buffer, 0, numRead);
                        }
                    }
                }
            }
        }

Open in new window


Once the file has been created, linking it should be a no brainer.
0
 
LVL 4

Author Comment

by:asp_net2
ID: 37752055
@mgfranz,

What is the difference from just manually zipping the files up and placing them in the files system for retrieval compared to the code you supplied?

I just need to be able to download the .bat file. Firefox will NOT run scripts from within their browsers for security reasons but IE will. So I thought it would be best to some how provide the user with the option to download the file.

I did include the .bat file into a .zip folder but when I provided the link to click on it did not ask me if I wanted to "Open" or "Save" the file. It appeared to be trying to open the .bat file instead.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 24

Expert Comment

by:alexey_gusev
ID: 37752088
hmm, that's interesting.
is there any setting in FF that prevents files from just simple downloading? imho, the normal behaviour is to start downloading showing the progress in separate Downloads popup.
0
 
LVL 4

Author Comment

by:asp_net2
ID: 37752092
@alexey_gusev,

for some reason if I zip the file up I'm not promtped to Open or Save the .zip file.
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 37752114
can you use linking based on IP address rather than WNet name?
(ie http://1.1.1.1/backup/printerdrivers/HP-LaserJet4250.zip)

just trying to see if it makes any difference. also, have a look at your registry to get default behaviour for "zip" extension
0
 
LVL 4

Author Comment

by:asp_net2
ID: 37752128
@alexey_gusev,

Let me try this solution to see if IP link works. I'm currently using \\backup\printerdrivers\HP-LaserJet4250.zip.

Stand by :)
0
 
LVL 4

Author Comment

by:asp_net2
ID: 37752368
@alexey_gusev,

Yes, if I use the IP then it prompts me to Open or Save in both IE and FF.
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 37752912
ok, ip or hostname, it seems that the browser treats it as URI and offers you to save it, while network path is interpreted as 'command line' sort of thing.

alternatively, you probably could register your own custom scheme (like http) but it's too much hassle I reckon.
0
 
LVL 4

Author Comment

by:asp_net2
ID: 37752978
How would I do what you mentioned below?

>> alternatively, you probably could register your own custom scheme (like http) but it's too much hassle I reckon.
0
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 1500 total points
ID: 37753248
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 37753948
Check the MIME types that your host allows, if it does not allow .zip files to be sent you will get the kinds of issues you are running into.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question