Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

using 7zip in c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nologo - 26 Mar 2008 16:52 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.