I am trying to create a cab file that composes of 3 files. I am using WiX dlls as recommended on another page. The problem I face is that I need the files compressed without creating a folder. When I use the below method and extract the files once again, the compressed files are now houses within a folder of the same name as the cab file.
Is it possible create the file without the folder?
Here is my code
CabInfo cab = new CabInfo(#"c:\cab\test.cab");
List<String> files = new List<string>();
files.Add(#"C:\cab\test.D");
files.Add(#"C:\cab\test.L");
files.Add(#"C:\cab\test.U");
cab.PackFiles(null, files, null);
extracted files
-test
-test.D
-test.L
-test.U
The problem comes from the program that extracts the .cab file. Nothing can be done at compression side.
If the decompressor is yours, it can be made to extract files directly. 7-Zip has the option to not create the folder too.
There is nothing in the format of an archive (.cab or anything else) that can prevent that folder creation.
Related
I have one git repository where I have to modify one file under that zip folder.
I'm looking a way to modify file over repository only. I know below one options:
download zip file and make changes and push it back [this is not working because my zip file is 11 mb and administrator not allowing me to increase the size which is currently 10 mb from the project setting in devops]
Is there any other way I can follow and modify the zip file content.?
Thanks
Under the hood, git will compare multiple versions of files, work out the differences, then compress everything.
By storing a file that's already compressed you are preventing git from storing multiple similar versions efficiently.
If you need a zip file, create it in your build script, not your source code.
I want to zip some files in a directory. I have googled a lot but i always saw examples about zipping a directory (all files in directory) by the code below:
string startPath = #subPath;
string zipPath = #"C:\result.zip";
ZipFile.CreateFromDirectory(startPath, zipPath);
I am referencing System.IO.Compression.Filesystem.dll
This code zips all the files in the directory referenced by startPath.
I tried ZipArchive class for compressing but it compress file with directories on its path. For example,
assume i want to zip "a.txt" located at "C:\directories\Graphics\a.txt". The zip file contains directories "directories" and "Graphics" and into these directories the file "a.txt". It is not a good solution to cut files then erase the directories and paste again since i am working on big size data.
How can I zip only some of files at a directory?
How can I zip some files that are located in different directories?
I am looking up the subject for 2 days. Is it a kind of constraint in .Net?
You can use the ZipArchive class, first create it and then - once created you just add ZipArchiveEntry objects into the archive. Each of the ZipArchiveEntry objects represents a single file that you will add to the archive.
Some tips:
You can find more info and a sample of how this could be done on MSDN, here: http://msdn.microsoft.com/pl-pl/library/system.io.compression.ziparchive(v=vs.110).aspx and here: http://msdn.microsoft.com/pl-pl/library/system.io.compression.ziparchiveentry(v=vs.110).aspx.
This may not be an exact solution but should work for your scenario. I'll give you the steps :
Create a Temporary Directory
Read and copy your Selected files into the Temporary directory. This applies to your second scenario as well.
Zip the temporary directory
Delete Temporary Directory after you are done
I would recommend using File.Copy to copy all your desired files to a temporary directory, then zip them all from there and delete the temporary directory once the zip operation has finished.
I'm developing a 3D application in which the user may load multiple images, the 3D library I use has a function to export the whole scene as XAML, of course in XAML I only have the path to the images, so the file will only be valid on the machine in which it has been created, what I want to do is to save the XAML , change image(s) path inside the XAML to be relative to the XAML file path, save image(s) along the XAML in the same new file, like this the new file will always contain the XAML and the images. how to save multiple files types within the same file ? any other suggestions on the whole idea would be appreciated.
If you are using .NET 4.5, then you can programmatically save multiple files into a zip folder easily using the new ZipFile class.
First, you'll need to prepare your files into a new folder (Directory.CreateDirectory, File.Move) and then you can simply use the ZipFile.CreateFromDirectory Method (adapted from the linked page):
string filePathOfNewFolder = #"c:\example\start";
string zipFilePath = #"c:\example\result.zip";
ZipFile.CreateFromDirectory(filePathOfNewFolder, zipFilePath);
UPDATE >>>
For .NET 4, you might have to rely more on third party libraries. You can download the DotNetZip library from the DotNetZip - Zip and Unzip in C#, VB, any .NET language page on CodePlex. It also works fairly simply. Here is an example taken from the linked page:
using (ZipFile zip = new ZipFile())
{
// add this map file into the "images" directory in the zip archive
zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
// add the report into a different directory in the archive
zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
zip.AddFile("ReadMe.txt");
zip.Save("MyZipFile.zip");
}
Store your XAML and other image files into one file (e.g. zip or cab).
When running your program, unzip relevant file into a temp folder so you can get the relevant path working.
Empty the temp folder afterwards if required.
I am having a project which is named as myfirstproject.In that I am having .cs files .xsd files .rpt files and .config files etc.Here I need to get the filename of .xsd files,if it is example.xsd,I need to get the example file name in one datatable.Like that all the .xsd file names should be filled in one datatable.The project exists in any C or D or E drive in that drive myfirstproject is the solution name and project name.In that I need to get the filenames with the extensions of .xsd.I am working with windows application.Please help me with suggestions or solution
Thanks In Advance.
Perhaps this helps:
var root = new DirectoryInfo(Path.GetDirectoryName(Application.ExecutablePath)).Parent.Parent;
var allXsdFiles = root.EnumerateFiles(".xsd", SearchOption.AllDirectories);
DataTable tblFiles = new DataTable();
tblFiles.Columns.Add("Filename");
tblFiles.Columns.Add("Directory");
foreach (FileInfo xsd in allXsdFiles)
tblFiles.Rows.Add(xsd.Name, xsd.Directory);
Maybe you need to to play around with the root folder. I have used Application.ExecutablePath to get the bin folder. Normally your project path is two parents above.
You can retrieve files from disk by using many different methods. The System.IO namespace contains many helper classes that are useful to you.
Usually you wouldn't want to read directly from your solution directory (you will read files from the executable directory, relative to the executable directory, or from a directory configured in your configuration file. Many of the methods also depend on whether you're using winforms or webforms.
The following bit of code is not something I would use in a production system, but will scan through the executable directory and pick up every .xsd file and writes it to the console, for a winforms application:
foreach (var file in System.IO.Directory.GetFiles(Application.ExecutablePath, "*.xsd")) {
System.Diagnostics.Debug.WriteLine(file);
}
Webforms / MVC would require you to swap out Application.ExecutablePath for something else.
Also, you will need to set all .xsd files to "Copy to output directory" in their VS settings.
I am trying to write a small application, whose only purpose is to copy some folders and .cs source files into a user specified Directory, I can do it easy enough by simply having the application look for the files and folders in its own install directory then copy them to thier destination Directory, but I was wondering if its possible to Embed the Folders and Files into the Application, so that when you run the application it creates or copies the folders and files from the exe app directly to the install directory, rather than searching for them in the apps install directory then copying them over. Basically Im trying to only have a single exe file rather than having an exe file and a bunch of folders and files along side it.
Is this possible to do with just a Windows Form App without using an actual Installer Class?
Yes. Embed the files into the application executable as embedded resources. Then when your application runs, access the embedded files and write them to disk in the desired directory structure.
Here is an example of how to embed and access embedded resources from your application assembly.
http://support.microsoft.com/kb/319292
Sure you can, use the BuildAction property as Content or Resource.
Depending on the number and structure of files/folders, you may also consider embedding one zip file and extracting it with sharpziplib or some such.