I am developing a Sandbox solution for SharePoint Online 1 that receives an absolute URL as a configuration parameter:
Absolute URL example:
Due to the native limitations of Sandbox solutions, I am looking for a native C# way to encode an absolute URL in C# without using the HttpServerUtility class and related classes (without using SharePoint library dependencies or other classes that may not be available by the user). type of sandbox solution).
1 This version of SharePoint supports Add-ins and Sandbox solutions ("the latter is not supported by Microsoft since the introduction of Add-ins or also called Apps").
Native way in C#? You must be wrong, when you develop in SharePoint with C# it is no longer a native development since you are adding code and this is not native.
A native solution involves a minority of code, for example displaying a list via definitions (xml) and schemas (schemas), everything can be done fully declarative (definitions/schemas).
Now when you say that you are looking for a native way to encode the urls with C#, I assume that you mean to use the utilities that SharePoint provides at their best. So I recommend you and use SPEncode .
Here is an example of how to encode a url string:
The output would be:
http%3A%2F%2Fmsdn%2Emicrosoft%2Ecom
Here are all the methods you can use:
https://msdn.microsoft.com/es-es/library/office/microsoft.sharepoint.utilities.spencode_methods.aspx
To know more about the sandbox restrictions you can take a look here:
https://msdn.microsoft.com/en-us/library/office/ff872402(v=office.14).aspx#InsideSP14_Ch4_USR
There is always the alternative to do it manually :) DotNetFiddle
Departure:
If you need something that is part of the framework (and not use
HttpServerUtility
), you can useWebUtility
, which is part of the namespaceSystem.Net
(inSystem.dll
): https://msdn.microsoft.com/es-xl/library/system.net.webutility. aspx