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 :)
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Vijay ChavanPosted Mar 1, 2013, 12:14 AM
Nice it's working, Thank's
Ravishankar SinghPosted Mar 31, 2011, 6:59 AM
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.. :)