Can we say ServerRelativeUrl is a decoded URL only?

Yuvraj Patil 441 Reputation points
2022-11-15T07:14:11.367+00:00

I am using CSOM with SharePoint online. I am working on a application where I need to support for # and % characters in file name/path. I read on below article that ResourcePath.FromDecodedUrl(string) expects only decoded URL and in case we use encoded URL then it wont work properly. I am using ServerRelativeUrl from File and Attachment CSOM objects to pass to ResourcePath.FromDecodedUrl(string). So can I say or be sure that ServerRelativeUrl will always be decoded URL only?

Or do I have to add some extra to code to make it sure and change? if yes then how?

Article : https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/supporting-and-in-file-and-folder-with-the-resourcepath-api

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} votes

Answer accepted by question author
  1. RaytheonXie_MSFT 40,496 Reputation points Microsoft External Staff
    2022-11-16T02:27:24.597+00:00

    Hi @Yuvraj Patil
    Per my test, I try to retrieve the ServerRelativeUrl by File.ServerRelativeUrl and get the following result return
    260707-image.png
    The result turns out to be decoded URL and encoded URL should be like following

    %2Fsites%2Fxiexin%2FCoding%2F%25%25%25%23%23%2FNew+Text+Document+%2812%29.txt  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.


    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.