locked
Iframe in Webpart RRS feed

  • Question

  • I would like to display a document (from document library) in a iframe in a web part. Can anyone please provide the full code for the same? I am not able to get all the members of the pageviewerwebpart and no clue why this is happening... Pls let me know if someone has any information on this.
    • Edited by Mike Walsh FIN Wednesday, December 16, 2009 12:52 PM "An early response will be very helpful." removed. Never put any kind of time pressure on other forum members. If in a hurry, ring MS Customer Support Services and pay
    Wednesday, December 16, 2009 12:34 PM

Answers

  • add Literal control to the Controls collection and put you HTML to it`s Text property
    Literal lit = new Literal();
    lit.ID = "lit";
    lit.Text = "<IFRAME ...";
    • Proposed as answer by Peter Holpar Wednesday, December 16, 2009 12:46 PM
    • Marked as answer by Mike Walsh FIN Wednesday, December 16, 2009 12:52 PM
    Wednesday, December 16, 2009 12:38 PM

All replies

  • add Literal control to the Controls collection and put you HTML to it`s Text property
    Literal lit = new Literal();
    lit.ID = "lit";
    lit.Text = "<IFRAME ...";
    • Proposed as answer by Peter Holpar Wednesday, December 16, 2009 12:46 PM
    • Marked as answer by Mike Walsh FIN Wednesday, December 16, 2009 12:52 PM
    Wednesday, December 16, 2009 12:38 PM
  • Thanks...I tried that...But it works fine only for PDF files. For excel and doc files, it shows the saveas dialog box which means it works like a download. Any other way????
    Wednesday, December 16, 2009 1:29 PM
  • Go to doclibs settings and check "display as webpage" in advanced settings.

    Make also sure your office integration is correctly set:

    http://support.microsoft.com/kb/162059/
    Wednesday, December 16, 2009 1:37 PM
  • It depends on your browser`s settings.
    If you want be sure that if will be shown in browser then you should create some page to ghost controls which can display this type of files.
    Wednesday, December 16, 2009 1:41 PM
  • I need customization. Actually, I am displaying the details of a document and that page is full of multiple sections and each section contains a web part to display document related stuffs.
    One of those sections should display the document  (kind of document preview). I am getting the URL through querystring and then I need to display the document (of any type like doc, xls etc) in that web part.
    So, need customization coding for that. Please help.

    Wednesday, December 16, 2009 1:43 PM
  • Jevgeni,
    Sorry..couldn't get it...could you pls elaborate? BTW, pls check my above reply and let me know, if you have any clue.
    Wednesday, December 16, 2009 1:46 PM
  • You need some third-part control which can display this kind of documents.
    This kind of control can be written only with client-side technologies like a Flash and Silverlight.

    Something like this:
    http://silverlightspy.com/blog/xps-in-silverlight-revisited/
    http://blogs.msdn.com/delay/archive/2007/05/22/lighting-up-the-xml-paper-specification-proof-of-concept-xps-reader-for-silverlight.aspx

    So you have more wider problem, than just using a IFRAME inside a WebPart
    Wednesday, December 16, 2009 2:00 PM
  • Are you sure that there is no way to show all kind of documents in an iframe in a web part?
    Wednesday, December 16, 2009 2:14 PM
  • "to show All kind of documents" in a browser will not work as each possible application must then be able to display it's data inside a browser. And I would really wonder whether a selfwritten CAD-programm should open within the IE ;o)


    Office-integration is another topic. For dsoing so please follow my steps mentioned above.
    Wednesday, December 16, 2009 2:21 PM
  • Markus, are you proposing to configure all client`s browsers??
    As I have already wrote it depends on browser`s configuration. If you want to display some types of documents in web part without dependence on Browser`s configuration, then you should use client-side control to render required type of document.
    Wednesday, December 16, 2009 2:54 PM
  • Jevgeni,

    it really depends on the OP situation. In a company's environment with central administrated PCs you could roll this out with the next custom service pack. Furthermore this KB-article relates AFAIR to Office 2000/2003, so perhaps "display as webpage" will already do the trick.
    Wednesday, December 16, 2009 3:00 PM
  • Markus,
    I tried the way you mentioned. However, we need a preview not the origional document...is there any way? Any javascript clue?

    Jevgeni,
    Dont we have any other way other than third-party tools?
    Thursday, December 17, 2009 10:56 AM
  • Yes, you have. :) You can develop this controls by yourself.
    Thursday, December 17, 2009 11:04 AM
  • Basbabdatta, no way, sorry.

    Either you find a third-party-tool or you develop a custom-control for doing so.
    Thursday, December 17, 2009 11:27 AM
  • Thanks to both of you for your quick responses. Could you please go through this http://www.codeproject.com/KB/aspnet/WebPartsQueryStrings.aspx and let me know in case anything comes positive...I created a content editor webpart to test this javascript. But no clue how to create the iframe in it. This is my last try.
    Thursday, December 17, 2009 12:24 PM
  • This works fine:
    Create a content editor webpart and put the following code in the source editor:
    <script type="text/javascript">
    //Call the Function Onload
    _spBodyOnLoadFunctionNames.push("ajaxviewer");

    function ajaxviewer()
    {
    //Url string in variable
    var qsParm = new Array();
    qsParm['document'] = null;
    qsParm['file_size'] = null;

    //Parse the QueryString
    var query = window.location.search.substring(1);
      var parms = query.split('&');
      for (var i=0; i<parms.length; i++)
       {
       var pos = parms[i].indexOf('=');
       if (pos > 0)
                           {
        var key = parms[i].substring(0,pos);
        var val = parms[i].substring(pos+1);
        qsParm[key] = val;
       }
       }

    //Get the Server Name Dynamically
    var actualUrl=window.location;
    actualUrl= "'"+actualUrl+"'";
    var serverPrefixPosition = actualUrl.indexOf("//");
    var urlWithoutServerPrefix = actualUrl.substring(serverPrefixPosition+2);
    var serverNamePosition = urlWithoutServerPrefix.indexOf("/");
    var serverName = urlWithoutServerPrefix.substring(0, serverNamePosition);

    //Create the iframe
    var menu1newHTML =  "<table cellspacing=0 cellpadding=0 border=0><tr><td><iframe src='http://" + serverName + "/_layouts/PageViewerFolder/index.aspx?document=" +qsParm['document'] + "'" + " width ='700' height='500'></iframe></td></tr></table>";

    //Create the innerHTML
    document.getElementById('testing').innerHTML = menu1newHTML;
    }
    </script>

    <!--Display the iframe in Div-->
    <div id ="testing"></div>

    Friday, December 18, 2009 12:52 PM