I have written in C# using the Client Object Model libraries (Microsoft.Sharepoint.Client) to create a hierarchy of lists containing a number of files, at various levels. In order to view all the files, I can Edit the View, and in the Folders section, change to Show all items without Folders.
Question is, is there way to do this programmatically? Currently the code creates a large number of sites, and to change the view manually for each would be a real pain.
You will want to update the Scope property of your View object to be Recursive (1) or RecursiveAll (2).
Recursive will give you all files (regardless of which folders they're in).
RecursiveAll will give you all files and folders (regardless of which folders they're in).
For example:
ClientContext clientContext = new ClientContext(siteUrl);
Web site = clientContext.Web;
List targetList = site.Lists.GetByTitle("My List");
View targetView = targetList.Views.GetByTitle("My View");
targetView.Scope = ViewScope.RecursiveAll;
targetView.Update();
clientContext.ExecuteQuery();
I want to search all files inside a root folder and its sub folders in Google Drive API using C#.
Suppose there is a root folder "A" which contains 5 files
and a sub folder named "B".
The sub folder "B" contains 4 files only.
Now I have to populate all the files inside the root folder(5 + 4 = 9 files).
Currently I'm populating files like-
FilesResource.ListRequest list = service.Files.List();
list.OrderBy = "createdDate";
list.MaxResults = 1000;
if (search != null)
{
list.Q = search;
}
FileList filesFeed = list.Execute();
If anyone has any idea please share.
Thanks.
I only have objective-C sample code for search all file and folder.
I use recursive way for search all file.
you can use file MIMEType for determine folder or file.
My goal is to check all files which are shared BY me (whetever type or permissions).
So I need to find files which I'm the owner and has Shared property set to true, so I wrote the following code:
var listRequest = driveService.Files.List();
listRequest.Q = "'me' in owners and shared = 'true'";
FileList fileList = listRequest.Execute();
foreach (var file in fileList.Items)
SharedByMe.Add(file);
but the part with "shared = 'true'" doesn't working. I found that custom properties can be put in query, but what about standard ones? Because downloading all files and then checking it, is obviously not an option.
(1)
I can list the files on a folder this way:
var parameters = new Dictionary<GetListParameters, string>();
parameters.Add(GetListParameters.Path, "folder1/"); // get items from this specific path
var containerItemList = connection.GetContainerItemList(Settings.ContainerName, parameters);
However, this:
parameters.Add(GetListParameters.Path, "/");
or this:
parameters.Add(GetListParameters.Path, "");
does not work.
How can I query the files on the root folder?
(2)
The code above returns the list of files in a folder.
How can I get the list of folders within a folder? I there any parameter I can set to get this list?
Note: I know that this is a 'flat' file system, similar to Amazon S3. However, both (cloudfiles and S3) provides a way to work with 'folder'. In S3 is easy. In cloudfiles (with the .net API) I could not find how to do this.
Any hint will be highly appreciated.
This has just been fixed with the latest push and closes issue #51 on github
Link to downloadable package
Hope this helps.
I am using XNA and I want to save files to Vista's "Saved Games" folder.
I can get similar special folders like My Documents with Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) but I cannot find an equivalent for the Saved Games folder. How do I get to this folder?
http://msdn.microsoft.com/en-us/library/bb200105.aspx#ID2EWD
Looks like you'll need to use Microsoft.Xna.Framework.Storage and the StorageLocation class to do what you need to.
Currently, the title location on a PC
is the folder where the executable
resides when it is run. Use the
TitleLocation property to access the
path.
User storage is in the My Documents
folder of the user who is currently
logged in, in the SavedGames folder. A
subfolder is created for each game
according to the titleName passed to
the OpenContainer method. When no
PlayerIndex is specified, content is
saved in the AllPlayers folder. When a
PlayerIndex is specified, the content
is saved in the Player1, Player2,
Player3, or Player4 folder, depending
on which PlayerIndex was passed to
BeginShowStorageDeviceSelector.
There is no special folder const for it so just use System Variables. According to this Wikipedia article Special Folders, the saved games folder is just:
Saved Games %USERPROFILE%\saved games Vista
So the code would be:
string sgPath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "saved games"));
...
EDIT: If, as per the comments, localization is an issue and as per your question you still want access to the Saved Games folder directly rather than using the API, then the following may be helpful.
Using RedGate reflector we can see that GetFolderPath is implemented as follows:
public static string GetFolderPath(SpecialFolder folder)
{
if (!Enum.IsDefined(typeof(SpecialFolder), folder))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GetResourceString("Arg_EnumIllegalVal"), new object[] { (int) folder }));
}
StringBuilder lpszPath = new StringBuilder(260);
Win32Native.SHGetFolderPath(IntPtr.Zero, (int) folder, IntPtr.Zero, 0, lpszPath);
string path = lpszPath.ToString();
new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
return path;
}
So maybe you think all i need is to create my own version of this method and pass it the folder id for Saved Games. That wont work. Those folder ids pre-Vista were actually CSIDLs. A list of them can be found here. Note the Note: however.
In releasing Vista, Microsoft replaced CLSIDLs with KNOWNFOLDERIDs. A list of KNOWNFOLDERIDs can be found here. And the Saved Games KNOWNFOLDERID is FOLDERID_SavedGames.
But you don't just pass the new const to the old, CLSIDL based, SHGetFolderPath Win32 function. As per this article, Known Folders, and as you might expect, there is a new function called SHGetKnownFolderPath to which you pass the new FOLDERID_SavedGames constant and that will return the path to the Saved Games folder in a localized form.
The easiest way I found to get the Saved Games path was to read the Registry value likes this:
var defaultPath = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "Saved Games");
var regKey = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders";
var regKeyValue = "{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}";
var regValue = (string) Registry.GetValue(regKey, regKeyValue, defaultPath);
I changed the location of my Saved Games via the Shell multiple times and the value of this key changed each time. I use the USERPROFILE/Saved Games as a default because I think that will work for the default circumstance where someone has never changed the location.