Hi friends,
Through this blog I just want to share my experince that how to recognize your current page or can get page detail for your current from sharepoint page library.
You need to use the below code:
char[] delimiters = new char[] { '\\', '?' };
string s = Page.Request.Path.ToString();
string[] words = s.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
int i = words[0].IndexOf("Pages/");
foreach (SPListItem uitem in SPContext.Current.Web.Lists["Pages"].Items)
{
if (uitem["FileLeafRef"].ToString().ToLower()==words[0].Substring(i + 6).ToLower())
{
//you code logic to get item value e.g uitem["Title"].ToString() etc
}
}
Explaination:
1.I am assuming my current page url is :http://sharepointHome:2012/Pages/Sample.aspx?id......(blahh blahh...with some query string).
2.Now define delimiter and string to get current page url:
char[] delimiters = new char[] { '\\', '?' };
and
string s = Page.Request.Path.ToString();
Output of s will be:
http://sharepointHome:2012/Pages/Sample.aspx?id......(blahh blahh...with some query string).
3.Create one string of array and use integer to get value for IndexOf .
string[] words = s.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
int i = words[0].IndexOf("Pages/");
Output of words[0].Substring(i + 6) :
"Sample.aspx" which is equal to SPContext.Current.Web.Lists["Pages"].Items["FileLeafRef"]
Hope you like this blog.It will reduce your extra effort.
Please post me if you have any doubt :)
How to get current Pages details in SharePoint2010 publishing site
This blog will help you understand the logic/trick to get current page details if you site is using publishing portal template i.e from your page library.


Vijay ChavanPosted Feb 28, 2013, 7:14 PM EST
Nice it's working, Thank's
Ravishankar SinghPosted Mar 31, 2011, 2:59 AM EDT
You can also try the below to get current pages value: SPContext.Current.Web.GetListItem(this.Page.Request.Url.AbsoluteUri).Name the below code will also provide you the detail of current pages.. :)