I have a problem I can't copy the contents of a folder exactly, as these are normally altered during copying using the classic IO.File.Copy commands or with the My.Computer.FileSystem.CopyFile function by vb.net.
Is there a single file bit-to-bit copy method without altering file and folder attributes?
Related
I would like to modify the contents of a file placed in my project folder (Specifically "Assets/recentChanges.txt") at runtime. Let's say it contains information about recent changes in application. It is supposed to be read and bound to a textbox control, which later on can be edited by developers and saved back. The problem with content files is that they are copied to output directories and therefore I'm not editing the original file in Assets folder, but the one in bin/Debug/Assets/ folder. And the Embedded Resource build action is not an option since such files cannot be modified.
The question is: how can I modify mentioned .txt file in its original root/Assets/recentChanges.txt location during runtime? All of the below instructions point to similiar build-dependant path:
Environment.CurrentDirectory;
Assembly.GetExecutingAssembly().Location;
Or, in other words, what would be the correct approach for implementing "Recent Changes" section with following conditions:
based on text file in its original project location
possibilty to modify the file at runtime through UI
file copied to the output folder and visible to the user (through textbox) in published application
I am aware that it's probably not the perfect approach, because "recent changes" info could be collected from database or the .txt file could be modified manually and then copied to output locations... but nevertheless I think the issue is somewhat confusing and I would love some help. Thanks!
The compiled and running application doesn't know anything about some "original" location. This location is only important to Visual Studio when the application is built.
If you want to modify the file in this folder you should specify an absolute path to it, i.e. "c:\your_project_folder\file.txt".
The .exe cannot be supposed to know from where it was compiled
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.
I have some project what contains 3 dll libraries (one of them has 2 dependencies)
At the output folder of 'DLL parent' I need to have all source files of this 2 children. Moveover I want to save structure of this cs files by making 'cs' folder at output folder of DLL-parent, create subfolder with DLL-Child name there and copy all cs files of it to this folder.
For doing this I use post build events for DLL-Child.
And at bottom level when I build just this dll it works perfect.
After I set this command line at DLL-Child post build event it's output is created with folder with source files inside.
But when I build whole solution problem that this folder is not copied from output of DLL-Child to output of DLL-Parent.
Why ? At references section of DLL-Parent I set 'Copy local' to true for dependencies but it copies nothing.
Have your files be exported in separate folders per project. With this simple post build script (it's better to set it as post build event and select on successful build so as to not copy it each time but only when a build has been done properly)
copy "$(ProjectDir)FolderName\*" "PathYouWantYourFilesCopiedTo"
You can output all files from specific folder in your project.
You do not need checks for folders existing, VS does it on it's own. Create one build event for each folder of your files. If you have them in separate folders, nothing will overwrite nothing (as long as you maintain the folder structure in the output). And copy a whole folder is easier than copying file by file.
Basically what you need to do is to specify explicitly folder names for the output location. That will stop overwriting of files.
I'm building a class library which use a .dat file, inside the library i made a folder App_Data and put the .dat file inside it, how can i have my library to use the .dat file. How could it be included at the dll when build?
I already tried Path.GetFullPath, and almost anything in Path, but all i get is the path to debug folder, and in that folder i dont even have the .dat file which i expect to be included because the .dat file is in the project.
I just want to use that .dat file without hard coding its path, and it should still work when referenced.
You must right-click the .dat file and set Copy to Output Directory = Copy Always. Doing so, the path to the debug folder will correctly point to the file. No need to hard code the path.
If you're interested in embedding the .dat file in the DLL (a bit more work), you can go this way:
Can I embed other files in a DLL?
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.