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

Forums / Developing with Sitefinity / Set Category after uploading documents via zip

Set Category after uploading documents via zip

25 posts, 0 answered
  1. Jeff Mah
    Jeff Mah avatar
    31 posts
    Registered:
    25 Feb 2005
    05 Jan 2009
    Link to this post
    Hi,

    Is it possible to set the category for documents that have been uploaded via the zip file process immediately after the zip file is uploaded and extracted on the same batch screen along with the Title, Description, etc.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Jan 2009
    Link to this post
    Hi Jeff Mah,

    Thank you for contacting us.

    Here is an example that shows how to add Categories drop down to BatchEditor template. This will allow you to set the category for your items after they have been extracted from an archive.

     <asp:Repeater ID="itemList" runat="server"
                    <ItemTemplate> 
                        <li>                     
                            <dl> 
                                <asp:PlaceHolder ID="imagePlaceholder" runat="server"
                                    <dd class="image"><asp:Image ID="thumbnail" runat="server" /></dd
                                </asp:PlaceHolder> 
                                <sf:ContentMetaFields ID="Image" runat="server" Visible="false"
                                    <ItemTemplate> 
                                        <dt> 
                                            <asp:Label runat="server" AssociatedControlID="Name" Text="<%$Resources:Title %>"></asp:Label> 
                                            <asp:TextBox ID="Name" runat="server"></asp:TextBox> 
                                            <asp:RequiredFieldValidator ValidationGroup="editItems" ID="RequiredFieldValidator1" runat="server" ControlToValidate="Name" Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True"><strong><asp:Literal ID="Literal8" runat="server" Text="<%$Resources:TitleEmpty %>"></asp:Literal></strong></asp:RequiredFieldValidator> 
                                            <asp:RegularExpressionValidator ValidationGroup="editItems" ID="RegularExpressionValidator2" Runat="server" ValidationExpression='[^\\/:*?"<>|]+' ControlToValidate="Name" Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True"><strong><asp:Literal ID="Literal7" runat="server" Text="<%$Resources:FileNameRestrictions %>"></asp:Literal></strong></asp:RegularExpressionValidator> 
                                        </dt> 
                                        <dd> 
                                            <asp:Label runat="server" AssociatedControlID="AlternateText" Text="<%$Resources:Alternative %>"></asp:Label> 
                                            <asp:TextBox ID="AlternateText" runat="server"></asp:TextBox> 
                                        </dd> 
                                        <asp:Label ID="Label8" AssociatedControlID="commonCategories" runat="server"
                                            <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Category %>"></asp:Literal> 
                                        <em id="Em1" runat="server"></em></asp:Label> 
                                        <sfCtg:CategoriesField ID="commonCategories" runat="server" /> 
     
                                    </ItemTemplate> 
                                </sf:ContentMetaFields> 

    It could be done programatically, but it will require more coding

    Example:

            // upload files using RadUpload  
            foreach (UploadedFile file in RadUpload1.UploadedFiles)  
            {  
                file.SaveAs("c:\\Images\\" + file.GetName(), true);  
            }  
            // create new instance of LibraryManager  
            LibraryManager libraryManager = new LibraryManager();  
            // get library by specified Name  
           ILibrary parentLibrary = libraryManager.GetLibrary("Images");  
            // create an image content item  
            IContent testContent = libraryManager.CreateContent("image/jpeg");  
            // specify parent library the image will belong to  
            testContent.ParentID = parentLibrary.ID;  
            //get the first uploaded file  
            UploadedFile firstFile = RadUpload1.UploadedFiles[0];  
            byte[] buffer = new byte[firstFile.InputStream.Length];  
            long position = 0;  
            int currentByte = firstFile.InputStream.ReadByte();  
            while (currentByte != -1)  
            {  
                buffer[position++] = (byte)currentByte;  
                currentByte = firstFile.InputStream.ReadByte();  
            }  
            IContent content = null;  
            // upload the file  
              
            try  
            {  
                content = libraryManager.UploadFile(buffer,  
                firstFile.GetNameWithoutExtension(),  
                firstFile.GetExtension(),  
                firstFile.ContentType,  
                firstFile.ContentLength,  
                parentLibrary);  
      
                StagedContent temp = libraryManager.GetCurrentState(content.ID) as StagedContent;  
                temp.SetMetaData("Author""myself");  
                temp.SetMetaData("Category""mycategoryhere");  
                libraryManager.SaveContent(temp, ContentStatus.Published);  
                  
            }  
            catch (ArgumentException ex)  
            {  
                Response.Write("There is an exception");  
            }  
            // save the image as a content of the file  
            testContent.Content = buffer;  
            Response.Write(testContent.GetMetaData("Name") + "<br />");  
        }   

    Let us know if there is anything else that we can do for you.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Jeff Mah
    Jeff Mah avatar
    31 posts
    Registered:
    25 Feb 2005
    08 Jan 2009
    Link to this post
    After adding the code highlighted to the ~\Sitefinity\Admin\ControlTemplates\Libraries\ there wasn't anything different on the batch edit screen. Do I need to do more to enable this?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Jan 2009
    Link to this post
    Hello Jeff Mah,

    The code should be pasted in ~\Sitefinity\Admin\ControlTemplates\Libraries\BatchEditor.ascx.
    However, after reviewing the code and implementation again, I figured out that adding CategoriesField control would not do the trick. It will list the categories correctly, but after you click "save" button the categories will not be assigned to your items. It is a bug that we will try to fix for 3.6.
    The solution that we could offer you is to use the second snippet of code I sent you.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. shae
    shae avatar
    30 posts
    Registered:
    26 Jul 2012
    21 May 2009
    Link to this post
    What File do you edit for the second option?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 May 2009
    Link to this post
    Hello shae,

    You can use LibraryItemBatchEdit.ascx template located under Sitefinity/Admin/ControlTemplates/Libraries/ folder of our External templates archive. You can donwload the external templates form MyClient.net and then map LibraryItemBatchEdit to your project. Afterwards you should declare ContentCategoriesfield control in you template as the example below demostrates. 

    <%@ Control Language="C#" %> 
    <%@ Register TagPrefix="sf" Namespace="Telerik.Cms.Engine.WebControls" Assembly="Telerik.Cms.Engine" %> 
    <%@ Register TagPrefix="sf" Namespace="Telerik.Cms.Engine.WebControls.Categories" Assembly="Telerik.Cms.Engine" %> 
    <%@ Register TagPrefix="sf" Namespace="Telerik.Cms.Web.UI" Assembly="Telerik.Cms.Web.UI" %> 
    <%@ Register TagPrefix="sf" Namespace="Telerik.Cms.Engine.WebControls.Admin" Assembly="Telerik.Cms.Engine" %> 
     
    <div class="ToolsAll">  
        <div class="backWrapp">  
        <asp:HyperLink ID="backButton" runat="server" CssClass="actions back"><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:BatchEdit_BackToItems %>"></asp:Literal></asp:HyperLink> 
        </div> 
    </div> 
     
    <div class="workArea">  
        <div class="mainForm">  
            <class="button_area top">  
                <asp:LinkButton ID="saveButton1" runat="server" ValidationGroup="editItems" CssClass="CmsButLeft okdark"><strong class="CmsButRight dark"><asp:Literal ID="Literal4" runat="server" Text="<%$Resources:BatchEdit_SaveChanges %>"></asp:Literal></strong></asp:LinkButton> 
                <span id="Span1" runat="server">  
                    <asp:Literal ID="Literal5" runat="server" Text="<%$Resources:BatchEdit_Or %>"></asp:Literal></span>  
                <asp:HyperLink ID="cancelButton1" Text="<%$Resources:BatchEdit_Cancel %>" runat="server" CssClass="cmscclcmd" 
                    CausesValidation="false"><asp:Literal ID="Literal6" runat="server" Text="<%$Resources:BatchEdit_Cancel %>"></asp:Literal></asp:HyperLink> 
            </p> 
            <class="mand">* Mandatory fields</p> 
            <h3><asp:Literal ID="Literal9" runat="server" Text="<%$Resources:BatchEdit_Preview %>"></asp:Literal></h3>  
            <fieldset class="set">  
                <div class="setIn batchtags">                 
                    <asp:Label runat="server" AssociatedControlID="commonCategories" Text="<%$Resources:Category %>"></asp:Label> 
                    <sf:CategoriesField ID="commonCategories" runat="server" /> 

    Note that the control works in the above context in versions 3.6.

    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.
  7. shae
    shae avatar
    30 posts
    Registered:
    26 Jul 2012
    26 May 2009
    Link to this post
    That works, but not quite there yet.

    1) I like that you can choose the category for all the items at once when you upload a zip file. Because usually when you upload multiple files in a .zip file they are the same category. However, when you choose to batch edit, you only have one category dropdown instead of a category drop down for each item. I don't want all the items in the library to be the same category, so I would need a category dropdown for each item.

    2) I would like category to be mandatory everytime.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 May 2009
    Link to this post
    Hello shae,

    1. You can also add ContentCategoriesField for each item in the batch edit, so that you can set different categories to your items or use the previously posted solution for globally assigning a category.

    LibraryItemBatchEdit.ascx template:
    Note that you should set the provider.

    <sf:ContentCategoriesField ID="Category" runat="server" ProviderName="Libraries" /> 

    2. To make the control required - Map the external template directly in the control declaration using LayoutTemplatePath property. After you have mapped the template, add RequiredFieldValidator control to the RadCombobox declared in this template.

    Best wishes,
    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.
  9. shae
    shae avatar
    30 posts
    Registered:
    26 Jul 2012
    26 May 2009
    Link to this post
    I was able to follow you on step one and it is working.

    Can you elaborate more on step 2 for me.
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 May 2009
    Link to this post
    Hello shae,

    1. Map LibraryItemBatchEdit.ascx
    2. Modify ContentCategoriesField control as below:

    <sf:ContentCategoriesField ID="Category" runat="server"  LayoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/Generic_Content/CategoriesField.ascx"></sf:ContentCategoriesField> 

    By doing so you are mapping the external template for ContentCategoriesField control. Here layoutTemplatePath is for demonstrative purposes. You need to locate your template.

    3. Modify ContententCategoriesField control template using Validator:

    <%@ Control Language="C#" %> 
    <%@ Register Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" TagPrefix="telerik" %> 
    <asp:Label runat="server" ID="lbl" Text="MAPPED"></asp:Label> 
    <telerik:RadComboBox ID="categoriesList" EnableEmbeddedSkins="true" Skin="WebBlue" runat="server"></telerik:RadComboBox> 
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" 
    ControlToValidate="categoriesList" 
    InitialValue="* Uncategorized *" 
    ErrorMessage="Please select category" 
    ValidationGroup="YOUR VALIDATION GROUP"/> 
     

    Just to let you know this approach works only in Sitefinity versions 3.6x. The control in the previous versions is different and its container is private which means that it cannot be accessed.


    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.
  11. Graham
    Graham avatar
    6 posts
    Registered:
    18 Sep 2006
    17 Feb 2010
    Link to this post
    I followed the steps in this post and added the sf:CategoriesField control to my custom LibraryItemBatchEdit.ascx template. 

    On my admin page, the drop-down list for category shows up, but the list is empty.  If I use LibraryItemEdit.ascx to edit an image, the category drop-down list is correctly populated.
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Feb 2010
    Link to this post
    Hi Graham,

    These are changes that applies to the controls declaration and this does not affect the bindings. Make sure that you have the same IDs as the default controls in edit and new templates.

    Anyhow, you could try to get the categories using a custom code in the code behind of LibraryItemBatchEdit.ascx.

    • Subscribe for itemList.ItemDataBound
    • find the ContentMetaFileds control e.Item.FindControl("Default") as ContentMetaFields;
    • Create a RadComboBox and bind it to a list of all categories for Libraries provider

    This should work for sure.

    Regards,
    Ivan Dimitrov
    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.
  13. Graham
    Graham avatar
    6 posts
    Registered:
    18 Sep 2006
    17 Feb 2010
    Link to this post
    Your suggestions raise some new questions:

    1. You suggest I update the codebehind for LibraryItemBatchEdit.ascx.  There is no code behind included in the template zip file; do I just create a LibraryItemBatchEdit.ascx.cs file, and add the methods I need?  Must I update the ascx file with a reference to this newly created ascx.cs file?  How can I be sure that I'm not overriding essential code?

    2. You mention 3 steps: are these all required, or are they alternatives?  You mention creating a RadComboBox; isn't this already done in the sf:CategoriesField control?

    3. If I'm to use step 3, I'll need a little more information on how to subscribe a RadComboBox to a list of all categories for Libraries provider
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Feb 2010
    Link to this post
    Hi Graham,

    1. Create a code behind of the template. You cannot override any code because the base events will be triggered instead of yours in the custom control. Also there are not any changes related to the base implementation that could corrupt something.

    2. The three steps are required.

    3. Sample code is shown below

    var manager = new ContentManager("Libraries");
    IList listofCategores = manager.GetCategories();
     foreach (ICategory cat in listofCategores) 
            {
                            string val = cat.CategoryName;
                            RadComboBoxItem item = new RadComboBoxItem(val, val);
                            combo.Items.Add(item);
            }


    Sincerely yours,
    Ivan Dimitrov
    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.
  15. Graham
    Graham avatar
    6 posts
    Registered:
    18 Sep 2006
    18 Feb 2010
    Link to this post
    Almost there.  I have included the code you recommended, but I can't seem to "find" my RadComboBox control in the ContentMetaFields section. 

    When I execute the following code, the "combo" variable is always null (even if I don't try to cast it to a RadComboBox):

     

    void ItemList_ItemDataBound(Object sender, RepeaterItemEventArgs e)

     

    {

     

        ContentMetaFields f = e.Item.FindControl("Default") as ContentMetaFields;

     

     

        RadComboBox combo = f.FindControl("Category") as RadComboBox;
    }

    This is in the LibraryItemBatchEdit markup:

     

    <

     

    telerik:RadComboBox ID="Category" runat="server" />

     

  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Feb 2010
    Link to this post
    Hello Graham,

    Try using Controls[0].FindControl("Category"). This is general ASP.NET.

    Sincerely yours,
    Ivan Dimitrov
    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.
  17. Graham
    Graham avatar
    6 posts
    Registered:
    18 Sep 2006
    18 Feb 2010
    Link to this post
    Thanks for the tip, I can now find my RadComboBox control.  However, I'm adding the categories (and I can step through the code, so I know it's happening) but the RadComboBox is empy when the page is displayed.  I'm populating the RadComboBox in the ItemDataBound event of the repeater.
  18. Karl
    Karl avatar
    45 posts
    Registered:
    18 Jun 2009
    15 Mar 2011
    Link to this post
    Hi,

    I'm trying to implment  this for our instance of SiteFinity 3.7 SP4 .NET 4 and get this error:
    The resource object with key 'BatchEdit_BackToItems' was not found.

    Line 7:  <div class="ToolsAll">
    Line 8:      <div class="backWrapp">
    Line 9:      <asp:HyperLink ID="backButton" runat="server" CssClass="actions back"><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:BatchEdit_BackToItems %>"></asp:Literal></asp:HyperLink>
    Line 10:     </div>
    Line 11: </div>
      

    I've copied the templates and added the below to the configuration file, all I want to be able to do is set the category for the bulk upload to all files contained in a Zip File.

    <!--

     

     

    Edit library item properties in batches - Images & Documents.-->

     

     

    <

     

     

    viewSettings hostType="Telerik.Libraries.WebControls.Admin.LibraryItemBatchEdit`1[[Telerik.Libraries.WebControls.Admin.LibraryItemsView, Telerik.Libraries]]" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/Libraries/LibraryItemBatchEdit.ascx" />

    Many thanks

     

  19. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    19 Mar 2011
    Link to this post
    Hi Karl,

    The particular error is that there is no resource file, from which the strings for the links/button can be taken. Have you mapped the resources as well?

    I suggest you to go with this way:

    Find:

    <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:BatchEdit_BackToItems %>">

    and change it to:
    <asp:Literal ID="Literal1" runat="server" Text="Back">

    This way no resource should be involved. You may do the same for any other links or resource strings. 

    Regards,
    Georgi
    the Telerik team
  20. Karl
    Karl avatar
    45 posts
    Registered:
    18 Jun 2009
    21 Mar 2011
    Link to this post
    Hi,

    Thanks I added this 
    <viewSettings hostType="Telerik.Libraries.WebControls.Admin.LibraryItemBatchEdit`1[[Telerik.Libraries.WebControls.Admin.LibraryItemsView, Telerik.Libraries]]" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/Libraries/LibraryItemBatchEdit.ascx">

    to the
    Telerik.Sitefinity.Configuration.ControlsConfig.xml which is in the App_data folder and copied the templates, is that not the correct way to map? By doing the below wouldn't have to go through every control. I've done what you mentioned below and its bringing up the same error for the next control.

    Thanks
  21. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Mar 2011
    Link to this post
    Hi Karl,

    Have you added the resx files for the template you are trying to map? We use the ASP.NET local resources.

    Regards,
    Ivan Dimitrov
    the Telerik team
  22. Karl
    Karl avatar
    45 posts
    Registered:
    18 Jun 2009
    21 Mar 2011
    Link to this post
    Thanks, that was the bit I was missing.
  23. Karl
    Karl avatar
    45 posts
    Registered:
    18 Jun 2009
    21 Mar 2011
    Link to this post
    Hi,

    Where do you set it so when I upload a zip file I can select the category to upload in to? I don't want to have to select a category for each individual file after uploading.

    Thanks
  24. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Mar 2011
    Link to this post
    Hi Karl,

    To set the categories when you make batch edit you should enable categories drop down from the external template

    <fieldset class="set">
                <div class="setIn batchtags">               
                    <%--<asp:Label runat="server" AssociatedControlID="commonCategories" Text="<%$Resources:Category %>"></asp:Label>
                    <sf:CategoriesField ID="commonCategories" runat="server" />--%>
                    <sf:ContentTagEditor ID="commonTags" runat="server" />
                </div>
            </fieldset>



    Kind regards,
    Ivan Dimitrov
    the Telerik team
  25. Karl
    Karl avatar
    45 posts
    Registered:
    18 Jun 2009
    21 Mar 2011
    Link to this post
    thanks
Register for webinar
25 posts, 0 answered