質問する質問する
 

回答済みChanging file creation dates

  • 2009年6月26日 18:44spazmospazmo ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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

回答

  • 2009年7月4日 17:20Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み
    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

すべての返信

  • 2009年6月26日 19:43David Lozzi ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
  • 2009年6月26日 20:36Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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


  • 2009年6月26日 22:51Steve.CurranMVPユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     コードあり
    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
  • 2009年6月27日 6:59Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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
  • 2009年6月27日 23:19Steve.CurranMVPユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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
  • 2009年6月28日 7:39Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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
  • 2009年6月28日 13:31Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     

    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

  • 2009年6月28日 22:17Steve.CurranMVPユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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
  • 2009年6月29日 6:38Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    "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
  • 2009年6月29日 13:43patharsh ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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
  • 2009年6月29日 15:58Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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
  • 2009年7月3日 18:09spazmospazmo ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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
  • 2009年7月3日 18:10spazmospazmo ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hey, Harsh! It would be great if that were possible! Can you recommend how this is done?

    Thanks!

    Spazmo
  • 2009年7月4日 17:20Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み
    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
  • 2009年7月6日 18:08spazmospazmo ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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
  • 2009年7月6日 19:03Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hi Spaz,

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

    Peter
  • 2009年10月10日 2:54Peter Holpar ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    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