Can we say ServerRelativeUrl is a decoded URL only?

Yuvraj Patil 361 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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,214 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,790 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,594 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 33,486 Reputation points Microsoft Vendor
    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