Frage

Ich muss eine absolute URL eines Display-Formulars von ListItem haben - derzeit mache ich das folgende Weg:

auf http://example.com/ : generasacodicetagpre.

Dies bringt mir die richtige URL, dh http://example.com/Listen / Workflowtasks / dispform.aspx? Id= 1 .

Dies fehlschlägt jedoch, wenn meine Site-Kollektion auf einer etwas ausgefeilten Host-URL ist, z. B. http:// Beispiel.com / Sites / sekundite / - Beide Methoden von meinem Code geben die URL zurück, die die "/ Sites / Sekundenstände / Teil, also enden, mit http://example.com/siten/secondsite/sitts/secondsite/lists/etc ...

Wie kenne ich es auf zuverlässigere Weise?

War es hilfreich?

Lösung

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.

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top