as a starter of c# (And honestly not really loving the visual express c# environment) I'm in need of a back-up function to finish off my program.
I have 4 xml files in the /Data folder (In my project's root)
Now, what I want to do is back these files up in a file-save sense.
When a user clicks the "Back-up 1.xml!" button I want the program to open a saveDialog which automatically saves a pre-defined XML file (/Data/1.xml), to wherever the user wants, under whatever name the user wants.
However, I just cannot get googled how to make c# preselect that file. I only get these plugins from MSDN (which isn't very usefull either)
Any help would be appreciated, thanks in advance!
It looks like you need to copy a file from one location to another one.
Here is another StackOverflow thread that looks similarly to yours:
Copy a File
Esentially, the only thing you need to do:
System.IO.File.Copy(oldPathAndName, newPathAndName);
You can get newPathAndName from user input. You know oldPathAndName already.
Related
I was always pretty impressed by those programs that you could install by executing one installer file, which would then extract all the other required files to run the actual program.
And even now im still wondering how you would code a program that extracts files that are literally still inside the program ( so not in some kind of zip) , i've seen tons of installers for games who have this. I need this cause I want to extract a file on the right moment without giving the person who uses the program the ability to delete the file before its extracted, this may seem vague, but I hope i've informed you enough.
I'm just going to say that building an installer is difficult.
I'd recommend using NSIS: http://nsis.sourceforge.net/Main_Page
As for creating a file the user can't access, create a temp file with the correct read/write permissions, extract the data to the temp file, then copy the file where it needs to go.
Extract happens without the user interfering, and copy protection is handled by the OS.
What about changing the build action for the file you want to hide to Embedded Resource, or something like that that compiles the file inside the dll/exe?
Executable program is just file, So you can append any data at you executables. (works for my c++ compiled program)
$ cat executables some_blob_data > new_executables
Since argv[0] of main() is name of your file, you can use this to acess data in this file itself (works for c or c++ and likley for other languages to)
A really simple way to do this is to use your archive tool or one of the dozens of already made installers. WinRar, WinZip and most others allow the creation of self extracting exe files. I know you've said that is not what you want but if you make sure to make it auto exec your installer app and remove all of the temporary files when you're done it really can be very fool proof and professional looking. Obviously, the various installer applications are able to do what you're wanting.
If you really want to do this yourself the easy solution is going to most likely be dependant on your IDE software and language. The generic answer is that you'll need a compression library which can accept a stream as input. Then you'll want to make your actual files into resources inside your installer app. At that point it's just a matter of telling the compression library to read from a stream which is pointed at the resource. How that is done varies greatly from language to language.
I am new to programming and want to write a simple program in C#. I will be using VS Express to compile my code.
Goal:
I want to write a program that will search within a directory for all files that were created by a particular author. (Author is found by right clicking the file, opening properties, selecting the details tab and there is a field called Author with a name next to it). If the Author is the specified author I'm searching for, then I want it to copy the file to a new folder.
The end goal will be that all files created by this particular author will be in one folder.
Is there an easy way to create this program using a windows forms application in VS express? I was thinking you click a button, a message box appears that you select the directory you want, then another message box appears and asks which author you want to search for. Then a third message box appears asking where you want to save the new folder to. then the program does everything else.
Any help pointing me in the correct direction to write a program like this, or providing code would be greatly apprecaited. thank you.
Check out this:
http://wiki.terrasynq.net/tutorials/c-add-and-edit-ntfs-custom-properties/
It shows how to use OleDocumentProperties to read and edit properties.
I am new to C# , i wrote one application its contain directories and some file , i dont want to edit these file from outside of the program or manually , plz tell me how to do that if u provide the code that will be very usefull.
Thx
There is no real way to protect from within the application. If you're storing these files on a file system, they will be accesible based on file system permissions. You could store information in a password protected database or something similiar in order to make it only accessible to the application.
Actually on second thought, you may be able to save these files within a resource bundle. I'm not sure if that is entirely protected though.
You can set the read only attribute. It is only a minor inconvenience to someone who wants to edit a file, but you haven't got much control over what a user does outside of your program. At least if a user clears the read only attribute and changes your file you can blame them for it.
System.IO.File.SetAttributes("path\\file", FileAttributes.ReadOnly)
Are you just reading from these files or writing to them? If you're just reading them, you might embed them as resources in your compiled output rather than keeping them as files on disk.
http://support.microsoft.com/kb/319292
We have to build an event registration website for our client in ASP.NET using C#.
One of the requirements is that the client wants to add new foreign languages to his website himself using en excel file. I know how to make a website multilingual in Visual Studio, but I have no idea how to generate a resource file based on an excel file in code.
I also noticed VS generates a second file called Resource.en.designer.cs but I can't find any documentation how to generate that file either.
btw, the enduser is anything but IT-related. He knows his way around excel though (obviously).
Any help is appreciated!
Yoeri
EDIT:
!Robert Levy Provided a good method!
HOW TO:
STEP 1:
Read the excel file (using an OleDBAdapter was the best method for me, as you can use column headers etc)
Write the language to a txt file in this format:
KEY=TRANSLATION
no spaces or anything else
STEP 2:
Locate ResGen.exe on your computer (it comes with Visual Studio, so look somewhere like c:\program files\visual studio\sdk... however I found it # C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe)
STEP 3:
Invoke the exe with Process.Start("resgen.exe")
hint: use ProcesStartInfo for easy argument and preferences settings
(STEP 4:)
Move the file to your desired location (I find the App_GlobalResources works perfectly)
STEP 5:
Set the user currentUIculture to your desired culture!
ResGen.exe will compile resource files for you. You could either get him to deliver text files in the format used by that tool or write your own code that extracts from excel to generate the text files. Then just invoke this EXE and deploy your newly generated resource DLL. I am assuming you already know how to read things from resource files and use the appropriate one based on user preference.
http://msdn.microsoft.com/en-us/library/ccec7sz1.aspx
This is probably one place where you would like to use resources from database rather than simple resx files. It would be easier just to populate database table(s) with Excel data than transforming it to standard resx file (it could be a problem in the future if MS decided to modify file format).
So I would suggest you to write your own ResourceReader which would load strings from database (it could load it directly from Excel as well, but for many reasons I wouldn't recommend this method).
You should ask your end-user if they really have to get another language 'on the fly' and how many languages they expect they are going to add.
Otherwise, e-mailing the Excel file to you and manually creating the resource file might be by far the cheapest solution....
I would like activity in my Visual C# 2008 Express to not appear in My Recent Documents (I use Windows XP). To clarify, when you open a solution or other file in Visual C#, a link to that solution or other file is added to "My Recent Documents". I would like that not to happen.
How can that be achieved?
I know there's a chance this question is better fit for one of SO's sister sites, but my best judgment was that it fits here...
Thanks
I know there is a away of stopping Windows from updating the list, but I don't believe there is a way to stop it from updating for certain file types.
I way you may be able to do it with is to use batch scripting.
cd "C:\Documents and Settings\PROFILE_NAME\Recent"
del *.<C# file extension or other project extensions>
...
del *.<C# file extension or other project extensions>
Create the file using Notepad and save it as <any name>.bat.
After you work with you C# project you just run this Batch script and it will remove all your evidence from your My Recent Documents folder.
NOTE: If you can't access the Recent folder (because it's hidden) try replacing Recent with My Recent Documents
Thanks
link textI've added this functionality to Visual Studio MRU editor.
The list of extensions is currently fixed, and it needs to be roughened out.
The new prelimenary executable can be downloaded here.
... and the Sources, in case you don't trust me ;)
(I'm not sure if I should keep the separate "save" handling - it was a good idea during testing, but otherwise is rather annoying).