Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm not looking for the solution using SPContext & so. I tried it but I can't get URLs like:
http://mypage.com/testblog/Lists/Posts/Post.aspx?ID=1 )
thanks george

ps: I forgot to mention that this is about a MS Sharepoint 2010 Visual Webpart and I'm programming in C#

share|improve this question
    
What is the context of your situation, are you in an ItemEventReceiver, WebPart, DataViewWebPart, etc? –  James Love Sep 28 '10 at 14:25
    
Visual WebPart! and I'm looking for a solution in C#... –  Anonymous Sep 28 '10 at 16:22

4 Answers 4

this.Page.Request.URL should give you the URL of the current HTTP request.

share|improve this answer
    
thank you so much! that's perfect & so simple! this.Page.Request.URL.AbsoluteUri works all the time & It's way less complicated than working with SPContext & stuff! cheers george –  Anonymous Sep 29 '10 at 8:30
    
No problem, you're welcome. –  Flo Sep 29 '10 at 8:45
    
FYI - This property can be used by all ASP.NET pages, not just SharePoint pages. –  Russell Oct 17 '12 at 1:59

For a C# solution you could use HttpRequest.Url, that may get you the full current URL, or otherwise get the Url property form SPContext.Current.

share|improve this answer

You could use jQuery to get the path and display it.

$(document).ready(function() { var pathname = window.location.pathname; });

share|improve this answer

Lori's answer will work, but if you haven't already loaded jQuery to do something else then it's probably just a waste of overhead to load it just for this purpose.

You can grab it with straight JavaScript:

var theURL = window.location.pathname;
share|improve this answer
    
Thanx, but I forgot to mention that I'm looking for a solution in C#. JavaScript is nice but I dont want to use it because of ActiveScripting(could be disabled in some browsers)... –  Anonymous Sep 28 '10 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.