Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i wanted to create single executable file with c#
with my database and application.I wanted to install that application in client machine which have no internet. how can i include my database into my executable file (.exe) to let the user in client machine save and retrieve information.
thank you
This is simplest with single-file databases like SQLite. Create the database, pack it up with one of the compression APIs, then include the result as a resource in your application. On startup when the application fails to find the SQLite database file it can unpack it from the resource, save it to disk, then carry on. From that point the user is working on a copy of the database on disk and can make whatever changes they like.
If you're using a proper SQL server of some sort it's a bit more difficult, but essentially the same idea. Gather the data into a format you can work with, compress it and bind into a resource. On startup if the database doesn't exist you create it with whatever scripts or EF code you need, then unpack the resource and load all the data into the database.
Of course if your database is very large then you'll have a lot of bloat in your application. Better to pack the application and any data it needs as separate files in a ZIP or similar, then distribute the ZIP file. User unpacks the ZIP file and runs your application, which finds everything it needs sitting in the folder it was unpacked to.
Honestly, I'd go with the ZIP file option unless you have a really good reason not to.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I need to write code that receives firmware update files from various sources (nothing is a given, not even the file extensions) and passes them up to the cloud so that our software can download them to individual machines.
As part of the process, the front end needs to give the users a richer experience, so I need to include information such as the version number, last time there was an approved update to the file, and some other info about who is responsible for the update.
I've been directed to pass the data in as "meta-data" so that we don't have to include two files and at this point that doesn't seem like a very viable option. I've been researching meta data all day. TagLib is only for media files. I can use Microsoft API Code Pack to read some attributes but it won't let me write anything.
The shell32 option looks like the only other possibility but I can't figure out how to write to it. I'm using C# code in VS 2019, currently .NET framework 4.6.1 but we are about to upgrade to 4.8, I think.
Is there a practical way to write a string value as meta-data into a file without knowing anything more about the file than what I could discover with c#?
If you don't want to provide additional files or locations with the meta information you can create a new single file which contains your meta data and the actual firmware update. Think of it as a ZIP file where you have the firmware update file and some other file with the meta information. This way you will have only one file you can send around, but it has all the information you will need at any later point.
You cannot change the firmware update file in any way, specially if you don't know how the file format is. It would most likely break the firmware update.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to write a Windows desktop app with C# that virtualizes a certain file system folder basically so that the app stores files in a folder and makes the file system see the files and sub folders in this folder as if they were files/sub folders in another folder somewhere else (the virtualized folder).
Can this be done with C#?
And can it be done without file access performance penalties?
I know some apps written in C++ that do this but I want to use C# (because more modern and I'm more familiar with it). Perhaps there are even some libs available for this? I only came across sharpfilesystem but - without having looked too deep into it yet - I'm not sure it can do what I'm looking for. I'm also not sure if file system virtualization is the right word used for what I want to do so please correct me if this is something else (symlinks, aliases are related).
The technology you are after is called Shell namespace extension (SNE). Unfortunately, there is no (supported) way of creating a managed SNE:
Microsoft recommends against writing managed in-process extensions to Windows Explorer or Windows Internet Explorer and does not consider them a supported scenario.
For your particular scenario, NTFS junction points might be good enough though.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm working on a project that needs to look at large amounts of data (~1TB) and copy it from drive A to drive B. It will be constantly run in the background (or tray) and run a check every XX hours/mins. At that time, it will check if there are any NEW files in drive A and copy them to drive B. If there are any files that were updated and newer then it will also copy and replace the files from A to B.
I'm not really sure where to start. Should I write this in Python or C# (maybe visual?)? If someone could give me some advice I would greatly appreciate it. Thanks!
EDIT:
Just wanted to give an update! I ended up using Robocopy, which is built into Windows. I moved away from Python and just created a small batch file that would check all of the files in drive A and compare to drive B. If anything was new or didn't exist, it copies it over. I then set up a task through Task Scheduler, also built into Windows. Works PERFECTLY in literally just 1 line of code in a batch file!
I was starting to look into building something like this myself. I was going to write it in c#, probably as a system service and then have it periodically scan for new files. It would then build checksums with either sha1 or md5. You can look here about how to generate an MD5 in c#. Here is some additional information talking about byte-for-byte vs checksum comparisons.
After it has its hash list, it can do a transfer of the files then do another hash on the destination to ensure it was written properly. I was going to just hang on to all the hashes and then when it rescans the directory it has something to compare to in order to see if a file was updated. Then it would just repeat the above.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need to backup a file located on a remote machine using C#.
For example: "\server1\docs\test.txt" needs to be copied or moved to "\server1\docs\backup\test.txt."
Question: When I use File.Copy, does that move the file from the server, to my machine, back to the server -- essentially round-tripping the file across the network?
I'd like to avoid round-tripping.
Details: Both machines are Windows OS's on the same Domain.
Note: I want you guys to know that I have searched all over for the answer to this question, however, I have found contradicting answers. I'd like to know definitively. Thank you for your time.
You should run this from the server in order to avoid round-tripping the data. Keep in mind that if the files you're trying to work on are located on the same hard drive, moving them will be faster than copying them.
Just looking at the source code of C# (http://referencesource.microsoft.com/#mscorlib/system/io/file.cs,4a0905e7dc32d77d) it seems that File.Copy calls Win32Native.CopyFile function. To be honest I don't know exactly what it does, I mean I never saw the code, but I guess there's no magic and it reads the bytes from the remote computer and writes to the other remote computer.
Edit
One alternative is to login into the remote server via powershell (you can invoke ps scripts via C#) and execute the command to copy to the 2nd machine.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I made a program that saves information on .dat files.
On each time the program is closed the old information is replaced by the new information.
When I open the program, it reads the information from the dat files.
I want to create a server that I will be able to upload the .dat files to it and on each Form_Close the old information will be deleted from the sever and the new information will be uploaded to the server.
When I open the program, I want it to delete the .dat files on the computer and replace them by the information from the server.
What is the best choise of service for that kind of problem ?
I thought maybe I should use Google Drive.
But I don't know if it's a good choise.
Thanks for helping.
You have tons of options here, which one is better depends on your project and goals, but all of them will work.
You can use cloud drives, like google drive, dropbox, amazon s3 and so on.
And there is 2 ways to use them.
Just File.Copy your file to the local folder and let cloud client deal with it.
Use cloud drive's API to upload file
You can buy an ftp/http hosting, or set up one of your own and upload files with c# FtpClient or HttpClient.
You can use WebDAV
You can copy your file to shared folder on the server.
You can write your own simple socket/http/ftp server. (with c# HttpListener for example)