1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Display Document within page

Display Document within page

34 posts, 0 answered
  1. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    14 Jan 2009
    Link to this post
    Hi, I am wondering if it is possible to isert a document in a page rather than have just a link being displaied which then takes you to a new instance of teh browser that displays the document. I want to create a page and insert the document in that page so that when i navigate to that page i can see the document rather than a link to the document. Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Jan 2009
    Link to this post
    Hi Andrei,

    You can do this only for templates. The simplest way is to use #include directive ( <!--#include file ="YOUR_FILE_HERE"-->.The last one will return plain text. Your file will not look as it looks if you use Word or other format. The other way is to use GenericContent control and paste your text there.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    14 Jan 2009
    Link to this post
    what do you mean only with templates? how do you do it in template. I tried it and it just adds the link. I am not sure what you mean.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Jan 2009
    Link to this post
    Hi Andrei,

    Check out the following url http://www.w3schools.com/asp/asp_incfiles.asp. You could use only plain text, Otherwise the formatting will be messed up. I suggest using the GenericContent control for this purposes. This is the easiest way to have some content on a page.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    14 Jan 2009
    Link to this post
    When you said "You can do this only for templates" I thought you meant there was a way of doing it without the "<!-- #include" way. The other way that I am thinking of doing it, is by having a user control with an <iframe> in it. Then link the iframe to the document. Will have to somehow invoke the panel that allows you to select documents from teh library. Need to find out what teh Editor is for that panel. Any more bright ideas are more than welcome, until then, thank you very much.

    Andrei
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    15 Jan 2009
    Link to this post
    Hello Andrei,

    I think that you may find the following article useful - iPaper.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    15 Jan 2009
    Link to this post

    Thanks, quite interesting, but not adequatly tested yet, I think. So I will stick to iFrames for now. I can make teh iFrame into a User Control (.ascx) and then drag and drop it on teh page.

    The only problem I have is the URI property. I can not find the correct editor to make a 'Select' button come that would allow me to link the iFrame src with a document in the library. This is what I use now:

     

    <Category(

    "Behavior"), UrlProperty("*.aspx"), Bindable(True), DefaultValue(""), _

     

    Editor(

    "System.Web.UI.Design.WebFormsRootDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", _

     

     

    GetType(Drawing.Design.UITypeEditor))> _

     

     

    Public Property URI() As String

     

     

     

     

     

    Get

     

     

     

     

     

    Return m_uri.NavigateUrl

     

     

    End Get

     

     

     

     

     

    Set(ByVal value As String)

     

    m_uri.NavigateUrl = value

     

    End Set

     

     

     

     

     

    End Property
    Which gives me teh Site map. What Editor do I use that will give me the Libraries, so that I can link the iFrame src with a document from the library. I am developing in Visual Studio and then loading the controls. I am not using any of the RAD namespaces or anything to do with Telerik.

     

  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    15 Jan 2009
    Link to this post
    Hello Andrei,

    Please check out blogs.sitefinity.com. There are two posts regarding selectors. There will be a new one in the next few days about pages, blogs, and newsletter subscriber lists.

    I hope this helps.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    15 Jan 2009
    Link to this post

    Hi Ivan,

    Thank you for the last post. I thought that was the answer that I was looking for but after trying what you are saying in the posts:

     

    <Category(

    "Behavior"), UrlProperty(), _

     

    Editor(

    "Telerik.Libraries.WebControls.DocumentsSelector", "Telerik.Libraries")> _

     

     

    Public Property URI() As String

     

     

     

     

     

    Get

     

     

     

     

     

    Return m_uri.NavigateUrl

     

     

    End Get

     

     

     

     

     

    Set(ByVal value As String)

     

    m_uri.NavigateUrl = value

     

    End Set

     

     

     

     

     

    End Property

    I am still getting the URI pop-up window with the Site Map of all the aspx pages. I am not getting the Libraries po-up window even though I am using the Documents Selector as you said. What am I missing?

    Thanks

    Andrei

     

  10. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    15 Jan 2009
    Link to this post
    Hi Ivan,

    I am not sure if you are still looking at my issue. I am aware that my trial license has expired. I have been evaluating Sitefinity to see if it meets our needs as a company before buying it. It looks like we are gonna buy it because it is very good. It meets our needs, but I can not get one feature going which is quite important.

    I want to embed PDF, DOC, etc files into pages so that if you navigate to the page then you can see the file, but I want to do it via iFrames. Now in order to do that I must link the iFrame with a document in the Databse. How do I make a Select button bring up the Library Interface which will give me the option to choose documents?

    <UrlProperty(), Editor(

    "System.Web.UI.WebControls.Image, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", _

     

     

    GetType(Drawing.Design.UITypeEditor))> _

     

     

    Public Property URI() As String

     

     

    Get

     

     

    Return doc_path

     

     

    End Get

     

     

    Set(ByVal value As String)

     

    doc_path = value

     

    End Set

     

     

    End Property

    The above property brings up the the File system up, but I want to choose documents that are stored in the database. All I need to know is what do I write inside Editor("?") that would give me the Documents from libaray. Please let me knwo if you have any idea. Sorry and Thank you.

    Andrei

     

  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 Jan 2009
    Link to this post
    Hello Andrei,

    Here is the selector that you need to put in the code behind of a control.

    [Category("Behavior")] 
    [WebEditor("Telerik.Libraries.WebControls.DocumentsSelector, Telerik.Libraries")] 
        public string SelectDoc 
        { 
            get 
            { return this.doc; } 
            set 
            { this.doc = value; } 
        } 
        private string doc; 

    I hope this helps.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  12. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    16 Jan 2009
    Link to this post
    Thanks Ivan,

    I got it working now. I had to switch to C# from VB. I am not very good with C# which made it a bit harder, but I got it working in the end.. Could not get it working in VB at all. I looked at your blog as well, it helped.

    Thanks again for all your help. Excellent support service!!!

    Andrei
  13. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    16 Jan 2009
    Link to this post
    Ivan,

    I forgot to mention. When the Documents Library comes up with the list of documents for me to select one, the documents are shown as a row of blank squares. So you are not sure which document you are choosing. When hovering over one the square changes colour, but still no tag name. Not sure if you understand what I mean, I hope you do.

    Thanks for all your help.

    Andrei
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Jan 2009
    Link to this post
    Hello Andrei,

    I forgot to mention. When the Documents Library comes up with the list of documents for me to select one, the documents are shown as a row of blank squares

    We will try to fix this issue. I replied to your the other post at our forum about this problem.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  15. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    11 May 2009
    Link to this post
    This is wonderful.  But simply, what do I put in the control (ascx) to view the document in the iFrame?  <iFrame .....> using C#?
    Thank you.
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 May 2009
    Link to this post
    Hello Laura,

    You should have iframe declaration in the control template

    <iframe id="frame1" runat="server"></iframe> 

    Then you can use docFrame.Attributes to set the value of the IContent item( document) you have selected.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  17. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    18 May 2009
    Link to this post
    Thank you!
    However:
    After selecting the file from the library, the link it is putting in is the sfref link (for example:  sfref="[Libraries]b4a95a1f-9fd2-4f1e-8503-2701e695b1ba" ) and not the href link (for example: href="/Libraries/My_PDFs/pdfdocumentname.sflb.ashx" )

    And of course it can not find the sfref link and so it errors. If I input    /Libraries/Atrium_Health_PDFs/med1-summ.sflb.ashx into the SelectDoc field in the edit properties window the selected file does display in the iFrame.

    How do I get it to use the href when selecting the file from the library?

    Thank you.
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 May 2009
    Link to this post
    Hello Laura,

    The [Libraries]b4a95a1f-9fd2-4f1e-8503-2701e695b1ba is a dynamic link. We added the dynamic links in Sitefinity 3.6

    You can try to convert the guid the the item url.

    Here is a sample code:

    WebEditor("Telerik.Libraries.WebControls.DocumentsSelector, Telerik.Libraries")]  
        public string DocumentUrl  
        {  
            get  
            {  
                return this.documentUrl;  
            }  
            set  
            {  
                this.documentUrl = value;  
            }  
        } 
    private string documentUrl;  

    private string GetUrl(string value)  
        {  
            // if our value starts with ~/   
            // we return url  
            if (value.StartsWith("~/"))  
                return this.ResolveUrl(value);  
      
              
            if (value.StartsWith("["))  
            {  
                int idx = value.IndexOf("]");  
                //getting the provider [Libraries]  
                string provider = value.Substring(1, idx - 1);  
                string strId = value.Substring(idx + 1);  
                Guid id = new Guid(strId);  
      
                if (ContentManager.Providers.ContainsKey(provider))  
                {  
                    IContent cnt = ContentManager.Providers[provider].GetContent(id);  
                    if (cnt != null)  
                        return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath);  
                }  
            }  
            return value.ToString();  
        }  


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  19. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    19 May 2009
    Link to this post
    Ivan,

    Brilliant explanation. Got it almost working. I add the resolved URL from the GetUrl method to my <iframe src="GetUrl(DocumentUrl)" />. When I load the page, the document from the library gets downloaded automatically but does not get displayed in the iFrame. I think the probalem is that it does not have the ~ at the start. It is a link and acts as if it is clicked. Downloads the document but does not display it.

    Any thoughts Ivan?

    Thank you again.

    Andrei
  20. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    19 May 2009
    Link to this post
    Ivan,

    Got it working. I was testing it in Google Chrome which was downloading the PDF rather than displaying it in the iFrame. Now I am testing it in IE8 and it seems to be working fine. In Firefox it goes bad as well. It seems that only IE displays the documents inside the iFrame properly. What a surprise!

    Thank you again for all your help. Brilliant support.

    Andrei
  21. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    19 May 2009
    Link to this post
    Thank you for everyones responses.  I hope you can help though. I am doing something wrong though that I am sure is a simple fix that I am not seeing. In my control on the page I get the IIS error page and the requested path it is looking for is
    http://www.websitename.com/PDFs/GetUrl(DocumentUrl)  with the GetUrl(DocumentUrl) instead of the resolved url.
    Thank you.

    this is the control:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="GenericIFrame.ascx.cs" Inherits="custom_controls_GenericIFrame" %> 
     
    <iframe runat="server" id="frame1" frameborder="0" width="980px" src="GetUrl(DocumentUrl)"  height="600px"></iframe> 

    this is the code behind:
    1 using System;  
    2 using System.Collections;  
    3 using System.Configuration;  
    4 using System.Data;  
    5 using System.Linq;  
    6 using System.Web;  
    7 using System.Web.Security;  
    8 using System.Web.UI;  
    9 using System.Web.UI.HtmlControls;  
    10 using System.Web.UI.WebControls;  
    11 using System.Web.UI.WebControls.WebParts;  
    12 using System.Xml.Linq;  
    13 using Telerik;  
    14 using Telerik.Cms.Web.UI;  
    15 using Telerik.Cms.Engine;  
    16  
    17 public partial class custom_controls_GenericIFrame : System.Web.UI.UserControl  
    18 {  
    19       
    20  protected void Page_Load(object sender, EventArgs e)  
    21     {  
    22       
    23     }  
    24     //document selector  
    25     [WebEditor("Telerik.Libraries.WebControls.DocumentsSelector, Telerik.Libraries")]      
    26     public string DocumentUrl      
    27     {      
    28         get        
    29         {      
    30             return this.documentUrl;       
    31         }      
    32         set        
    33         {      
    34             this.documentUrl = value;      
    35         }      
    36     }      
    37     private string documentUrl;        
    38  
    39     private string GetUrl(string value)        
    40     {      
    41         // if our value starts with ~/         
    42         // we return url       
    43         if (value.StartsWith("~/"))        
    44             return this.ResolveUrl(value);         
    45        
    46                
    47         if (value.StartsWith("["))         
    48         {      
    49             int idx = value.IndexOf("]");      
    50             //getting the provider [Libraries]         
    51             string provider = value.Substring(1, idx - 1);         
    52             string strId = value.Substring(idx + 1);       
    53             Guid id = new Guid(strId);         
    54        
    55             if (ContentManager.Providers.ContainsKey(provider))        
    56             {      
    57                 IContent cnt = ContentManager.Providers[provider].GetContent(id);      
    58                 if (cnt != null)       
    59                     return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath);      
    60             }      
    61         }      
    62         return value.ToString();       
    63     }  
    64
  22. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    20 May 2009
    Link to this post
    Laura Hi, I am Andrei.

    First of all, I see you are calling the GetUrl function in the src="". Look below at how I did it.

    <%

    @ Control Language="C#" AutoEventWireup="true" CodeFile="Document.ascx.cs" Inherits="Document" %>

     

    <

     

    iframe id="doc" runat="server" width="500px" height="500px" ></iframe>

     


    The Code:

    using

     

    System;

     

    using

     

    System.Web;

     

    using

     

    System.Web.UI;

     

    using

     

    Telerik.Cms.Web.UI;

     

    using

     

    Telerik.Cms.Engine;

     

    public

     

    partial class Document : System.Web.UI.UserControl

     

    {

     

    protected void Page_Load(object sender, EventArgs e)

     

    {

     

    this.doc.Attributes.Add("src", GetUrl(DocumentUrl));

     

    }

    [

    WebEditor("Telerik.Libraries.WebControls.DocumentsSelector, Telerik.Libraries")]

     

     

    public string DocumentUrl

     

    {

     

    get

     

    {

    return this.documentUrl;}

     

     

    set

     

    {

    this.documentUrl = value;}

     

    }

     

    private string documentUrl;

     

     

    private string GetUrl(string value)

     

    {

     

    // if our value starts with ~/

     

     

    // we return url

     

     

    if (value.StartsWith("~/"))

     

     

    return this.ResolveUrl(value);

     

     

     

    if (value.StartsWith("["))

     

    {

     

    int idx = value.IndexOf("]");

     

     

    //getting the provider [Libraries]

     

     

    string provider = value.Substring(1, idx - 1);

     

     

    string strId = value.Substring(idx + 1);

     

     

    Guid id = new Guid(strId);

     

     

    if (ContentManager.Providers.ContainsKey(provider))

     

    {

     

    IContent cnt = ContentManager.Providers[provider].GetContent(id);

     

     

    if (cnt != null)

     

     

    return VirtualPathUtility.ToAbsolute(cnt.UrlWithExtension, this.Context.Request.ApplicationPath);

     

    }

    }

     

    return value.ToString();

     

    }

     

    }


    I was testing it in Google Chrome and Firefox and what it would do is, download teh document rather than display it in the iFrame. In Internet Explorer works fine. Also, note that for word documents you will have to further tinker with some settings. PDFs should be ok.

    Try that.

    Andrei
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 May 2009
    Link to this post
    Hi Laura,

    For the src attribute of your iframe you should return DocumentUrl get accessor.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  24. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    20 May 2009
    Link to this post

    Thank you Andrei for the code. It was exaclty what I needed.  Got it working perfeclty.  Will try in other browsers...     I knew it was simple!  I am not verse in C# and it has been a while for me for VB so I am copying and pasting my way through some of these things before handing off to the developers...  

    Thank you Ivan too - the Telerik team is always on top of things! 

     

  25. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 May 2009
    Link to this post
    Hello Laura,

    Just to let you know, that you can use http://converter.telerik.com/ to convert some code from C# to VB and vice versa.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  26. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    21 May 2009
    Link to this post
    Ivan, Thank you. Sitefinity is a great product that keeps getting better!  I am always amazed at all the things it can do and what can be built around it with its flexibility.  
  27. David Meyer
    David Meyer avatar
    13 posts
    Registered:
    29 Oct 2009
    11 Feb 2010
    Link to this post
    Hi,
    Similar to getting the url of a document, can we access the "Link Name" as the text of the link to the document? I added the ability to add documents to events and when I show the link to the document, I can use the document filename. However, the client would like to see the name that was specified during the document selection.  To get the filename, I'm using IContent cnt = ContentManager.Providers[provider].GetContent(id);  Where can I get the alias name?
  28. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    12 Feb 2010
    Link to this post
    Hello David Meyer,

    How do you add documents to events? Do you set them as meta fields or you just insert the link to the document within the content of the event?

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  29. David Meyer
    David Meyer avatar
    13 posts
    Registered:
    29 Oct 2009
    12 Feb 2010
    Link to this post
    I'm using meta fields, in the admin page the "Insert a Document" dialog, the second step says:

    Now, the document is selected.
    A link to it will be inserted in your content.


    That value that a person enters into the text box is what Im trying to get.
  30. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    12 Feb 2010
    Link to this post
    Hi David Meyer,

    Well in this case you have to use a little bit different approach. As the regular selectors for items return the provider name and id of the Item and you want to use the RadEditor dialogs for selecting documents and saving html content into the meta field instead of the ID as string. You can achieve this if you sue RadEditor for setting the content of your meta field. In the sample I am providing you I have declared a News.Links metafield for the news module of type long text, to store my links. Extract the contents of the .zip file I attached to ~/Sitefinity/Admin/Controltemplates/ directory of your project.It contains the configuration file for your toolbar, and some CSS to makeRadEditor look it like text box. After that when declaring your editor use thefollowing settings:

    <telerik:RadEditor ID="Links"  
            Height="150px" Width="300px" ToolsWidth="200px"
            EditModes="Design" runat="server" ToolbarMode="ShowOnFocus" 
            ToolsFile="~/Sitefinity/Admin/ControlTemplates/LinkSelectors.xml" 
            Skin="WebBlue"
            NewLineBr="true"
            <CssFiles
            <telerik:EditorCssFile Value="~/Sitefinity/Admin/ControlTemplates/TextBoxLikeEditor.css" /> 
            </CssFiles
    </telerik:RadEditor>



    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
34 posts, 0 answered
1 2