How search for item in specific folder and get its properties with sharepoint online REST API? - rest

I have to search in specific subfolder on sharepoint online for file with title.
Right now I am using the following call
/_api/web/lists/getByTitle('MyDoc3')/items?$select=FileRef&$filter=substringof(%27test2.docx%27,FileRef)
But here I am passing a list title to get the file ref as output. How can I search in specific folder by url and get the same output as above call?

You can use Regular Expressions to extract the list name from the URL- and then use the list name in the above query

You could use below GetFolderByServerRelativeUrl endpoint to get specific libray folder by relative url like below and select the file server relative url which is the same as FileRef.
Below get the default Document library root folder:
https://tenant.sharepoint.com/sites/dev/_api/web/GetFolderByServerRelativeUrl('/sites/dev/Shared%20Documents')/files?$select=ServerRelativeUrl
Reference:
Working with folders and files with REST

Related

List of files and folders that don't require authentication

How can I get a list of shared files or folders that don't require you to authenticate to download the file etc, is there a specific attribute for the listed files and folders using "files_list_folder"
There isn't such a property on the entries returned by files_list_folder/files_list_folder_continue directly, but you can use files_get_temporary_link to get a temporary direct link to a file. The files_get_temporary_link call itself requires authorization, but the resulting link doesn't.

How to get version history of a file in folder in sharepoint using SharePoint REST API using c#?

I have a SharePoint library with a file in it. I need to get previous versions of the file who created it and when. What is the rest endpoint to fetch those details. I am new to SharePoint. Please help
You could use this rest endpoint to get previous versions of the file by the file id:
https://<server>/sites/<site>/_api/web/lists/getByTitle('Documents')/items(1)/versions
You could add filters at the end to get the information you need:
https://<server>/sites/<site>/_api/web/lists/getByTitle('Documents')/items(1)/versions?$select=VersionLabel,Created_x005f_x0020_x005f_By,Created
in order to get additional information from REST API request You need to use the $expand property. If You need information like who made the update please add '?$expand=CreatedBy' at the end of the request.. so for Your example it will be something like:
https:///sites//_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/general')/files('SampleDocFile.docx')/versions?$expand=CreatedBy
that way You will have the user who modified the file in
content>properties>Title
other interesting data is:
updated>
content>properties>CheckInComment>
content>properties>VersionLabel>

How to get a single file that has been shared with me on OneDrive?

I'm building an app that uses the ms-graph v1.0 API to write data to excelsheets in my OneDrive. It works with excel files that I uploaded to my drive but doesn't work with excel files that've been shared with me.
I know that I can get a list of all shared files with me/drive/sharedWithMe and the file that i want to edit is amongst the files that are being returned.
However, when i try to get one shared drive item using its driveItem property parentReference: driveID like this: /drives/{driveID}/items/{itemID} it returns : 403 - acces denied.
Here are my permissions:
"user.read",
"calendars.read",
"directory.accessasuser.all",
"files.readwrite.all"
I couldn't try the shares path /shares/{shareID} because I don't know how to figure out the shareId. It doesn't seem to be among the properties of the item that is returned by /sharedWithMe. Where can I get it?
Figured it out by myself.
I got the error
"message": "Cannot reference a user's drive from another user's personal site"
so I removed the me/from the route me/drives/{driveID}/items/{itemId} and it worked.

List folder contents of 'Shared with Me' folder from Office 365 OneDrive (Sharepoint) for Business and Education using the REST api?

Is there a way to get the contents of the 'Shared with Me' folder from the Office 365 (Sharepoint) REST api ?
I can't see anything in the api reference reagrding this.
https://msdn.microsoft.com/office/office365/APi/files-rest-operations
Found the solution to this...
Instead of using the files api you must use the sharepoint search api.
The following endpoint with the KQL query parameters can be used to get a list of files 'shared with me'
https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(SharedWithUsersOWSUSER:{UserAccountName} AND contentclass:STS_ListItem_MySiteDocumentLibrary)'
This above will get a list of files 'shared with me' but not anything inside a shared folder. To get the items inside a shared folder you can use the following endpoint.
https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(ParentLink:{ParentLink})'
Make sure the parent link is url encoded. You can retrieve the parent link from the folder properties.
Finally to get the account name used in the first request you can make a request to the sharepoint webs api.
https://{tenant}-my.sharepoint.com/_api/web/CurrentUser

Redirect to same named page in directory structure before path changes

Well, say I have a number of html pages in my web. The case is that I´m doing changes sometimes in the directory structure, so when anybody try to access to a determinated URL, it's possible that such URL does not exit. The files names don't change but so do the paths.
As far as I now, the server takes the user to a "404" page that can be customized. Is possible to customize the page in this way?:
The user tries oneweb.com/oldpath/page.html; which does not exist.
A 404 customized page is launched
404 page runs an script IS THIS POSSIBLE?
The script is given the name of the file WHERE IS STORED SUCH NAME?
The script search the entire directory structure to find page.html HOW TO ACCESS TO THE STRUCTURE
The file is found and the new URL is stored: oneweb.com/newpath/page.html
a link appears showing the new URL
Maybe this process is relatively common and I can find some related code or tutorial?
Are you using Apache? Linux?
Add a 404 handler
ErrorDocument 404 /404.php
Then use 404.php to parse the url. This simple example just grabs everything after the last / in the URI so http://example.com/foo/bar/page.html would put page.html in $url:
$url = end(explode('/', $_SERVER['REQUEST_URI']));
Then use one of the comment example functions in http://php.net/manual/en/function.readdir.php to search your directory and find the file.
Then do a header 301 redirect
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://example.com/' . $file_path);