windows native copy multple file dialoge - c#

How to copy or move MULTIPLE files and show respective native file dialog ? like this:
Although I can copy multiple files using this code:
using Microsoft.VisualBasic.FileIO;
FileSystem.CopyFile("1.txt", "2.txt");
FileSystem.CopyFile("3.txt", "4.txt");
But it shows separately for each of files like:
I know there's already FileSystem.CopyDirectory(...). But I don't want to copy whole directory. I just want some files from directory to be copied without multiple prompts or separate progress.
I believe its possible. Because I seen that in team viewer and anydesk software.


How to add or use .docx template file as a resource or reference in c#?

Im trying to make a winapp that fills the document template file using the C# form and create a new .docx file. Where should i put the .docx file and how should i use it. I placed my template inside the Debug folder and load it like:
Im having a problem when using the executable because it doesnt seem to find the template.docx
It is possibly to have files copies into the Output Directory. This is a simple mater of setting the File up accordingly.
However, having data like this in the Programm directory is frowned upon. As of Windows XP, you are unlikely to get write access to those files anymore. So any form of changes would be blocked unless your programm runs with full Administrative Rights.
The intended place for such files are the SpecialFolders. On those you are guaranteed write rights to some degree. While you could still store the template in the programm directory to copy it there if needed, it might be better to use copy it to default user as part of hte setup process.
Of course Visual Studio loves to run code under rather odd user accounts. So I am not sure how far that works for testing.
You can store you word document directly in your assembly (juste copy past the file in your project).
Then you just copy it to windows temp folder before doing your own business. Just don't forget to delete the file in the temp folder when you are good because windows won't do it for you.
Dim fileLocation As String = Path.GetTempFileName()
Using newFile As Stream = New FileStream(fileLocation, FileMode.Create)
End Using

How to determine path of resource files on different computers? - C#

I am writing a simple game for my course work. The application contains many pictureboxes with no images inside them. I also have a directory with needed pictures in the Visual Studio project debug folder. I need to put the pictures' paths into an array in my program to then randomly insert them into pictureboxes.
The problem is I don't know how it would work on another computer, so I can't organize all the things. The game must be launched without using Visual Studio there, only exe file. Should I first make the installation setup of my unfinished program, or something like this, and then place the application with resources somewhere on disk to know where all my pictures would be on any computer? And then maybe I could determine the exact path where I would take all the pictures and put them into the array. Or vice versa... I'm totally confused with this.
Here what I use to fill the array:
string[] spritePaths = Directory.GetFiles(/*paths*/);
Is it possible for you to distribute the pictures in a folder with the .exe file? If so, you could use a relative path to get all of the pictures.
string[] spritePaths = Directory.GetFiles("pictureFolder");
As DangerZone suggests, you could also add your images as embedded resources.
Here are a few options:
Specify the path to the folder of images as a command line argument. Then you can launch it from CMD, or create a shortcut and specify the arguments there.
Add a TextBox for the user to enter the path to the images.
Add a browse button or menu button and allow the user to search for the folder using a dialog.
Use a predefined location, such as an images folder next to the exe.

Add Multiple Folders / Directories to a ZipFile

I am writing a backup program that requires predefined multiple folder(s) & single file(s) to be added to a single zip archive. I have had no issues adding a single folder using -ZipFile.CreateFromDirectory(string, string, c..level, bool(false))
However i am having a hard time adding multiple folders as there does not seem to be a way to update an archive or target two folders using the CreateFromDirectory method.
- Would be nice if there was an UpdateFromDirectory mehod!
I have been trying to stay away from third party libraries for no reason really, however as far as i have found none deal with multiple unrecursive folders.
I have tried just about everything other than writing my own code to recurse & add individually which i don't really want to do.
The program has several inputs that defines the folders / files to be zipped and depending on whether they are not null should add them to a single zip file regardless of whether they are a folder or file.
I guess my question is whether this is possible at all using the boxed libraries without custom recursing or even with a third party library without heavy mods... Not sure if i have made my question clear, sure you will all let me know if i have not.
From what I can tell using the ZipFile class you can only create and read. if you want to update you would need to create the whole zip again. [Source: ZipFile methods]
to target more than one folder you could arrange all the files and folders into one folder then zip the entire source without including the source folder. In most cases moving this files/folders isn't possible so I'd recommend looking into Symlinks within windows. I'd redirect to you [Issue with creating symbolic link to directory
You can create a "myFolder" folder and put in it all the folders you want found in the zipped folder. Then do ZipFile.CreateFromDirectory("myFolder", "name of zip file to create", CompressionLevel.Fastest, false, Encoding.UTF8). Overriding this IncludeBaseDirectory method to false allows this to be done.

