Hosting A Page Inside A SharePoint Page

One of the tasks I had recently was to get not only a web page into a SharePoint page but also pass in parameters from the Query String. Let’s say I am going to create the page at http://localhost/sharepoint/mypage.aspx in a normal way. In order to host a page inside that SharePoint page, we can use a Page Viewer Web Part, but this limits what can be done. Instead, we can create a custom web part to do the work…

Please excuse me if the code isn’t exactly correct. I do not have the code in front of me right now and will update it when I do.


1
2
3
4
5
6
7
8
9
10
11
12
13
public class CustomWebPart : WebPart {
    public override void Render(HtmlTextWriter writer){
        string rawUrl = Context.Request.Url.OriginalString;
        int index = rawUrl.IndexOf("?");
 
        string query = String.Empty;
        if(index != -1) query = rawUrl.Substring(index);
 
        writer.Write(
            "<iframe src='http://localhost/sharepoint/myOtherPage.aspx" + query + "' width='100%' height='765px'/>"
        );
    }
}

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

WordPress Themes