0

I have developed an enterprise wiki site collection inside my staging server , then I backup , restore the enterprise wiki inside my live server.

But currently the created data for my welcome page is equal to the date I have created it inside the staging server and not the date i have restore it inside the live server . and also the created by is “System Account ” as shown below.

enter image description here

So my question if there is a way to manually modify the "created" & and "Created by" to a custom values only for the welcome page ?

Thanks

EDIT

i tried the following code after i added , SPSecurity.RunWithElevatedPrivileges(delegate() :-

protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();

            using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists["Pages"];
                web.AllowUnsafeUpdates = true;
                foreach (SPListItem items in list.Items)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        items["Author"] = "Test Name";
                        items["Created"] = "01/08/2014 01:44 PM";
                        items.Update();
                    });

                }
                SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                list.Update();
                web.AllowUnsafeUpdates = false;
                    });

            }
        }

but this will raise the following error when i try to add the web part inside the page:-

Invalid data has been used to update the list item.The field you are trying to update may be read only

1

you can do this by code behind :

using (SPSite site = new SPSite(SPContext.Current.Site.URL))
        using (SPWeb web = site.OpenWeb())
        {
            SPList list = web.Lists["ListName"];
            web.AllowUnSafeUpdates = true;
            foreach (SPListItem items in list.Items)
            {
                items["Author"] = value;
                items["Created"] = value;
                items.SystemUpdate();
            }
            web.AllowUnSafeUpdates = false;
        }
  • can you explain your point in more details, where exactly i need to do so ? using the SharePoint designer ? – john Gu Sep 16 '14 at 12:55
  • 1
    right. but if you require a particular item to be updated you can even modify the code using itemID and change the values. – Hardik Kothari Sep 16 '14 at 13:53
  • 1
    easiest way you can use Client Obj Model and create a c# class file and update the list items. but creating visual web part would give you more control and on removing the web part the values won't change. – Hardik Kothari Sep 16 '14 at 14:33
  • 1
    for Created it must be data time format value like "10/09/2014 8:27 AM" or else in code you can select System.CurrentDateTime and for CreatedBy it should be the domain account UserName i.e:displayname – Hardik Kothari Sep 16 '14 at 15:04
  • 1
    create a visual web part(farm solution) – Hardik Kothari Sep 16 '14 at 15:57
0

Try adding the code in SPSecurity.RunWithElevatedProviledges delegate and also try working around items.update() and list.Update()

  • currently i have the code inside " protected override void OnInit(EventArgs e)", so should i move the code to another method? – john Gu Sep 16 '14 at 16:28
  • Better you can use button click event .so u can control the update – Hardik Kothari Sep 16 '14 at 16:30
  • but even if i use a button click what will this change ? – john Gu Sep 16 '14 at 16:39
  • Try using the same then np – Hardik Kothari Sep 16 '14 at 16:41
  • i got confused , which approach i should try ? – john Gu Sep 16 '14 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.