Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I created a game in C# XNA using simple file IO to handle saving game data, however this creates a problem when I package my game and have someone else run it. After a few tests, I found out the game could be run in Administrator, however would throw UnauhorizedAccessExceptions when not done so (And simply hang unresponsive when not caught). This does make sense to me, as I remember seeing this exception back when I was experimenting with the File IO.
I could simply catch the exception and do nothing with it, leaving the game itself responsive... but saving functionality non-working unless run with Admin privileges.
So my question is, is there a place I can save to that isn't user intrusive, but accessible without Administrator access? Is this even a matter of an accessible locations or something more? Is there any decent way around this at all? If I need to provide code or any more specifics please let me know.
Somewhere inside the user profile, for example AppData or My Documents.
Get the path to AppData as follows:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Documentation for Environment.GetFolderPath is here:
http://msdn.microsoft.com/en-gb/library/system.environment.getfolderpath.aspx
Where are you trying to save the files?
Depending on what you want to save, I would say saving to ApplicationData is a good bet.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I don't know if someone has already asked this simple question earlier as well. So, the question is I have a simple code test for one of my assignment, I want to use C# to solve the problem, and I am wondering if I build a new solution in C# with the main method to run the code within the solution, then it will contain probably an sln file and also csproj file and some other files as well. So will it be wise to submit the entire solution as zipping or upload in a repo for an assignment, or there are some other smarter ways to submit a code assignment while coding in visual studio in C#.
I don't want a logic or code for my assignment, I just expertise ideas I would say as I more of intermediate in .NET
TIA
I guess it depends on how your tutor is expecting / willing to receive it?
The modern (and arguably best in my opinion) way would be to push it to a repo. Otherwise you could go old school and zip up the whole folder structure (minus the bin and obj folders).
I think it's much better to keep code in one file.
You could try the Visual Studio Code editor to create one-file programs.
Or use the online C# compilers (.NET Fiddle, OnlineGDB). I personally use the online compilers, and then just store the code on my computer in *.cs files.
Just zip your whole project and upload it to the google drive. After uploading it into the drive you will get an option of sharing setting and through that you can feed the email id of the person whom you want to send it.. That link will be sent to that person and he/she can download it easily...
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 5 years ago.
Improve this question
This is more of a blanket question than specific, but in my case I have a program I was given, but unfortunately it's broken. (It worked before, which was a while ago)
The program is a C# WPF .exe, but I'm just learning programming and I have no clue how to fix it. I can view the code behind it, I think, when I decompile it (dotPeek, but it seems to be read only), but I've no clue how to edit and recompile the program to work just like previously. I tried googling but I wasn't sure what terms would answer this question and the ones I've used proved fruitless.
Tl;dr - how to modify programs (especially C# WPF .exe)
Incorporated comments from #PaulF:
Programs don't tend to break of their own accord - beyond getting corrupted - if that is the case then decompiling wont work. So you need to understand why it has stopped working - it is likely that a decompile & recompile will not work. What has changed from when it worked to when it stopped working (maybe operating system version or PC)? Can you go back to a state where it was working ?
If that's not the issue, then:
Do you have access to the source code? If not, you cannot make it work without re-writing it and re-deploying it, which isn't a bad thing. Then you would be able to have the source code and hopefully source control it.
dotPeek allows you to see decompiled code, but you cannot do anything to the file safely.
Those are about your only three options:
Figure out what dependencies/configurations have changed
Get the source and modify that
Re-write it
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 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 9 years ago.
Improve this question
I am programming in C# since half a year. I have made a database project. What I want to do is, now that my project is finished, I want that no one should be able to edit any of the code of my C# project. How can I make my C# project uneditable?
You can hide give out DLLs of the compiled code to others, which they could then use without being able to see / edit the source code.
You can't make code permanently read only / I can't think of a reason why you'd want to (since if you had a bug you'd need to edit this code). However if you put your code into source control (e.g. TFS (free for small teams at http://tfs.visualstudio.com)) you can have a copy of your code with a full change log, so even if someone changed it, you could pull back a version as of today which didn't include their changes.
Alternatively you can use file permissions to stop others from editting the code, or make the files read only if you're worried about accidentally updating the code - but you'd still be able to edit it by amending those permissions / removing the read only flag at a later date.
As others have indicated you cannot really make your code readonly. What you can do is sign your assemblies. Other people will still be able to read and change your code. But as long as you keep your private key private, they will not be able to create the same signed assembly.
This does require that all the assemblies you reference are signed as well and that you store your private key in a safe place. If someone else gets your key, he or she will be able to recreate your assemblies, if you loose your key you will not be able to recreate them.