1

We have added a content editor webpart to EditForm.aspx for document library. In the CEWP, there's a JS filed. We need to execute different code when a folder is getting edited (like renaming the folder) and when file metadata is edited.

How can we check if the currently opened item is a folder or a document in EditForm.aspx? We can use the ID field in the URL and check using REST API or CSOM but I would like to avoid server calls for efficiency purpose.

3

Use out of the box object WPQ1FormCtx or WPQ2FormCtx. I have seen former in SharePoint Online and the later in SP2013 on prem. The property you are interested in is WPQ1FormCtx.ItemAttributes.FsObjType. If it is 1, the the object being edited is Folder. Attaching the screenshot from my SharePoint tenant. Folder

You can also refere to this link. Here I had used WPQ2FormCtx in SP 2013

  • Thanks. I found another way to implement it. Posted another answer. But your approach seems to be better as it provides a few other details which developer might need in future. – Naveen Feb 6 '18 at 13:17
0

This is an alternative approach to Nadeem's answer.

When SharePoint opens the EditForm.aspx it sends the ContentTypeId in the URL parameters. From this article I was able to find out that ContentTypeId for folder starts with 0x0120. With that in hand I was able to check and code according to folder or a document.

  • 1
    Remember that user can still eidt the item/folder by having a Url upto .../EditForm.aspx?ID=5. In this case the Only parameter in the query string is ID of the item – Nadeem Yousuf Feb 6 '18 at 13:24

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.