Sharepoint 2013 Client Object Model - How to set 'View all files' - c#

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();

Related

Getting files from Sharepoint using .Net

Good afternoon, I am using the Microsoft.SharePointOnline.CSOM library to work with Sharepoint. I have a code where I get a list called MyDoc like this:
using (var context = new ClientContext(url)
{
varweb = context.Web;
var list = web.Lists.GetByTitle("MyDocs");
}
Then I iterate through all the folders to find a folder with a suitable name and get files from there. With the help of file.ServerRelativeUrl I found out the link to the file on Sharepoint:
/MyDocs/Documents/Students/Homework/1lesson.pdf
How can I immediately access the Homework folder and download all the files from there without going through all the possible folders in the MyDocs sheet?
Instead of getting the list, just use the method GetFolderByServerRelativeUrl within the context.Web object
var folder = context.Web.GetFolderByServerRelativeUrl("/MyList/MyFolder");
context.Load(folder);
context.ExecuteQuery();

Drive API v3, C# - Folder Hierarchy

I've got an app that communicates with Drive (specifically TeamDrives) and I need to pull a hierarchical folder structure within a given TeamDrive.
I can list my available TeamDrives then get the files (filter: folders mime type) within them but there doesn't seem to be any parent info to each folder so my structure is seemingly 'flat'.
I get that on Drive a folder is just a label and that 'sub-folders' could be shared in several places so I will cater for that but I just want to be able to create the directory tree on my app.
e.g. structure as I want to show it in my app:
Team Drive Name
Main Folder
Sub Folder
My 'list' code:
var request = service.Files.List();
request.Corpora = "teamDrive";
request.IncludeTeamDriveItems = true;
request.SupportsTeamDrives = true;
request.OrderBy = "name";
request.PageSize = 100;
request.TeamDriveId = "[teamDriveId]";
request.Q = "mimeType='application/vnd.google-apps.folder'";
This gives me for a given 'teamDriveId':
Main Folder
Sub Folder
parent on the Sub Folder result is null.
You haven't specified which fields you want in the response, so you are getting the default which doesn't include parent information. Try adding request.Fields = "*". I'm not familiar with the library you are using, so I might have the wrong syntax - please double check.
You might also find this useful In Google Apps Script, how would I get all subfolders and all subsubfolders and all subsubsub folders etc.?
As pinoyyid suggested you need to add 'Fields' to your request.
request.Fields = "name, id, parents";
https://developers.google.com/drive/api/v3/folder

Is there a way verify all Content files still exists?

I have a WPF application that uses too many images and videos to set the Build Action as Resource, so I'm using Content instead. Is there a way that I can dynamically search those files the application was compiled with so that I can verify that all the files still exists on the computer at runtime? I'd rather not write up a file list that I have to constantly update when adding, removing, or renaming content files. Thanks!
In order to find so called loose content files in the runtime you should use Reflection and look for instances of AssemblyAssociatedContentFileAttribute attribute. This attribute is added automatically during build process of WPF application for every file with Build Action = Content.
To sum up, you can verify if your files exist on the target computer during the application startup in the following way:
public App()
{
var a = Assembly.GetExecutingAssembly();
var attributes = a.GetCustomAttributes<AssemblyAssociatedContentFileAttribute>();
foreach (var attr in attributes)
{
var path = attr.RelativeContentFilePath;
//Verify if a given path exists
...
}
}

Rackspace CloudFiles C# API: How to list files on root 'folder', and how to list (sub)folders within a 'folder'?

(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.

How do I generate links in nested folders in T4 for ASP.NET MVC?

We are using T4MVC to generate for us links to our scripts and content. We've added a Script folders to some of our areas, and we want T4MVC to generate links for them as well.
We've tried to modify it to add it as an line to T4MVC.tt.settings.t4, but unfortunately with no success. The links for the Areas/Webcard/Scripts folder haven't been generated:
readonly string[] StaticFilesFolders = new string[] {
"Scripts",
"Content",
"App_Sprites",
"Areas/Webcard/Scripts"
};
How do I generate links for a new folder when I add a folder to each area?
It doesn't look like StaticFilesFolders supports/recognizes the path delimiter. It does however process items recursively, so you may want to try just adding "Areas" to the StaticFilesFolders list instead of "Areas/Webcard/Scripts". This should allow you to then access the scripts like #Links.Areas.Webcard.Scripts.Script1_js.

Categories