Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting (Public) Internet URL for the Sharepoint Portal Site

I have a custom infopath workflow which allows users to submit expesne reports. Whenever someone submits an expense report in the Forms Library the workflow is initiated. The workflow checks the weburl and using a generic method creates a link to point to the workflow item and sends this link in a mail to the submitter and approvers.

Now what i want to achieve is that i need a way to point to the workflow item using a public url so even if the user is submitting a request from intranet or internet the link will be pointing to the internet url and hence the users can open items from their mailbox using internet url when the intranet is not available.

So i guess in short i need a way to get the public url for a site. Also keeping in mind that site may be extended for internet with some security settings in place. What would be the easiest and most efficient way to do this.


2 Answers

Relative path of you Page or the Link will be same irrespective of the Zone from which the user access the Site. All you need to change in the URL is the host name part.

You can get the URL for any Zone with the Following code

SPContext.Current.Site.WebApplication.GetResponseUri(Microsoft.SharePoint.Administration.SPUrlZone.Default).AbsoluteUri
like image 150
Kusek Avatar answered Jan 01 '26 18:01

Kusek


You can make sure you always get URLs from a specific zone by creating a new SPSite object and specifying the zone for it in the constructor. In your case you could try with the Default zone (SharePoint uses URLs from this zone when sending emails for example) or the Internet zone. You have a small sample below:

using(SPSite site = new SPSite(currentSiteId, SPUrlZone.Default)
{
    string publicUrl = site.MakeFullUrl(serverRelativeUrl);
    // note that MakeFullUrl takes a server relative url not a site relative one
}
like image 22
Soda Avatar answered Jan 01 '26 17:01

Soda