question

johnjohn-0472 avatar image
0 Votes"
johnjohn-0472 asked MichaelHan-MSFT commented

How to pass the item Id to the ContentType.EditFormUrl

I have the following CSOM to change the "EditFormUrl" & "NewFormUrl" for a list's content type:-

 static void Main(string[] args)
         {
             //customer sites
             string siteUrl = "https://***.sharepoint.com/sites/Intranet/";
             string clientId = "***";
             string clientSecret = "***";
    
    
             using (ClientContext context = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientId, clientSecret))
    
             {
                 try
                 {
    
                     context.Load(context.Site);
                     context.ExecuteQuery();
    
                     var omsWeb = context.Site.RootWeb;
                     context.Load(omsWeb);
                     context.ExecuteQuery();
                     //query for the alert period
                     List customerliveorderlist = omsWeb.GetList(omsWeb.ServerRelativeUrl + "/lists/userfeedbacksystem/");
                        
                     context.Load(customerliveorderlist.ContentTypes);
                     context.ExecuteQuery();
                     foreach (var ct in customerliveorderlist.ContentTypes)
                     {
    
                         ct.EditFormUrl = "https://***.sharepoint.com/sites/Intranet/Lists/UserFeedbackSystem/EditForm.aspx";
                         ct.NewFormUrl = "https://***.sharepoint.com/sites/Intranet/Lists/UserFeedbackSystem/NewForm.aspx";
                         ct.Update(false);
                         context.ExecuteQuery();
    
                     }
    
                        
    
    
    
                 }

but i am not sure how i can pass the ID of the item to the ct.EditFormUrl ?
Thanks

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT commented

Hi @johnjohn-0472,

Per my test, we do not have to pass the ID of the item to the ct.EditFormUrl. Just use the EditForm.aspx would work. Besides, you need to make a bit change on your code, as the following.


 ct.NewFormUrl = "~site/Lists/UserFeedbackSystem/NewForm.aspx";
 ct.EditFormUrl = "~site/Lists/Lists/UserFeedbackSystem/EditForm.aspx";
 ct.Update(false);
 context.ExecuteQuery();


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MichaelHan-MSFT your code worked for me. but what is the differences between my code which did not work and your code?

0 Votes 0 ·

@johnjohn-0472 According to the documentation, the URLs you specify must be relative to the root location of the content type. So I think the urls you used in the code is not correct.


0 Votes 0 ·