Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a sharepoint 2010 workflow builded in VS2010, not by me, but some colleage. This workflow need to start manual by the user if he would like to copy a document from list X to list y. In list x there is a manual created content type with the field start date. This field is a date picker, where the user can select a date. Only the date will be selected, not the time. If you select the date from today you will see 10-1-2013 in this field.

If you start the workflow this document and content type field values will be copied to list y. In list y there is another content type.

The problem is that the start date field value is copied to a date time value, and also inclusive the time. You see now 1-10-2013 0:00:00. 2 problems!

  • Problem 1: format is not the same
  • Problem 2: you see now the date and time. I only selected the date in the first list.
  • Problem 3: i see in the manual created content type of list y, the start date field is a text field and not a date time field like in the content type from list x. This is not my biggest problem, because I only want to see the same date like I selected in list x.

Following code which copied the fields from list x to list y:

private void CopyItemToConcepten_Invoked(object sender, EventArgs e)
    {
        SPWeb web = workflowProperties.Web;
        SPListItem item = workflowProperties.Item;
        SPList targetList = web.Lists[Lists.Concepten];
        if (targetList == null)
        {
            throw new Exception("Workflow error: The list '" + Lists.Concepten + "' does not exist on the current web.");
        }

        SPFile targetFile = targetList.RootFolder.Files.Add(item.File.Name, item.File.OpenBinary(), false);
        foreach (SPField field in item.Fields)
        {
            if (!field.ReadOnlyField && field.InternalName != "Attachments")
            {
                targetFile.Item[field.InternalName] = item[field.InternalName];
            }
        }
        targetFile.Item.Properties["SourceUrl"] = item.Url;
        targetFile.Item.SystemUpdate();

        targetFileUrl = web.Url.EndsWith("/") ? workflowProperties.Web.Url + workflowProperties.Item.Url : workflowProperties.Web.Url + "/" + workflowProperties.Item.Url;
    }

Do I need explicit check if the field is a date field, and then do something with date format?? Or is there some better solution??

share|improve this question
I have fixed my own. I have changed the field from text to datetime in sharepoint. – KHA Jan 23 at 13:09
closing this as you resolved the problem by changing the field. – SPDoctor Jan 23 at 17:39

closed as too localized by SPDoctor Jan 23 at 17:39

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.