2

I could achieve this i.e. creating a list's NewForm named CustomNewForm.aspx setting it as Default NewForm and editing it in advanced mode to add a script code which redirects to CustomForm.aspx Page using code
window.location.href = "/sites/<Site Collection Name>/SitePages/CustomForm.aspx"

Using SharePoint Designer but as per deployment is concerned I need to achieve this using Powershell only. Is there a way to do the above two steps using Powershell or is there a better solution to achieve the task of mainly to redirect to CustomForm Page (The CustomForm.aspx page has custom UI and consist of jsom code to create a new ListItem) for creating new item in the list and making it available on the click of New item button.

  • Do you want to redirect after item is saved? – ThinkB4Code Jun 19 '17 at 6:11
  • No before, actually at page load itself – Ashwin Kheta Jun 19 '17 at 6:13
  • searched for creating a list form using powershell didn't get relevant solutions – Ashwin Kheta Jun 19 '17 at 6:15
  • What is your environment SPO or SP on-prem? – ThinkB4Code Jun 19 '17 at 6:20
  • SPO environment – Ashwin Kheta Jun 19 '17 at 6:25
2

Use the following CSOM code to update the NewFormUrl property of the list item content type.

            ClientContext ctx = new ClientContext("http://spm:5002/sites/test");
            Web web = ctx.Web;
            List test = web.Lists.GetByTitle("TestList");
            ContentTypeCollection ct = test.ContentTypes;
            ctx.Load(ct);
            ctx.ExecuteQuery();

            ContentType item = ct.Where(x => x.Name.Equals("Item")).FirstOrDefault();
            Console.WriteLine(item.Name + ", " + item.Id + ", " + item.NewFormUrl);
            item.NewFormUrl = "SitePages/asd.aspx";
            item.Update(false);
            ctx.ExecuteQuery();

Now whenever you click on New Item it will open the desired page. Also note that item.Update(false); statement is going to update the content type. The false as function parameter used to not update the derived content type.

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.