By Default when we serialize an object to a json string format, it will use the object property name along with its case. I.e. if i have a property named "MyString" = "TestString" the json format will be
{"MyString":"TestString"} however sometimes we want to have the property name to be camel casing like
{"myString":"TestString"}
Here is how to do it:JsonConvert.SerializeObject(obj, Formatting.None,
new JsonSerializerSettings
{ContractResolver = new CamelCasePropertyNamesContractResolver()})
References:http://stackoverflow.com/questions/2789593/force-lowercase-property-names-from-json-in-asp-net-mvc
Thursday, April 28, 2011
JSON.Net Custom rule to serialize property
I faced a problem where I need to not serialize to Json a Property when the Property is either empty string or zero.
I have Json.Net library which can be download here http://json.codeplex.com/. Very robust library. I highly recommend using it when dealing with Json string.
Anyway, back to the issue, to solve this problem, we create a method on the class itself with the following prefix "ShouldSerialize" + "". So for example if the property name is MyString, the method would be like the following
public bool ShouldSerializeMyString()
{
return !string.IsNullOrEmpty(MyString);
}
References:
http://james.newtonking.com/
I have Json.Net library which can be download here http://json.codeplex.com/. Very robust library. I highly recommend using it when dealing with Json string.
Anyway, back to the issue, to solve this problem, we create a method on the class itself with the following prefix "ShouldSerialize" + "
public bool ShouldSerializeMyString()
{
return !string.IsNullOrEmpty(MyString);
}
References:
http://james.newtonking.com/
Tuesday, April 19, 2011
Sitecore Media Upload is not working for Safari or FF with Windows Authentication turned on
Recently, I have been spending time trying to figure out how to get Media Upload to work for Safari or FF when Windows Authentication is turned on IIS.
Safari or FF will ask for credential again when uploading files, even though you have entered the credential when you browse the website for the first time. When you enter the credential, Firefox will freeze while Safari will throw an error.
I have tried changing the config in Firefox by tweaking "network.automatic-ntlm-auth.trusted-uris". This setting can be shown by typing "about:config" in url bar. It still does not work.
I have then lodged a ticket with Sitecore support. Few days later they come back with a solution that is to enable "Anonymous" authentication in IIS for ‘/sitecore/shell/Applications/FlashUpload’ and ‘/sitecore/shell/Applications/Media’.
Safari or FF will ask for credential again when uploading files, even though you have entered the credential when you browse the website for the first time. When you enter the credential, Firefox will freeze while Safari will throw an error.
I have tried changing the config in Firefox by tweaking "network.automatic-ntlm-auth.trusted-uris". This setting can be shown by typing "about:config" in url bar. It still does not work.
I have then lodged a ticket with Sitecore support. Few days later they come back with a solution that is to enable "Anonymous" authentication in IIS for ‘/sitecore/shell/Applications/FlashUpload’ and ‘/sitecore/shell/Applications/Media’.
ASP:Repeater displaying different markup for the first item
There is a little trick i found here http://asp-net-whidbey.blogspot.com/2006/07/net-20-repeater-different-template-for.html that i think is really neat like to display different markup/html for the first item in the repeater.
<asp:placeholder runat="server" visible="<%# (Container.ItemIndex == 0) %>"%></asp:placeholder%>
Thursday, April 14, 2011
File Upload on Mac throwing an error
Today, I encountered an issue where uploading file on Mac is throwing "One or more files could not be uploaded. See the log for file for more details".
I investigated the issue, and it turns out to be enabling IIS "Windows Authentication" setting is the culprit. For some reason, file upload isnt working properly even though I have managed to Authenticate and login to Sitecore successfully.
Creating additional tab similar to "content" or "builder" tab
recently, I was asked to create additional tab similar to "content" or "builder" tab. Unfortunately there isnt much info on it. I managed to get the info needed to do this from my colleague, and here is field that govern the tabs.
Under Appearance Section (you will need to checked "standard fields" under view) look for "editor" or "editors" fields. Here you defined the controls that you want to display as the tab.
Subscribe to:
Posts (Atom)