Access File Properties and then copy files to folder (C#) - c#

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.

Related

How can I open a text file with my executable?

I want to right-click on a text file and "Open With..." it with my own program, but I can't find any information on how to do that. I want to make my program in C++ or with WinForms (C#).
I want to open that file and to use my program as an interpreter on a small "homemade programming language", so I want to pass the data from the file directly to my program.
Can anyone help me?
*hope I'm clear enough on what I'm trying to do.
I'm just gonna to answer your Question for C#. If you still need C++ support you can tell me.
Option 1 - Drop down:
So if you for example create a Console-Application in C# (Visual Studio), it will look like this:
As you can see in the Picture: the Program accepts Arguments (args String Array)
If you drag & drop your file on your .exe, the filepath of the file you dropped will be saved in the args String Array. Now you can read the file (for example with the File-Class).
Option 2 - Right Click -> Open with my Program:
For that, you can simply add a new entry in HKEY_CLASSES_ROOT\Directory\Background\shell (Windows Registry) to register you Program as a "Right Click Menu Program".
Here is a detailed How-To:
https://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/
After you added your Program to the Windows Registry you can proceed as shown in Option 1 (args).
Any more questions? Let me know.
Greets
Bennet
EDIT:
Sorry, didnt really read the comments :D but i guess your Question is answered. I will let this stay here for future readers which dont read the comments either ;)

Code Behind the "Add to My Drive" Button

I was wondering if anybody has had to write a program which moves a folder from "shared with me" to "My Drive". I am trying to do this, but cannot find any Google source code anywhere for moving files. There is code to cop the file, but I do not want to create a copy, I want to move the location of the file from the "Shared with me" folder to the "My Drive" folder. I do not have any ideas as I have looked and looked and looked without finding anything related to moving a file, and I also cannot post any code snippets as I have none. :(
EDIT: This is being done on a service account and being shared with thousands of users, so currently they would all need to authorize the app. We want to be able to share it with them and put it into their drive too. We tried briefly by giving them ownership, which worked, but giving them ownership is not an option.
So, the user will have the file shared with them, and then we want to put it directly into their drive for their convenience.
Shared with me, or in the new UI, 'Incoming' isn't really a folder - it is more a view of information shared with you. As such, you cannot 'Move' in the traditional sense, but you can definitely add it to my Drive.
It is really simply to do programmatically if you have the file ID you wish to add. Have a read of parents.insert for code. All you need to do is add 'root' as a parent of the folder you wish to add. root=My Drive.
.NET example. Note, just set folderId to "root".
Hope that helps!
"Add to My Drive" work by adding parent to the file. use drive.files.update, example request
PATCH https://www.googleapis.com/drive/v3/files/FILE_ID?addParents=PARENT_ID&key={YOUR_API_KEY}

Back-up my /Data folder in my c# project

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.

Resource Folder VS Resx File

First, please note I am a Java developer, started C# just few weeks back. Here is my question, it is about Visual Studio IDE.
I am using visual studio ide 2008 to create C# projects. I opened a new windows application, added a picture box to the form and now ready to add an image to it. I clicked the small black arrow button in picture box and it opens a dialog where we can put images.
Now, the question comes. In my c# book, they add images using the first option "Local Resource". Anyway, since I have to add number of images, I selected the "Project Resource File" and added all the images to the folder at once. Now I am working smooth without any issue. But, I can see the "Form.resx" file is empty (in my book, they show that file contains all the image files).
I want to know whether what I have done is correct or not. Even though that file is empty, no errors in the program anyway. I don't know whether any issue will occur after the distribution, like missing resources (In Java it normally happens unless otherwise you put all the resources into a new 'Package' inside the project. That's one of reasons I selected the second option when adding the images). Please help!
Your resources will be in a file called Resources.Resx (I think) this can found in your Properties folder in your project file
http://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.80).aspx This link has some information about using Resources
Its better to add the files to the project resource if your going to need them on multiple forms in the project. If they are only going to be required by the current form, you might as well put them in the forms resource file

How can I make an application open when a user double clicks on its associated file?

I am creating an application that uses a certain file format as its data source. I want this application to open whenever the user double clicks on this file, like how MS Word will open when a user double clicks on a Word document. How do I accomplish this? Also how would I populate the data fields using the file that the user selected. Would I use args[] from the program.cs class? I am using c# to code this application.
N.B. I want this association to be made when the application is installed on the host machine without the user doing anything.
FIRST, you need to set up file association, so that your file type is associated with your application and opening the file type will run your application.
You can do the file association programatically, there is some detail here as mentioned:
http://www.codeproject.com/KB/dotnet/System_File_Association.aspx
You can also do it via your Setup project for you application if you have one. This is an easier path for "newbies". Details for using visual studio to get the setup project to add the file association and also set the icon for the file are here:
http://www.dreamincode.net/forums/topic/58005-file-associations-in-visual-studio/
Otherwise if you use InnoSetup, Wix etc then I suppose you could just see instructions for those installers to create the association for you.
SECOND, you need to have your application accept command line arguments. The opened file(s) is(are) passed as a command line argument(s). You need to process the arguments to get the file path/name(s) and open the given file(s). There is a nice description of this here with code:
C# Command Line arguments problem in Release build
In your case, rather than MessageBox.Show(s) in the form shown handler, you would call your bespoke argument parsing method.
For a simple application which only accepts files names to open as arguments, this could be as simple as
foreach (string filePathName in Args)
DoNamedFileOpen(filePathName);
Your code can also have a method that might extract from the file the values for the datafields you are interested in etc.
This is a nice simple approach to the issue of have file associations set on installation of your application, with icons, and having your application handle the opening of those files.
Of course, there are plenty of other options, like run-time file association (asking the user if they want the association), detecting "broken" associations, etc.
This question is a long time here but I hope this is useful for new searches
See this. Or this if you want API information.
ClickOnce supports file associations as of .NET 3.5 SP1, too. In the project's properties, switch to the Publish tab and click the Options button. There's a File Associations section in that dialog that allows you to specify file extensions, descriptions and custom icons.
First, you have to associate the filetype extention with your executeable. On Windows you do this via the registry (search "filetype association windows"). In this question you find some interesting hints: Filetype association with application (C#) Script to associate an extension to a program
Your program has to react on the command line arguments or parameters. In Java, it is indeed the string array of the main method. I would gess, it's the same in C#.
If you don't need to do it pro programatically, right click on the icon, click open with ..., then select 'always use this program ...'.
This is something usually handled by your setup program .. I've used INNO setup for example, and it's trivially simple to arrange for it to adjust user's registry to launch your app when associated file extension is double clicked/opened. It'll even take care of MIME types for you as well as clearing these things on uninstall, which is a very nice thing to do
I managed to solve this issue. I used WIX to create an install file and asked it to associate the file with the application when it installs.

Categories

Resources