Hi,
This is the problem with spaces and characters in SharePoint. You will have to replace them with the Ascii Hex codes (https://ascii.cl/htmlcodes.htm). In this case you are going to replace the # with %23.
Hope this helps.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
url = "xxxx.com"
site_url = url + "/xxxx/xxxx/xxxx"
def auth_api(user, pas):
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(user, pas)
ctx = ClientContext(siteurl, ctx_auth) # make sure you auth to the siteurl.
return ctx
def folder_check(user, pas, folder_path, folder_to_check):
try:
ctx = auth_api(user, pas)
libraryRoot = ctx.web.get_folder_by_server_relative_url(folder_path)
ctx.load(libraryRoot)
ctx.execute_query()
folders = libraryRoot.folders
ctx.load(folders)
ctx.execute_query() #Breaks here
for myfolder in folders:
if folder_to_check in myfolder.properties["ServerRelativeUrl"]:
return {'status': True,'message':'Folder Found'}
else:
continue
return {'status': False,'message':'Folder Not Found'}
except Exception as e:
return {'status': False,'message':str(e)}
folder_check('xxxxx', 'xxxx', "user # test", "test")
folder abc#123 contain folder test
but it is not printing test
Hi,
This is the problem with spaces and characters in SharePoint. You will have to replace them with the Ascii Hex codes (https://ascii.cl/htmlcodes.htm). In this case you are going to replace the # with %23.
Hope this helps.
Hi @Vinit Jain ,
In C#, we use ResourcePath
API to deal with special charaters, then use method Web.GetFolderByServerRelativePath(ResourcePath) instead of Web.GetFolderByServerRelativeUrl(String) to get the folder.
And this method is not available in python : https://github.com/vgrem/Office365-REST-Python-Client/blob/master/office365/sharepoint/webs/web.py
So, i think you may need to use the method get_folder_by_id()
to get the folder.
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.