Click here to Skip to main content
15,885,175 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Does anyone know how to run 7zip and name the archive the current date and time like: 11012010192708.7z?
Posted
Updated 14-Aug-12 7:43am
v2
Comments
Sergey Alexandrovich Kryukov 14-Aug-12 12:45pm    
Does it have anything to do with ASP.NET?
--SA
iismoove 14-Aug-12 12:46pm    
No
Sergey Alexandrovich Kryukov 14-Aug-12 12:58pm    
Then remove this tag. You are the one who is interested in tag relevance the most. I answered to your question, anyway.
--SA

1 solution

You don't need to "run" 7zip. You can use 7zip library for .NET, which is a .NET wrapper around 7-zip library:
http://sevenzipsharp.codeplex.com/[^].

See also this CodeProject article:
C# (.NET) Interface for 7-Zip Archive DLLs[^].

As to the file name, you can name your files any way you want. If you need to get current time, you can use System.DateTime.Now or System.DateTime.UtcNow; please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

To make a string out of time, use System.DateTime.ToString(string format) with appropriate format string. Please see:
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

Now you have all you need.

But I would not advise you to use the format you suggested. For most purposes, it's much better to use standard "sortable" format, which formats the time the way that ordering of stings by time is always the same as the files "by name" (standard alphanumerical order), which makes it very convenient to look through the files in the file managers (note that you did not ask us about setting file time, such as creation or last modification time). This format specifier is "s", highly recommended: Year-month-day"T"hours-minutes-seconds.

—SA
 
Share this answer
 
v2
Comments
Abdul Quader Mamun 14-Aug-12 13:13pm    
greatly Answered!

Please read my newly posted article and plz comments or vote.
http://www.codeproject.com/Articles/440607/A-Framework-for-Software-Application
Sergey Alexandrovich Kryukov 14-Aug-12 13:24pm    
Thank you, Abdul.
I'll need time to look at this article...
--SA
Abdul Quader Mamun 14-Aug-12 13:26pm    
ok, when you will get free/time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900