ListItemのデフォルト表示フォームに絶対URLを入手してください
-
10-12-2019 - |
質問
ListItemの表示フォームの絶対URLを持つ必要があります - 現在私は次のようにしています:
これは私に正しいURLを取得します、意味> http://example.com/リスト/ workflowTasks / dispform.aspx?id= 1 。
しかしこれは、私のサイトコレクションがやや洗練されたホストURL、たとえば、 http://)の場合、これは失敗します。.com / sites / shistionsite / - 私のコードからの両方のメソッドは、 "/ sites / seckessite / part http://example.com/site/secondsite/sites/secondsite/lists/etc
解決
There are a couple of methods for this available in the object model without the need to handle the slashes etc yourself, one method using MakeFullUrl:
var fullUrl = item.ParentList.ParentWeb.Site.MakeFullUrl(item.ParentList.DefaultDisplayFormUrl);
Parameters
strUrl
Type: System.String
A string that specifies the server-relative URL.
Return value Type: System.String
A string that contains the full URL.
他のヒント
var parentWebUrl = item.ParentList.ParentWebUrl;
var displayFormUrl = item.ParentList.DefaultDisplayFormUrl;
var itemIdQuery = "?ID=" + item.ID;
var fullUrl = parentWeblUrl.EndWith('/') ? parentWebUrl + displayFormUrl + itemIdQuery :
parentWebUrl + "/" + displayFormUrl + itemIdQuery
Just shut down my VM and hence can't test but how about using something like SPContext.Current.Web.Url
in combination with SPList.DefaultDisplayFormUrl
. Note that SPWeb.Url
gets the absolute URL for the website.