var img = new Image();
  img.ImageUrl = Request.Url.AbsoluteUri + "~/_layouts/images/Cv.Knowit/pie-1-4.png";

I am getting to this site

wingtipserver/SitePages/ Generated%20Cv.aspx?WikiPageMode=Edit&InitialTabId=Ribbon.EditingTools. CPEditTab&VisibilityContext=WSSWikiPage

So the image will not display. What could be the problem? I am getting an incorrect image url.

How do I get the correct image url?


Remove the Request.Url.AbsoluteUri - that is the Uri of the page you're on, including the query string, presumably what you spit out there (the rest is probably being cut off because it's invalid).

~ is a special character in Asp.Net server controls which will get you the root of your application, which may be what you want, or perhaps you want ~site or ~sitecollection which SharePoint will treat specially. (Read more here)

|improve this answer|||||

Try to use SPContext.Current.Web.Url to get absolute url of current web.

|improve this answer|||||
  • i want the image to get from the root of my application, – Batistuta Apr 22 '13 at 14:16
  • i only get this url wingtipserver~/_layouts/images/Cv.Knowit/pie-1-4.png – Batistuta Apr 22 '13 at 14:17
  • if i only use @"~/_layouts/images/Cv.Knowit/pie-2-4.png"; i will get cannot find the url , that because i am trying to do Request.Url.AbsoluteUri my friend did exacly the same on his server its working but not on mine.. – Batistuta Apr 22 '13 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.