ASP.net 7zip backup example?

cyberiadmin
cyberiadmin used Ask the Experts™
on
Hello,

Could someone please create an example 7zip asp.net script, more info below?

An ASP.net 2.0 web page that creates a 7zip archive on the server for a backup. This is done by executing a 7zip console application with parameters. The page should see the console output live.

7zip cmd line:
D:\7za.exe a “D:\backup.7z” “D:\backup source\”
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
I saw your other question. The compression I could do but I was not sure about the progress bar. It was something I was going to look into but would need a bit of time on that.

Regarding this though, have a look at the Process object

Now if you had spaces in your path in the arguments, Im not sure how to handle that, possibly single quotes?
Dim objProcess As System.Diagnostics.Process
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = "D:\7za.exe"
            objProcess.StartInfo.Arguments = "a D:\backup.7z 'D:\backup source\*.*'” 
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objProcess.Start()

            'Wait until the process passes back an exit code 
            objProcess.WaitForExit()

            'Free resources associated with this process
            objProcess.Close()
        Catch
            MessageBox.Show("Could not start process", "Error")
        End Try

Open in new window

Top Expert 2006

Commented:
chr(34). Should of known as thats what I use for classic vb, doh!

objProcess.StartInfo.Arguments = "a D:\backup.7z " + chr(34) + "D:\backup source\*.*" + chr(34)

when u use it remember the spaces before/after anything u use it on

Author

Commented:
From a quick read of this code, it looks like it just starts the backup but does not print the console output live, is this is right. Could i please have the code to print it live included also?

Thanks
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Top Expert 2006

Commented:
I was thinking these two lines might of done it. By console output live window, do you mean the 7zip process?

Set the window size
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal

Wait until the process passes back an exit code
            objProcess.WaitForExit()


I will give it a test with a large zip.
Top Expert 2006

Commented:
Ok, I ran a 7zip command backup up some large files and the console window (assume you mean the dos window) came up which showed the status of compressing files with percentages etc

Author

Commented:
I would like the 7zip console output displayed on the web page.
Top Expert 2006
Commented:
That is something I have never tried. I went looking at the MS website and came across this. Whaddya think?

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput%28VS.71%29.aspx

We can setup startupinfo with args like in the example above then see if we can use the streamreader output

From looking at this, I am not sure if the output you capure is realtime. it looks like you get it once the process completes.



Dim myProcess As New Process()
Dim myProcessStartInfo As New ProcessStartInfo("Process_StandardOutput_Sample.exe")
myProcessStartInfo.UseShellExecute = False
myProcessStartInfo.RedirectStandardOutput = True
myProcess.StartInfo = myProcessStartInfo
myProcess.Start()

Dim myStreamReader As StreamReader = myProcess.StandardOutput
' Read the standard output of the spawned process.
Dim myString As String = myStreamReader.ReadLine()
Console.WriteLine(myString)
myProcess.Close()

Open in new window

Author

Commented:
Thanks, again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial