احصل على عنوان URL المطلق لنموذج العرض الافتراضي ل Listitem

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/89773

سؤال

أحتاج إلى وجود عنوان URL مطلق لنموذج عرض Listitem - حاليا، أفعل ذلك بالطريقة التالية:

على http://example.com/ : giveacodicetagpre.

هذا يجعلني عنوان URL الصحيح، وهذا يعني http://example.com/القوائم / WorkflowTasks / Dispform.aspx؟ ID= 1 .

ومع ذلك فشل هذا عندما يكون مجموعة موقعي على عنوان URL المضيف أكثر تطورا قليلا، على سبيل المثال http:// المثال.com / المواقع / الثينيت / - كلا الطريقتين من التعليمات البرمجية إرجاع عنوان URL الذي يحتوي على "/ المواقع / ثانية / جزء حتى ينتهي بك الأمر مع http://example.com/sites/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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top