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

Forums / Developing with Sitefinity / Using Image/Document WebEditor in a module

Using Image/Document WebEditor in a module

15 posts, 1 answered
  1. David
    David  avatar
    78 posts
    Registered:
    29 Dec 2008
    28 Sep 2009
    Link to this post
    Hi all,

       I created a custom module on the backend for adding different events.  Each Event has a pdf associated with it. 

    How do I load the Insert an Image dialog box in the news module but for documents?  I would like the site editor to  beable to select an existing document or upload a new document.

    Can someone point me in the write direction?


    Thanks,
    David 
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Sep 2009
    Link to this post
    Hello David ,

    Thank you for using our services.

    Are you building your custom module on generic content? In case you do so, lets assume that you have added a metafield with name Document to your module content items. Then in the templates for creating new and editing existing items you can use the follwoing to associate documents with your content items. This should be done in the section for editing the content metafields:
    <%@ Register TagPrefix="sfLib" Namespace="Telerik.Libraries.WebControls" Assembly="Telerik.Libraries" %> 
    ..... 
    <sf:ContentMetaFields ID="MetaFields" runat="server"
    ... 
     <li class="selector">  
          <asp:Label ID="Label2" AssociatedControlID="Document" runat="server">  
          <asp:Literal ID="Label222" runat="server" Text="Document"></asp:Literal>  
          <em id="DocumentLabel" runat="server"></em></asp:Label>  
          <asp:TextBox ID="Document" Text="" runat="server" MaxLength="250"></asp:TextBox>  
           <sfLib:ButtonSelector WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ItemDialog.aspx" 
                AssociatedControls="Document" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx"  
                runat="server" ButtonText="Select" />   
           <class="example">  
           <asp:Literal ID="Literal26" runat="server" Text="Select Document"></asp:Literal></p>  
    </li> 
    ... 
     </sf:ContentMetaFields> 

    This will pass a string of the following format "[Provider]Guid". Now in the public views of your content items for your module you should add some logic for parsing and retrieving the content item itself. Lets say that you will display it like this:
    <asp:Literal id="AssociatedDocument" runat="server"/>
    <asp:HyperLink id="Document" runat="server" visible="false"/> 
     

    Add this logic to the code file of your public view:
    public void Page_Load(object sender, EventArgs e)  
    {  
            string item = Document.Text;  
            Guid guid = new Guid(item.Substring(item.IndexOf("]")+1));  
            Telerik.Libraries.LibraryManager managernew Telerik.Libraries.LibraryManager();  
            Telerik.Cms.Engine.IContent cnt = manager.GetContent(guid);  
            AssociatedDocument.Text = cnt.UrlWithExtension;  
    }  

    This will return a URL for the document item. You can also use hyper link controls instead of literal.

    I hope that this information will be helpful. If you have more questions, please feel free to contact us.

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. David
    David  avatar
    78 posts
    Registered:
    29 Dec 2008
    28 Sep 2009
    Link to this post
    Radoslave,

      Thanks for the help.  The module is based on simple a linqtosql example I piece together from Sitefinity Watch, and other videos.  I am not using the generic content way, I will look into that method later this week. 

    I was able to get the select document to work in my module from your example.  I just took out the sf:ConentMetaFields tag.  I tested the code, and document manager pops up and I am able to select a document.

    All I have let to do is write the insert and update code then I move onto the front end controls.

    Thanks
    David
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Sep 2009
    Link to this post
    Hello David ,

    Thank you for the feedback.

    I am glad I was able to help. Please if you get stuck somewhere in the implementation, feel free to drop a line. We will be happy to assist you.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. John
    John avatar
    14 posts
    Registered:
    07 Nov 2008
    29 Sep 2009
    Link to this post
    Hi,
    I've implemented the solution described in this thread, and am having issues using the ButtonSelector control in my new/edit templates. I'm actually having several issues:

    - While the Selector dialog does appear when the "Select" link is clicked, the dialog says I have no libraries or my libraries have no files in them. In fact, I have some image libraries with images in them. Browsing the file system works fine.

    - I have multiple meta fields in my module that need to be filenames chosen from a library. I therefore need several different ButtonSelector controls in the new/edit templates. When adding a second ButtonSelector control, the first properly shows the dialog when "Select" is clicked. However, when clicking the "Select" link for the second ButtonSelector control, nothing happens.

    Finally, I'd like to know (once I resolve these other issues) whether there's a way to specify which library a ButtonSelector chooses from by default.

    Thanks!
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Sep 2009
    Link to this post
    Hello John,

    Most probably you are not using the last official release( Sitefinity 3.7 SP1). The problems you have was related to bugs in older Sitefinity versions.

    Finally, I'd like to know (once I resolve these other issues) whether there's a way to specify which library a ButtonSelector chooses from by default.

    By default the ButtonSelector uses ItemSelector WebEditor which opens a dialog with all libraries and then you need to select from an item. If you want to set a default library or restrict the access to a given library from this selector, you need to implement a custom web editor and replace the default one. Your custom web editor should inherit from WebUITypeEditor. Then you can use ObjectDataSource  with
    SelectMethod = "GetAllLibraries"; Finally use a Repeater control and set its DataSource property. Then add a new property that can be used to specify the default library.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. John
    John avatar
    14 posts
    Registered:
    07 Nov 2008
    29 Sep 2009
    Link to this post
    Thanks Ivan,

    Unfortunately, the version I'm using is indeed 3.7 SP1, downloaded about four days ago.
  8. David
    David  avatar
    78 posts
    Registered:
    29 Dec 2008
    29 Sep 2009
    Link to this post
    The backend of the module is up and running now.  I am listing the records in a RadGrid template. 

    What is the correct to the front end in a grid to retrieve the file name and url for the hyperlink control.  Below is what I am trying so far.

    Thanks David 

    Like this:

     

        
    <asp:Literal id="AssociatedDocument" runat="server"/>  
    <asp:HyperLink id="Document" runat="server" NavigateUrl='<%# "~/" +  Eval("pdf") %>'   
                Text='<%# Eval("pdf") %>'></asp:HyperLink> 
     
    //Code behind file  
    HyperLink Document = (HyperLink)e.Item.FindControl("Document");  
            string item = Document.Text;  
            Guid guid = new Guid(item.Substring(item.IndexOf("]") + 1));  
            Telerik.Libraries.LibraryManager manager = new Telerik.Libraries.LibraryManager();  
            Telerik.Cms.Engine.IContent cnt = manager.GetContent(guid);  
            Literal AssociatedDocument = (Literal)e.Item.FindControl("AssociatedDocument");  
            AssociatedDocument.Text = cnt.UrlWithExtension;   
  9. David
    David  avatar
    78 posts
    Registered:
    29 Dec 2008
    29 Sep 2009
    Link to this post
    The file guid I am saving to my table below  Does this look correct for path to a file, is it being trunicated? What table is this information kept in?  I found the library table but not the file table.
     [Libraries]f2863087-69ce-4261-a3a9-c3648d8eb486

  10. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    29 Sep 2009
    Link to this post
    Hi David ,

    I think I have mislead you in one of my posts.

    What you are storing in your database table is not path to the particular item. It is rather a unique identifier to each item, so that content managers can pull it out from the CMS. It is the [Libraries] denotes the content provider the item is stored in (Images & Documents in this case), and the f2863087-69ce-4261-a3a9-c3648d8eb486 is an unique identifier to the item in the form of a Guid.

    Since you are pulling from the database a property with name Document, and having the value as described above, you should do the following. In code behind assign this to a value of type string.  Then parse the string to get the item Guid, and get the content item as in my last posts:
    public void Page_Load(object sender, EventArgs e) 
        { 
            //assume you have get the value from db to local variable string docStr 
            Guid guid = new Guid(docStr.Substring(item.IndexOf("]")+1)); 
            Telerik.Libraries.LibraryManager manager= new Telerik.Libraries.LibraryManager(); 
            Telerik.Cms.Engine.IContent cnt = manager.GetContent(guid); 
            //use ResolveUrl method because UrlWithExtension returns relative url 
            Document.NavigateUrl = ResolveUrl(cnt.UrlWithExtension); 
            //you can even get meta data such as document title if you have set it on upload 
            Document.Text = cnt.GetMetaData("Name"); 


    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. David
    David  avatar
    78 posts
    Registered:
    29 Dec 2008
    29 Sep 2009
    Link to this post
    Update:  I got the code above working better but not fix.  I forgot to connect the grid up with onitemdatabound="RadGrid1_ItemDataBound"

    Once I got the Grid working correcting, I got:
    Guid should contain 32 digits with 4 dashes  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    The data from the database is  [Libraries]e4757de1-a596-479c-807a-cd4d134dca3a .
    After the substing function the value is    e4757de1-a596-479c-807a-cd4d134dca3a. 

    The Guid store in the database table appears to be correct.


    HyperLink Document = (HyperLink)e.Item.FindControl("Document");  
                string item = Document.Text;  
                Guid guid = new Guid(item.Substring(item.IndexOf("]") + 1));  
                Telerik.Libraries.LibraryManager manager = new Telerik.Libraries.LibraryManager();  
                Telerik.Cms.Engine.IContent cnt = manager.GetContent(guid);  
                Literal AssociatedDocument = (Literal)e.Item.FindControl("AssociatedDocument");  
                AssociatedDocument.Text = cnt.UrlWithExtension; 

  12. David
    David  avatar
    78 posts
    Registered:
    29 Dec 2008
    29 Sep 2009
    Link to this post
    Hi Radoslav

      I just figure that out.  I took and paste the value I got after parsing the string into the new Guid.
    Guid guid = new Guid("e4757de1-a596-479c-807a-cd4d134dca3a");

     Everything works with the static value.  I am thinking I have some hidden char or white space after the value after parsing

    David
  13. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    29 Sep 2009
    Link to this post
    Hello David ,

    Can you try to trim the string after you parse it, to see what will happen:
    Guid guid = new Guid(item.Substring(item.IndexOf("]") + 1).Trim()); 

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  14. David
    David  avatar
    78 posts
    Registered:
    29 Dec 2008
    29 Sep 2009
    Link to this post
    Still getting the problem after trim.  Here is a value I loaded into a label for testing
    e4757de1-a596-479c-807a-cd4d134dca3a

    The value in document before substring and trim:
    [Libraries]e4757de1-a596-479c-807a-cd4d134dca3a

    If I paste (hardcode) into new Guid("e4757de1-a596-479c-807a-cd4d134dca3a") It accepts it. 

  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Sep 2009
    Link to this post
    Hello David ,

    I suggest that you should try to resolve the link using the solution provided in this blog post. Let us know how it goes.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
15 posts, 1 answered