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

Forums / Bugs & Issues / Images and Documents - should enforce unique constraint on Name

Images and Documents - should enforce unique constraint on Name

4 posts, 0 answered
  1. clayman
    clayman avatar
    38 posts
    Registered:
    23 Sep 2009
    29 Dec 2009
    Link to this post

    When uploading / saving a document within a library, it is possible to specify a name that is identical to an existing document in the same library. 

    Each document could have other unique attributes (category or tags or description...) but the names are identical.  So from the perspective of a content author, this could be considered a unique document.

    However, since the content item's url is generated based on the name, the result is that only one document will be retrievable, regardless of the other properties on the document that make it "unique".

    As a result, there should be a unique constraint enforced on the document's name property, so that in the event a user specifies an existing name they are presented with a cancel/replace dialog.  This would prevent the creation of "dead" documents (documents that exist but cannot be retrieved via url).
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Dec 2009
    Link to this post
    Hi clayman,

    There is no way to have two documents with the same name in one library. This could happen if the item has been uploaded and then renamed, but during the upload we append an index if there is a file with the same name. However, you can replace the default view for LibraryItemEdit, then override InitializeControls and subscribe for CommandEventHandler. Then you need to check whether in this library there is a an item with the same name.

    sample code:

    protected void SaveButton_Command(object sender, CommandEventArgs e)
    {
        if (this.currState == null)
            return;
        foreach (IContent cnt in library.GetItems())
        {
            Guid ItemID = cnt.ID;
            if (NameTextBox.Text == cnt.GetMetaData("Name").ToString() &&
                currState.ID != cnt.ID)
            {
               // do not proceed with saving    
             
            }
        }
             
     
           .....
                   .....
                        .....


    Sincerely yours,
    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.
  3. clayman
    clayman avatar
    38 posts
    Registered:
    23 Sep 2009
    29 Dec 2009
    Link to this post
    thanks for the code snippet.  although I really think your code should be doing this by default.  the fact that you enforce uniqueness on uploads (create) but not on save seems like a design flaw.  you should be appending the index on the save then, as well, if that was the developer's solution to enforcing uniqueness.  hopefully this will be resolved in 4.0?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Dec 2009
    Link to this post
    Hello clayman,

    Thank you for getting back to me. You are right and we will think of a possible way that we could handle this in one of the next SP of 3.7.

    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
4 posts, 0 answered