1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / metadata default value for datetime?

metadata default value for datetime?

4 posts, 0 answered
  1. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    04 Feb 2009
    Link to this post
    I am in the process of adding a new metadata field to the document and image library.  I need to keep track of when a particular document was first published.

    I have found numerous details on how to create the metadata and how to update the various screens so that this value can be edited once the document is uploaded.

    However, I am having trouble getting the 'defaultValue' to work when the document is first uploaded.  I have the following line in the web.config:

    <add key="Libraries.PublishDate" valueType="DateTime" visible="True" searchable="True" sortable="True" defaultValue="#Now" />

    However, when I upload a document, the PublishDate is always set to 1/1/0001.  It would be nice to set an initial date to 'today' and then let the user set it.  Having them modify from 1/1/1 is a bit ridiculous as they have to change the day, month and year.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Feb 2009
    Link to this post
    Hi michael,

    Thank you for using our services.

    The problem with the defaultValue of DataTime type metafield is a bug that will be sorted out in Sitefinity 3.6 Official release. Sitefinity 3.6 will be available for downloading till the end of the week.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    11 Feb 2009
    Link to this post
    Thanks for the reply.  Unfortunately, upgrading to 3.6 isn't really an option at this moment.  We are deploying to the customer site this week and upgrading the CMS is just too large of a risk.

    Do you have any approved work-arounds?

    Do you have a hot fix that would resolve this particular issue?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    12 Feb 2009
    Link to this post
    Hello michael,

    Here is a workaround to this issue.

    You should implement the solution in Application_Start event, Global.asax file:

    void Application_Start(object sender, EventArgs e)  
        { 
            Telerik.Libraries.LibraryManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(LibraryManager_Executing); 
        } 
     
        void LibraryManager_Executing(object sender, Telerik.ExecutingEventArgs e) 
        { 
           if (e.CommandName == "CreateContent" || e.CommandName == "UpdateContent"
            { 
                //take the IContent Item from the command arguments 
                Telerik.Cms.Engine.IContent cnt = e.CommandArguments as Telerik.Cms.Engine.IContent; 
                //chech if there is a content and if it belongs to the news provider 
                if (cnt != null && cnt.ProviderName == "Libraries"
                {
                    // if the value of our metafield is null we set new value
                    if (cnt.GetMetaData("PublishDate1") == null
                    { 
                        cnt.SetMetaData("PublishDate1", DateTime.Now); 
                    } 
                } 
            } 
        } 

    DataTime.Now will be set for every item, if there is no value entered during the item creation.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
4 posts, 0 answered