Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Does anybody know what is the usefulness of the SPHttpUtility.NoEncode method? It seems like it takes a string as parameters and returns it without any modification.

Is there a case where you can use this and I'm missing it?

share|improve this question
add comment

3 Answers

Looks like this function here just to have a stub for future use. Or probably vice versa, there was functionality some time agou, but after some refactoring it became obsolete :) I can also see 2 more overloads for it with (object) and (object, TextWriter) signatures. I would recommend to avoid these functions, they looks really strange.

share|improve this answer
    
I'm trying to understand the code for the BDC service aplications management pages in an effort to create a custom service application with the full features that you find on the OOTB. I saw this method used in some places. So I was wondering why would you write such code? :-) The stubs for future use seems to be a posibility. –  Emilian BALANESCU Apr 12 '11 at 19:01
add comment

The main reason for having that method is to force a developer on the SharePoint team that each string rendered to the client should be encoded. Or at least, the developer must have thought about whether the string should be encoded or not. Just returning the string does not put this knowledge in the code, however, having the developer call SPUtility.NoEncode makes it quite clear that the developer actually thought about the issue and decided that not-encoding the string is the best option.

share|improve this answer
add comment

Edit: You were the one who asked in SO? :-)

From Stackoverflow

The data in sharepoint that is markup content has to be encoded so that it can be passed around in xml without it breaking.

for example <a /> instead of "< a/ >" (without the spaces)

Therefore if you want to ouput the rendered instead of >a /< you use the NoEncode function to convert it to valid xml.

Hope that makes sense.

share|improve this answer
    
Can't see XML handling here ;) public static string NoEncode(string valueToEncode) { return valueToEncode; } –  Ivan Padabed Apr 12 '11 at 15:33
    
Shoban I know that this is what the documentation says this method does but when testing it doesn't do anything. :) –  Emilian BALANESCU Apr 12 '11 at 19:04
    
Strange! I did some testing too. I will do some more tests today and let me see if I find anything. –  Shoban Apr 13 '11 at 4:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.