How to Get SharePoint Page URL without SharePoint API

No.of Views2578
Bookmarked0 times
Downloads 
Votes0
By  André Lage   On  25 Oct 2011 08:10:04
Tag : SharePoint , Enterprise Content Management
The purpose of this article is going to explore that how to get the Home Page url in the SharePoint, but do not use the SharePoint API to implement it.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

The purpose of this article is going to explore that how to get the Home Page url in the SharePoint, but do not use the SharePoint API to implement it.I hope that you all are know that to get the url through the SharePoint API.

I was making a application to return all Sites and Sub-Site and the question came to my mind "What is the HomePage url for each Site?"

Scenario

You don't have access to Server SharePoint API and you need to get the Home Page for each SharePoint Site.When you list the Site Collection or Sub Sites on the SharePoint Site "can be using Out of the Box Web Services Webs.asmx" you will have something like this:

  • http://[site]
  • http://[site]/Sites/example1
  • http://[site]/Sites/example2
  • http://[site]/Sites/example3


But you don't have the Home Page url associated for each sub Site or Site Collection,For example if you use a normal SharePoint 2010 template the default page is,

http://[site]/SitePages/home.aspx

SharePoint 2007 Template was:

http://[site]/default.aspx

If you use Publishing Template you will have something like this

http://[site]/Pages/default.aspx

One way to manage the Home Page for each site is using SharePoint Designer 2010.

Image Loading

Since we cannot assume the same default homepage and Hard code url is not a good Solution we can use the .NET Framework to get the HomePage associate for each Site

C# Code

HttpWebRequest httpWebrequest;
HttpWebResponse httpWebresponse;

//Create a request for the SharePoint Site
httpWebrequest = (HttpWebRequest)WebRequest.Create("url site example, https://example/sites/example1");
 
//Associate the correct Credential to you SharePoint Site
CustomCredential.Add(new Uri("url site example, https://example/sites/example1"), "NTLM", new NetworkCredential("UserLogin", "Password", "Domain"));
//or you can assume the current local Credential to authenticate
CustomCredential.Add(new Uri("url site example, https://example/sites/example1"), "NTLM", System.Net.CredentialCache.DefaultCredentials);
 //If you don't have the credentials you will get error 401

// Assume the credentials to you request
httpWebrequest.Credentials = CustomCredential;  
httpWebresponse = (HttpWebResponse)httpWebrequest.GetResponse();

//Get the Homepage associate to "https://example/sites/example1"
String HomePage = httpWebresponse.ResponseUri.AbsoluteUri.ToString();
httpWebresponse.Close();

//Popup a message with the HomePage url
MessageBox.Show(HomePage);

For this example i create a application to list all Site Collection and Sub-Site and popup the HomePage of each one.

Image Loading

Hope you like and stay tuned with codegain to get more updates.Thank you for reading.

 
Sign Up to vote for this article
 
About Author
 
André Lage
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Portugal
Joined date-09 Jun 2010
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
    In this article, I'm going to explain how to create List of Definition in SharePoint 2010.The List Definition is brand new features in SharePoint 2010.
    Published Date : 22/Sep/2011
    Now its a time user need Rich User Interface with high level of interactivity that is easily possible with xhtml technologies
    Published Date : 21/Jun/2010
    Difference between MOSS and WSS
    Published Date : 16/Feb/2010
    In this article, I am going to give and walkthrough of how to define a custom Content type in MOSS or SharePoint.
    Published Date : 16/Feb/2010
    Recently I have involved in branding one of our clients sharepoint portal. As part of the branding process we needed to modify the application.master file, so even the layout pages will have the same look and feel. As part of the investigation, we come up with the best approach for doing this.
    Published Date : 05/Sep/2010
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top