All,
i'm using 7zip to archive data that my application produces, the
following code fails to work. The problem is, the code seems to
redirect where its looking for the 7z.exe to where-ever the
SaveFileDialog is pointed at to save the document.
if (this.saveFileDialog1.ShowDialog(this) != DialogResult.Cancel)
{
string strFileLocation = "C:\\temp\\";
string strFileName;
string strFileToZip = "c:\\temp\\reports";
string strSB;
strFileName = this.saveFileDialog1.FileName;
StringBuilder SB = new StringBuilder();
SB.Append ("/c ");
SB.Append ("7za ");
SB.Append ("a ");
SB.Append (strFileLocation);
SB.Append (strFileName);
SB.Append (" ");
SB.Append (strFileToZip);
strSB = SB.ToString();
ProcessStartInfo psiOpt = new ProcessStartInfo(@"cmd.exe", strSB);
psiOpt.WindowStyle = ProcessWindowStyle.Normal;
psiOpt.RedirectStandardOutput = true;
psiOpt.UseShellExecute = false;
psiOpt.CreateNoWindow = true;
// Create the actual process object
Process procCommand = Process.Start(psiOpt);
// Receives the output of the Command Prompt
StreamReader srIncoming = procCommand.StandardOutput;
// Show the result
MessageBox.Show(srIncoming.ReadToEnd());
// Close the process
procCommand.WaitForExit();
}
if i dont use the savefiledialog and use:
strFileName = C:\temp\archive%DATE:/=_%.zip, this works perfect to the
preset location in the string text.
Any ideas how i can retain the .exe location wihtout it changing by
using savefiledialog?
Cheers
Marc Gravell - 26 Mar 2008 17:09 GMT
Have you tried setting psiOpt.WorkingDirectory ?
Of course, I'd be tempted to use zip for compatibility; #ziplib for
example can be run directly as managed code, removing any pre-
requisites and IPC issues.
Marc
nologo - 26 Mar 2008 17:15 GMT
> Have you tried setting psiOpt.WorkingDirectory ?
>
[quoted text clipped - 3 lines]
>
> Marc
hmm #ziplib, i'll look into it. have been trying to find a freeware
zip application.
nologo - 26 Mar 2008 17:25 GMT
cheers all,
with regards to my initial question:
psiOpt.WorkingDirectory = [directory]
resolved the issue, but its not ideal.
i'm looking into #ziplib http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx
nologo - 26 Mar 2008 17:33 GMT
> cheers all,
> with regards to my initial question:
> psiOpt.WorkingDirectory = [directory]
> resolved the issue, but its not ideal.
> i'm looking into #ziplibhttp://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx
psiOpt.WorkingDirectory = [directory]
how do i make a reference to the starting location of the application?
for example, i just want it to quote \\bin\\debug instead of putting
something like C:\\username\folder\ ?
Ben Voigt [C++ MVP] - 26 Mar 2008 21:04 GMT
>> cheers all,
>> with regards to my initial question:
[quoted text clipped - 5 lines]
> psiOpt.WorkingDirectory = [directory]
> how do i make a reference to the starting location of the application?
For example, read Environment.CurrentDirectory when the application starts
and save that in a string variable.
Or Assembly.GetEntryAssembly().CodeBase if you want the directory containing
your application.
> for example, i just want it to quote \\bin\\debug instead of putting
> something like C:\\username\folder\ ?
Peter Duniho - 26 Mar 2008 18:35 GMT
> cheers all,
> with regards to my initial question:
> psiOpt.WorkingDirectory = [directory]
> resolved the issue, but its not ideal.
IMHO, you really should be using full path names always. Then the working
directory would have no effect. However, if that's not feasible for some
reason, a better solution to your immediate issue might be to set the
SaveFileDialog.RestoreDirectory property to "true".
Pete
Ignacio Machin ( .NET/ C# MVP ) - 26 Mar 2008 17:14 GMT
> All,
> i'm using 7zip to archive data that my application produces, the
[quoted text clipped - 41 lines]
> using savefiledialog?
> Cheers
Hi,
There are 100% managed solutions for zip files, take a lookat
ICsharpzip library
tuco - 26 Mar 2008 16:23 GMT
>>There are 100% managed solutions for zip files, take a lookat
>>ICsharpzip library
i have problem with ICsharpzip with big files, i use 7za.exe and problem
resolved.
Peter Bromberg [C# MVP] - 26 Mar 2008 21:13 GMT
If you like 7Zip there is a build using the managed LZMA# (7 zip) SDK I
believe on codeplex.com. It's all managed code, so you don't need to use
Process class at all. Or, as the other poster mentioned, use SharpZipLib.
--Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
> All,
> i'm using 7zip to archive data that my application produces, the
[quoted text clipped - 40 lines]
> using savefiledialog?
> Cheers