Building own Installer for Game

I have made a game and wish to distribute it online. I have spent years playing around with many Installers (InstallWise, InstallShield, etc, etc, etc).
They are very complex, require time and in most cases, a decent amount of money. So I want to write my own Installer, that will install my game for the user.
My game is comprised of:
DLL files (these will go inside the Game's folder, inside Program Files.
The application file itself (a single .exe file).
I will also need to create a shortcut on the Desktop (if the user allows) which will launch the .exe in Program Files folder. I can already do this.
I know how to copy and write files to folders. What I am asking is, how do I "pack" the files into my installer file, so that I can give a user a single file to download, which will then "unpack" the game's files into the appropriate location?
I have asked this question 2 years ago on SO and was met with hostility; the person claimed that this is not possible - but incase they haven't noticed, 90% of installers are just a single file, which unpacks its contents into a directory/several directories. So I know it is possible.
The only way I can think of that I can get this to work is by going over each file that needs to be packed, and reading the bytes into the app and storing it into an embedded file. And when the app is run, it will look for embedded files/bytes and write those bytes to new files in the specified locations. Please correct me if I am wrong.
Any help will be greatly appreciated.
You will need to either save the bytes in your installer, which means that you will need a builder for the actual installer which will use CodeDom.
Or you can download the files from a server, which seems faster in this case.
You choose.
To do so i would use a Self-Extract Zip. this is an exe that will unpack itself with all necessary files then you set the after extract command to call and exe of yours which copy everything where you want and then create yourself link on desktop and such. not very difficult.
In the Self-Extract file you can also specify that the content is extracted in the temp folder of the computer allowing you to find stuff using environment special directory

Building Content in Winform XNA

I have successfully been able to build content into my winform using Winform Series 1 and Winform Series 2 but my question is, how do you get the content to be loaded back into the editor the next time you open it. The content, .xnb, file is currently being saved to a temp folder. Is there anyway to have the content be loaded back into the editor with out having to go and build each file again?
Could I just save it to the Content folder inside the bin/ folder and then look through that folder at the start up and look for .xnb files and just load them? or is there an easier way to this?
In the second WinForms sample there is a HTML readme file that describes how the application saves built content to a temporary directory and then deletes it when the program closes.
This is the important bit:
Depending on your application, you might prefer to always use the same temporary directory name, and never delete it. This will leave files lying around on your hard drive. The content build process is incremental. If your program tries to load the same content files that were already built during a previous run, you will not need to carry out any actual processing work. This can speed up loading times for programs such as level editors that are likely to want to load the same files each time they start up.
It says that deleting the temporary directory "is handled by ContentBuilder.DeleteTempDirectory, which is called by Dispose". So simply find the call to DeleteTempDirectory and remove it.
The readme file describes in more detail how the temporary directory is selected (and why). You could modify CreateTempDirectory to suit your application better. For example if your editor has "level" files, you might want to save your built content (.xnb files) in a subdirectory with the same name, next to your level, so that your game can easily open the built content.
Once your files are being kept between sessions - all you have to do is reload them. The two obvious ways are to store a list of the files that are open, and reload it next session. Or simply open everything that is in your output directory:
Here is some rough code to do the latter (assuming no subdirectories):
string folder = #"C:\TemporaryXNAFilesOrWhatever";
List<Texture2D> textures = new List<Texture2D>();
ContentManager content = new ContentManager(serviceProvider, folder);
string[] files = Directory.GetFiles(folder, "*.xnb");
foreach(string file in files)
string assetName = Path.GetFileNameWithoutExtension(file);