Formula una domandaFormula una domanda
 

Con rispostaChanging file creation dates

  • venerdì 26 giugno 2009 18.44spazmospazmo Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hi! I've got a file archive with multiple views, each for a different month of the year (and files are sorted into these views by creation date). However, at the beginning, some files were uploaded at the same time, and have erroneous creation dates. I need to change these creation dates so that the files can be viewed properly. Note: I can't sit in front of the server, I can only administrate through SharePoint Designer, Visual Web Studio express or IE Browser.
     
    Any advice on how to do that? I couldn't find anything online.

    Thanks!

    Spaz

Risposte

  • sabato 4 luglio 2009 17.20Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    Hi Spazmo,

    C# is one (and maybe the most important) programming language that can one use when developing on the .NET Framework. It is not a script and you can use it both client and server side.

    Peter
    • Contrassegnato come rispostaspazmospazmo lunedì 6 luglio 2009 18.04
    •  

Tutte le risposte

  • venerdì 26 giugno 2009 19.43David Lozzi Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
  • venerdì 26 giugno 2009 20.36Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hi Spaz,

    "I can only administrate through SharePoint Designer, Visual Web Studio express or IE Browser."

    Then this question may be posted to the incorrect forum, as there is a separate one for administration:
    SharePoint - Setup, Upgrade, Administration and Operation
    http://social.msdn.microsoft.com/Forums/en-US/sharepointadmin/threads

    Can you create code that calls a SOAP web service from Visual Web Studio Express and do you have the knowledge and experience to do that?
    If yes, then you can try to update this field using the UpdateListItems() method (see http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx), but I am a little bit sceptic.

    Otherwise, it would be the best to get a person with direct access to the server and try the same with the SharePoint object model:
    Can we update the values of "Created By", "Modified By" columns in SharePoint lists ?
    http://blogs.msdn.com/sowmyancs/archive/2008/03/14/can-we-update-the-values-of-created-by-modified-by-columns-in-sharepoint-lists.aspx

    One thing you could do through standard SharePoint web based user interface is to add a new mandatory text field (let's call it Modified2) to your document library and set the default value of the field to be a calculated value (=[Modified]), and then modify the date in this field for the items it is required, and modify your views to use the Modified2 instead of Modified. The problem is that SharePoint does not behave like SQL server, adding a new required field with a default value does not affect existing items. For these items, the new field will be empty. Bad news. No more idea.

    Peter


  • venerdì 26 giugno 2009 22.51Steve.CurranMVPMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Contiene codice
    You are going to have to write some code using the object model and batch update the items you want to change the created date for. The created date is a read only field and it's readonly property must be set to false before updating. Below is some example code:

      public static void SetReadOnlyField()
            {
    
    
                using (SPSite site = new SPSite("http://basesmcdev2/sites/tester1/"))
                {
    
                    using (SPWeb web = site.OpenWeb())
                    {
    
                        try
                        {
                            SPDocumentLibrary spdocLib = (SPDocumentLibrary)web.Lists["tester2"];  
    
                            SPFieldDateTime spd = (SPFieldDateTime)spdocLib.Fields["Created"];
                            spd.ReadOnlyField = false;
                            spd.Update();
                            spdocLib.Update();
    
                            SPListItem myitem = spdocLib.Items.GetItemById(18);
                            object myval = myitem["Created"];
    
                            myitem["Created"] = DateTime.Parse("05/12/09");
                            myitem.Update();
                            spdocLib.Update();
    
                            spd.ReadOnlyField = true;
                            spd.Update();
                            spdocLib.Update();
    
                        }
                        catch (Exception ex)
                        {
                            string msg = ex.Message;
                        }
    
                    }
    
                }
    
            }
    

    certdev.com
  • sabato 27 giugno 2009 6.59Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Steve, David,

    It's all very nice in theory, but how can he apply that in practice if "I can't sit in front of the server, I can only administrate through SharePoint Designer, Visual Web Studio express or IE Browser."??

    Peter
  • sabato 27 giugno 2009 23.19Steve.CurranMVPMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    The issue here is the creation date not the "modified by" or "created by" fields. The creation date can only be modified by setting its ReadOnly property to false before you edit it. There is no web service which will do this, so you must execute some object model code to set this property. Once the ReadOnly property has been set to false for the creation date column it will show up in the SharePoint UI EditForm.aspx and you will be able to change the date from the "IE Browser", so its not theory and it satisfies one of the requirements of the question.

    Thanks.
    certdev.com
  • domenica 28 giugno 2009 7.39Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Steve,

    Sorry, but since he wrote he can't sit in front of computer (I assume no remote desktop connection or administrators' help to run such code on the server, as Spaz has not mentioned that, but it would be useful having a feedback about that from he) I still think it is theory in his case. If he had direct access to the computer, it would be very nice, of course.

    I see only a single requirement in the question: changing the creation date of the files given the condition "I can't sit in front of the server, I can only administrate through SharePoint Designer, Visual Web Studio express or IE Browser." I interpreted this as we can not use methods that rely on the object model, but I may be wrong in that. I'm really curious how would you achieve that without having a login session (either sitting in front of it, or using remote desktop) on the server? Of course, if you had once such access, and installed custom code (like custom web service or user interface), then you would be able to do it later remotely using your components...

    "The creation date can only be modified by setting its ReadOnly property to false before you edit it."
    In the article linked by David above, Steven Van de Craen wrote about setting Created, Created By, Modified, Modified By fields without setting ReadOnlyField property. I have not tried that out yet, but assume it works. I will check it soon. Of course, this solution also requires direct access to the server.

    Thanks!

    Peter
  • domenica 28 giugno 2009 13.31Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     

    Hi,

    I am back with the results.

    I've tried Steven Van de Craen's code, it works, of course I've changed the user name in his code to match my system. 

    I've also tried to set fields not to be read only. Based on checking the result, the change was successful (ReadOnlyField was false), but despite that first the fields are not displayed on the edit form of the document library, even after an IISRESET.

    I did it using the code below:
    SPField field = list.Fields["Modified"];
    field.ReadOnlyField = false;
    field.Update();
    // update list, just to be sure
    list.Update();

    Then I've tried setting field properties on the site collection level and pushing changes down (of course this method has the downside effecting all lists of the site collection):
    SPField field2 = web.Fields["Modified"];
    field2.ReadOnlyField = false;
    field2.Update(true);
    // update web, just to be sure
    web.Update();

    It was successful, but had effect only on document libraries but not for lists. After this I set back the field2.ReadOnlyField = true, but since that I am able to set field.ReadOnlyField = false also with success.

    Steve, how did you do that? What made I wrong?

    Thanks in advance!

    Peter

  • domenica 28 giugno 2009 22.17Steve.CurranMVPMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    SharePoint is strange. It appears the created date and the last modified date fields will only show up as editable in the EditForm.aspx for a document library and not a List. It could have something to do with the content type. Not sure but very strange.
    certdev.com
  • lunedì 29 giugno 2009 6.38Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    "SharePoint is strange."

    Absolutely agree in that. That is what makes it exciting to work with. And yes, sometimes frustrating. :-)

    As I wrote first it seemed to me not to work for document library either, but I might have made some mistakes there. Once I would have time I will check it with Reflector. Probably I have to check the ListFieldIterator again, one of my good old friends from the past weeks.

    It would be nice to know if this behavior is a bug or by design.

    Peter
  • lunedì 29 giugno 2009 13.43patharsh Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hi,

    Create a workflow in SharePoint Designer to change date of your field according to you,

    then run workflow in your site from IE. After changes are done, remove the workflow.


    Harsh Patel
  • lunedì 29 giugno 2009 15.58Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hi Harsh,

    Which built-in SPD activity can be used to change the Modified field? Also starting the activity and modifying a batch of items seems to me a bit of challange too (which items to update, where the new values come from, etc.).

    Peter
  • venerdì 3 luglio 2009 18.09spazmospazmo Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hi, Peter. Thanks for reiterating my point for me that I have no access to the server/computer. To answer your question I do not have access to Remote Desktop and since the client is the U.S. Federal Government it could take months to apply to receive the forms needed to get access to the request system to get an administrator to put me on his schedule of people to talk to.

    So basically, I have SharePoint Designer, Visual Studio Express and Internet Explorer.

    I notice you guys are discussing a C# script. Is this something I could put on the sharepoint server and run?

    Thanks!

    Spaz
  • venerdì 3 luglio 2009 18.10spazmospazmo Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hey, Harsh! It would be great if that were possible! Can you recommend how this is done?

    Thanks!

    Spazmo
  • sabato 4 luglio 2009 17.20Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    Hi Spazmo,

    C# is one (and maybe the most important) programming language that can one use when developing on the .NET Framework. It is not a script and you can use it both client and server side.

    Peter
    • Contrassegnato come rispostaspazmospazmo lunedì 6 luglio 2009 18.04
    •  
  • lunedì 6 luglio 2009 18.08spazmospazmo Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Good advice, Peter! Thanks for being vigilant in representing my limited access to the server in this thread.

    I'm going to devote some time to C# (I'm coming from the world of Linux and PHP, so this is all new to me).

    I decided that creating views based on creation date is too dificult, so I'm adding a month/date field that is mandatory information when files are uploaded.

    Should work out great.

    Thanks for the help, everyone!

    Spaz
  • lunedì 6 luglio 2009 19.03Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hi Spaz,

    Thanks for the feedback, and let us know if you still need help.

    Peter
  • sabato 10 ottobre 2009 2.54Peter Holpar Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    Hi Spaz,

    Maybe not ideal for you, as it requires an initial local access to the server to deploy the solution, but after that one can use the solution to modify list item system properties, like created by or modified date through standard SharePoint web user interface using the custom field I've created.

    You can read more about it in my blog here:
    Changing system properties for an item from the SharePoint user interface
    http://pholpar.spaces.live.com/blog/cns!2CD45589973F2849!200.entry

    Hope that helps someone.

    Peter