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}
Related
I've been trying to learn how to handle saving normal .txt files in UWP, and have realized that it's quite locked down compared to WPF, especially in the sense of what folders you can access without requesting the user to select a location. I have searched for various ways this might be possible but found no working answer.
Question Description:
I basically would love to know if this is possible, and preferably a point in the direction where I can learn how exactly to do this.
Application settings page requires user to select folder where files are saved.
Application remembers this between launches (unsure if this is possible, but I can't require the user to select the folder on every launch)
Application saves files to the specified folder.
In my understanding, this should be possible, as the user is the one specifying the location via filepicker, but is it possible to have this work between launches so that the user wont be required to re-select the save folder?
I need to figure this out, as I would like my application to support selecting attached network drives, cloud storage folders, etc.
Any help is very much appreciated, and if there are any questions I will answer them to the best of my ability.
Fow this purpose there are two access lists designed: FutureAccessList and MostRecentlyUsedList. Once the user has picked up the folder with the picker, you add it to such list and receive a token, which you save for future purpose in LocalSettings:
ApplicationData.Current.LocalSettings.Values["MyFolder"] = StorageApplicationPermissions.FutureAccessList.Add(pickedFolder);
Then later, once you want to access that folder, you can do it like this:
StorageFolder folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(ApplicationData.Current.LocalSettings.Values["MyFolder"].ToString());
You can't save a StorageFolder or a path to it in settings, hence the UWP app needs permissions to access the folder. Using above access lists solves this problem.
I believe you want to save user settings and keep it somewhere so that next time when they launch the application, they can use the same settings.
Please check out this tutorial from Microsoft, which describes how to do exactly that.
https://msdn.microsoft.com/en-us/library/bb397750(v=vs.110).aspx
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.
Windows defines five folder types (general items, documents, pictures, music, and video). In Windows Explorer you can get/set the type by right-clicking on the folder and selecting Properties->Customize->Optimize this folder for. I'm looking for a way to get/set folder type in C#. I've searched for this, but I must not be using the correct terminology.
Can someone point me in the right direction?
Update: Thanks to all for the insights! Thought this would be simple - apparently NOT.
Very odd. I can select a folder with no desktop.ini. I can change the properties of that folder, select a folder type, click apply, see a desktop.ini is created, and see the folder view change accordingly. However, I can delete desktop.ini and the folder type persists. Through Explorer restart. Through Windows restart.
With regard to possible shadow copies, I can find no evidence to support this. Except for C:, system protection is turned off on all my drives. Using ShadowExplorer, I find no references to any desktop.ini files.
Puzzling...
I think you can either use a desktop ini file or the registry.
However, if you create a desktop.ini in a folder be sure to add the "System" attribute to that folder, otherwise the desktop.ini will be ignored.
attrib +s FolderName
(or with C# Code)
Link to MSDN http://msdn.microsoft.com/en-us/library/aa969337.aspx
Folder type is stored in desktop.ini file located in that folder (which has SYSTEM attribute and its not visible by default - you have to uncheck "Hide protected system files in Windows Explorer settings).
Example desktop.ini content from Windows 7 from folder set to "optimize for pictures" or whatever its called in english Windows.
[ViewState]
Mode=
Vid=
FolderType=Pictures
To change/read FolderType you can just change/read that file.
That file (desktop.ini) can contain more settings (like custom icon file/resource location). See desktop.ini in standard Documents or Desktop folder.
Edit/update according to comment:
Maybe that happends, because files with system attribute may have shadow copy and they will be restored after you delete them? I'm sure that there is no other place where this is stored.
Try to overwrite that file instead of deleting.
In Windows Registry there are only default settings applied when you create new folders.
Also I made some more digging, and found some information about WINAPI function that handles desktop.ini files "more properly".
See this:
Create Icons for Folders in Windows Explorer, Using C# by Evan Stone at codeproject.net
One more thing about customized folders without desktop.ini - I think this is impossible. Check that again and make sure, that you can see files with system attribute.
Edit 2:
Please take a look at SchlaWiener answer, he pointed at something important.
I downvoted his answer, but I was wrong, now I cant undo my vote.
Well, you want a direction, so.....
This is a link to a Microsoft document about the customization for folders...
How to modify your folder view settings or to customize a folder
In this article you will find a reference to a couple of Registry Subkeys and Keys.
Of course they are not the same in different Windows version (too easy)
WinXP, 2003
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell
HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam
Vista, Win7
HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell
Looking at the mentioned registry Keys and at the complexity behind these keys I really suggest to leave this work to the OS itself.
EDIT I have been hit in my self esteem by some rude comments below, so I have decided to search for a bit more documentation on this DESKTOP.INI file that seems to be a better option to solve your problem. I have found this documentation that seems to be very exaustive (but again it also demonstrates how handling correctly this little file is very complex) And by the way I have still to understand if just changing this file really makes a difference or not. As far as I have tried the test folder remains unchanged but this could be caused by some sort of caching.
My application creates several text files that contain important data for its working. I am grouping up all these files in a folder. In Form_load() I gave Directory.CreateDirectory("C:\\xyz"), so that a folder is created in a drive which will later include text files, when the application will be delivered to clients. I want to see that the user does not delete or rename the folder. A dialog box that shows some warning message will be helpful. Is it possible with Directory.CreateDirectory()?
I think you should just warn the user about the importance of this directory. However, you can recreate the directory by performing this kind of check :
if(!Directory.Exists(path))
Directory.CreateDirectory(path);
From this point, you can imagine a mecanism that save the important files in a temporary way, and if the directory is deleted, you recreate it and put the previously saved files in it.
First of all, you might find reading this helpful.
Second: If I understand your needs correctly, what you want is much more painful than you think.
You should really consider doing what Damien_The_Unbeliever told you.
However, if you insist: You will need to use C++ (C# will give you and your users a lot of pain) for it, and you will need to "hook" SHFileOperation through something like ICopyHook. Start by taking a look at ICopyHook. It will be a lot of work and a lot of learning, and I don't think it's worth it, but there's the info. Good luck.
I have recently been assigned a task which sounded relatively simple!
Upon attempting it became clear it wasn't as straight forward as i first imagined!!!
I am trying to download multiple files to one location on the users machine. They select these files from lists within a custom share-point web part. Thats the bit i have managed to get working! The downloading is done via WebClient (System.Net.WebClient)
I now want to allow the user to select a location on their local machine to download the files to.
I thought i would be able to use but after attempting this i realized i can only pick files :( in order to get the desired location which will confuse the user
I want something similar to the above but i only need it to return a path location like c:\Temp or any other location the user prefers on their local machine.
Could anyone suggest a control that could provide this functionality. It can also be a share-point control.
In the meantime I will be attempting Tree view as i have never used these before and these may have the power to do this from what i have read
Cheers
Truez
Clarity on language ASP.NET
Unfortunately, you can't do this without some kind of active content, like a Flash control or spit activeX /spit.
It seems strange at first, but you have to consider that this kind of functionality would let a site discover the structure of anyones storage devices; this is not 'a good thing'™
However, perhaps a different approach might solve the problem?
Why are you using WebClient, can't you provide the link to the client and let them choose their own download folder ?
I ended up zipping the files in to one folder and passed the file to be downloaded through the browser! Thanks for your comments!