Sitecore 8 - Date issue

Jul 3, 2015 Posted by Lara Kannan 0 comments
In Sitecore 8, my due date column has the value like 2015-07-03 00:00:00. This date was displayed in UI as 2015-07-02 22:00:00+2.

The issue arises, because Sitecore have implemented a feature that tries to handle local time zones on the server. Old Sitecore 7.5 dates are stored without any timezone information

  • 20150412T000000
In Sitecore 8, Sitecore have changed the raw data format of the date field by taking the timezone into consideration. Which in my case means that my 2014-04-12 00:00:00 becomes 2015-04-11 22:00:00

  • 20150411T220000Z
Notice the “Z” at the end? This implies that this is a datetime that have a timezone, and the timezone is now 2 hours behind UTC.

To fix the old datetime fields, I need to tell Sitecore which timezone non-timezone-datetime fields have. This is the setting, ServerTimeZone:

<setting name="ServerTimeZone" value="UTC" />

I also needed to update the Lucene index, as the invalid datetime was added to the index as well.

Thanks to Peter Wind who helped find this issue.

Or else, use below method:
 DateTime dateShow = Sitecore.DateUtil.IsoDateToDateTime(showDate);        
 DateTime localDate = TimeZone.CurrentTimeZone.ToLocalTime(dateShow);   

Thanks!

Share
Labels:

How to get image URL from site-core via C#

Jul 2, 2015 Posted by Lara Kannan 0 comments
This is just a quick post to show how to get image URL via code behind C#.

This is mostly useful when you are binding children items to a repeater or returning image URL in a JSON web-service.

 public static string GetImageURL(Item currentItem)  
 {  
      string imageURL = string.Empty;  
      Sitecore.Data.Fields.ImageField imageField = currentItem.Fields["Image"];  
      if (imageField != null && imageField.MediaItem != null)  
      {  
       Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem);  
       imageURL = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image));  
      }  
 return imageURL;  
 }  


Special Thanks To : 


Share
Labels: ,

WP7 Tutorial : 04 - Know more about PhoneApplicationPage

Sep 13, 2012 Posted by Lara Kannan 0 comments

In our last post of the series, we learned about the base class "Page" and Here in this post we will learn about "PhoneApplicationPage" which is root of any Windows Phone 7 page.

Before jumping to the core in depth, a beginner must know all these things. As I am also exploring these for the first time, sharing the same knowledge with you.

I hope that, these series of posts will be helpful to a beginner. If you want to know more about PhoneApplicationPage class, read this post to learn about it.

What is PhoneApplicationPage?


PhoneApplicationPage is the root of any Windows Phone 7 XAML page. If you already worked on Silverlight, you must be aware of that by default "UserControl" is the root of any Silverlight XAML page. Similarly, Phone 7 XAML has the root named "PhoneApplicationPage".

As we described in our last post, every PhoneApplicationPage derives from "Page" which again derives from "UserControl". Hence, it is also nothing but a UserControl which has some additional features for Phone 7 application.

 
<phone:PhoneApplicationPage 
    x:Class="HelloWorldDemo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="True">


PhoneApplicationPage derives from Page class and can be found in Microsoft.Phone.Controls namespace. It has three Dependency Properties called "SupportedOrientations", "Orientation" and "ApplicationBar".

Have a look into the class meta data here:

 
namespace Microsoft.Phone.Controls
{
    public class PhoneApplicationPage : Page
    {
        public static readonly DependencyProperty SupportedOrientationsProperty;
        public static readonly DependencyProperty OrientationProperty;
        public static readonly DependencyProperty ApplicationBarProperty;
        public PhoneApplicationPage();
        public SupportedPageOrientation SupportedOrientations { get; set; }
 
        public PageOrientation Orientation { get; [EditorBrowsable(EditorBrowsableState.Never)]
        set; }
 
        public IApplicationBar ApplicationBar { get; set; }
        public IDictionary<string, object> State { get; }
        ~PhoneApplicationPage();
        protected virtual void OnOrientationChanged(OrientationChangedEventArgs e);
        protected virtual void OnBackKeyPress(CancelEventArgs e);
        protected virtual void OnRemovedFromJournal(JournalEntryRemovedEventArgs e);
        public event EventHandler<OrientationChangedEventArgs> BeginLayoutChanged;
        public event EventHandler<OrientationChangedEventArgs> OrientationChanged;
        public event EventHandler<CancelEventArgs> BackKeyPress;
    }
}


Let's discuss about the three properties available in PhoneApplicationPage.

What is SupportedPageOrientation?


SupportedPageOrientations is a Dependency Property of enum type SupportedPageOrientation, present in the Microsoft.Phone.Controls namespace and contains three enum values called "Portrait", "Landscape" and "PortraitOrLandscape".

It defines the property value to define the orientation supported by the application. If you define Portrait orientation your application will support only Portrait view, if declared as Landscape your application will support both left and right landscape view. The third property value defines that your application will support both Portrait and Landscape views.

 
namespace Microsoft.Phone.Controls
{
    public enum SupportedPageOrientation
    {
        Portrait = 1,
        Landscape = 2,
        PortraitOrLandscape = 3,
    }
}

What is PageOrientation?


PageOrientation is also a dependency property present in the Microsoft.Phone.Controls namespace. It defines the possible orientation of a Windows Phone 7 page.

 
namespace Microsoft.Phone.Controls
{
    public enum PageOrientation
    {
        None = 0,
        Portrait = 1,
        Landscape = 2,
        PortraitUp = 5,
        PortraitDown = 9,
        LandscapeLeft = 18,
        LandscapeRight = 34,
    }
}

From the meta data of the PageOrientation enum, you can easily understand about the property values. Use Portrait or Landscape property value to check the orientation of your application. According to the MSDN Documentation, if you want to check LandscapeLeft or LandscapeRight for Landscape orientation, check both of them and never check only left or right.

What is ApplicationBar?


This is a dependency property of type IApplicationBar which derives by the ApplicationBar class. It allows developers to create and display an application bar with 1-4 buttons and a set of text menu items for your Windows Phone application. IApplicationBar interface is part of Microsoft.Phone.Shell namespace and defines few properties as mentioned below:

 
namespace Microsoft.Phone.Shell
{
    public interface IApplicationBar
    {
        bool IsVisible { get; set; }
        double Opacity { get; set; }
        bool IsMenuEnabled { get; set; }
        Color BackgroundColor { get; set; }
        Color ForegroundColor { get; set; }
        IList Buttons { get; }
        IList MenuItems { get; }
        event EventHandler<ApplicationBarStateChangedEventArgs> StateChanged;
    }
}

Hope, this information helped you to learn about the PhoneApplicationPage. We will see the implementation of it in our next post. Till then enjoy coding.


Source : www.kunal-chowdhury.com/

Hope, this will help you to understand the basics of Windows Phone 7 Programming!

Share