1

I have a script going through all Web.Lists and List.Items in given site collection. On one point i want to have a full link to the item that is being processed. I'm doing it this way:

$ItemURL = $List.ParentWeb.Url + "/" + $List.RootFolder.Url + "/dispform.aspx?id=" + $Item.Id

It works on all lists, but not on libraries due to lacking /Forms/ after library name. Any idea how can i modify it to work also on libraries? Adding "/Forms/" strictly to the line of code will break link for lists.

2
  • string itemUrl = String.Format("{0}/{1}?ID={2}", properties.Web.Url, properties.List.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url, properties.ListItem.ID); convert this to powershell Commented Oct 25, 2017 at 9:04
  • OR var fullUrl = item.ParentList.ParentWeb.Site.MakeFullUrl(item.ParentList.DefaultDisplayFormUrl) + "?ID=" + item.ID; convert this to powershell Commented Oct 25, 2017 at 9:25

3 Answers 3

2

You can check for base type of the list type and handle it accordingly. If the base type is "DocumentLibrary" the you can have item url adding "Forms/" and else will be your list item url like below

if($List.BaseTemplate -eq "DocumentLibrary"){
 $ItemURL = $List.ParentWeb.Url + "/" + $List.RootFolder.Url + "/Forms/dispform.aspx?id=" + $Item.Id
}else{
 $ItemURL = $List.ParentWeb.Url + "/" + $List.RootFolder.Url + "/dispform.aspx?id=" + $Item.Id
}

Hope it helps you.

0
1

Try with List TemplateID

https://fcsharepoint.com/2015/08/19/sharepoint-2013-base-types-list-template-and-definition-ids-and-content-types-ids/

   if($List.TemplateID -eq "101"){
    $ItemURL = $List.ParentWeb.Url + "/" + $List.RootFolder.Url + "/Forms/dispform.aspx?id=" + $Item.Id
    }
    else{
    $ItemURL = $List.ParentWeb.Url + "/" + $List.RootFolder.Url + "/dispform.aspx?id=" + $Item.Id
    }
1

You should use the SPList.DefaultDisplayFormUr instead of assuming that it's /(Forms/)?displayform.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.