Office365-REST-Python-Client
Office365-REST-Python-Client copied to clipboard
How to Access SharePoint metadata from folders and files - Modified and Modified by ?
Hi Team, How to pull below meta information from SharePoint ? Modified and Modified by , Created by
Regards, Ranganna Naik
disclaimer, I'm just of user of this amazing package..
I use the following function to return last-modified and file-size Note the file object that gets called from using "get_file_by_server_relative_path()" has this information as you'll see in function. you can go into terminal call file object with get_file_by_server_relative_path() and return all dimensions. for ex.
In: file = ctx.web.get_file_by_server_relative_path(file_url).get().execute_query() In: dir(file) Out: .... will be all property dimensions
def fileprops(ctx, file_url_list): """ file_url_list = ['/sites/.../test.xlsx'] """ # Run Adhoc Test filename_lastmodified = {} filename_size = {}
for file_url in file_url_list: file = ctx.web.get_file_by_server_relative_path(file_url).get().execute_query() datetime_object = datetime.datetime.strptime(file.time_last_modified, "%Y-%m-%dT%H:%M:%SZ") filename_lastmodified[file_url] = "jq_" + str(datetime_object) ### making my own Mark to TIMESTSAMP filename_size[file_url] = file.length
return [filename_lastmodified, filename_size]
disclaimer, I'm just of user of this amazing package..
I use the following function to return last-modified and file-size Note the file object that gets called from using "get_file_by_server_relative_path()" has this information as you'll see in function. you can go into terminal call file object with get_file_by_server_relative_path() and return all dimensions. for ex.
In: file = ctx.web.get_file_by_server_relative_path(file_url).get().execute_query() In: dir(file) Out: .... will be all property dimensions
def fileprops(ctx, file_url_list): """ file_url_list = ['/sites/.../test.xlsx'] """ # Run Adhoc Test filename_lastmodified = {} filename_size = {}
for file_url in file_url_list: file = ctx.web.get_file_by_server_relative_path(file_url).get().execute_query() datetime_object = datetime.datetime.strptime(file.time_last_modified, "%Y-%m-%dT%H:%M:%SZ") filename_lastmodified[file_url] = "jq_" + str(datetime_object) ### making my own Mark to TIMESTSAMP filename_size[file_url] = file.length
return [filename_lastmodified, filename_size]
Hi Thanks for the reply i wanted the information who created the file username or modified username details
docLibrary = ctx.web.lists.get_by_title("YourLibrary")
lineItems = docLibrary.get_items()
ctx.load(lineItems)
ctx.execute_query()
for lineItem in lineItems:
print(lineItem.properties['Modified'])
print(lineItem.properties['Created'])
print(lineItem.properties['AuthorId'])
print(lineItem.properties['EditorId'])
You'd then need to lookup the AuthorId / EditorId to find the name I expect. (I've not played with that myself).