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

Forums / General Discussions / Select Document Tags

Select Document Tags

5 posts, 0 answered
  1. AFTR
    AFTR avatar
    22 posts
    Registered:
    05 Oct 2010
    13 Apr 2011
    Link to this post
    Hello,

    I am having a difficulty.

    I currently select a list of documents from a library like this.

               /// <summary>
            /// Selects a list of documents for the user to view
            /// </summary>
            /// <returns>A list of conformed contract documents</returns>
            public static IEnumerable<Document> SelectUserDocuments(string libraryName)
            {
                LibrariesManager libraryManager = LibrariesManager.GetManager();
                IEnumerable<Document> docs = libraryManager.GetDocumentLibraries()
                    .Where(dL => dL.Title == libraryName)
                    .First()
                    .Documents
                    .Where(d => d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
                    .OrderBy(o => (string)o.Title);
                 
                return docs;
            } // SelectUserDocuments

    I upload documents to a library like this.

    /// <summary>
    /// Uploads the selected document to the CDRLs library
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Event Args</param>
    protected void UploadButton_Click(object sender, EventArgs e)
    {
        int count = DocumentUpload.UploadedFiles.Count;
        string[] allowedTypes = Properties.Resources.DocumentAllowedFileExtensions.Split(Properties.Resources.DelimiterComma.ToCharArray());
        string error = String.Empty;
        if (count > 0)
        {
            foreach (UploadedFile file in DocumentUpload.UploadedFiles)
            {
                bool properFile = false;
     
                foreach (string allowedExtension in allowedTypes)
                {
                    if (file.GetExtension() == allowedExtension)
                    {
                        properFile = true;
                    }
                }
     
                if (properFile == true)
                {
                    // declare the document file and its properties
                    var manager = new LibrariesManager();
                    Telerik.Sitefinity.Libraries.Model.Document uploadDocument = manager.CreateDocument();
                    uploadDocument.Parent = manager.GetDocumentLibraries().Where(dl => dl.Title == Properties.Resources.DocumentsLibraryName_CDRLs).First();
                    uploadDocument.Title = file.GetNameWithoutExtension();
                    uploadDocument.UrlName = file.GetNameWithoutExtension();
                    uploadDocument.Extension = file.GetExtension();
                    uploadDocument.Status = Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master;
                    manager.RecompileItemUrls<Telerik.Sitefinity.Libraries.Model.Document>(uploadDocument);
     
                    // upload the document file
                    manager.Upload(uploadDocument, file.InputStream, file.GetExtension());
     
                    // publish the document file
                    uploadDocument.ApprovalWorkflowState = Properties.Resources.PublishedWorkflowState;
                    manager.Publish(uploadDocument);
                    manager.SaveChanges();
     
     
                    SystemMessage.Text = SitefinityCommon.BuildSuccessMessage(Properties.Resources.CDRLs_UploadSuccess);
                }
                else
                {
                    SystemMessage.Text = SitefinityCommon.BuildErrorMessage(Properties.Resources.CDRLs_UploadError_BadType + Properties.Resources.DocumentAllowedFileExtensions_Friendly);
                }
            }
     
            //refresh table
            RefreshDocumentsTable();
        }
        else
        {
            SystemMessage.Text = SitefinityCommon.BuildErrorMessage(Properties.Resources.CDRLs_UploadError_NoFiles);
        }
    } // UploadButton_Click

    Recently, I have discovered new requirements that require additional information for each document. Basically, each document needs to have a tag, category, or custom field with data associated with it

    For instance, in the first code example, what I want is something like another property for each document. Example, if the first code snip returned a list of 12 documents, 7 of them could have a tag (or something similar) that was equal to "Special".

    How can I access the tag for returned documents.

    Additionally, how can I set the tag for uploaded documents?

    Thanks
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    02 Dec 2016
    14 Apr 2011
    Link to this post
    Hi,

    1. How can I access the tag for returned documents. - you can pass the tag name and then get the tag Id (alternatively you can get the Id straight from the sf_taxa table in the DB. Once you get the Id you can select the documents that have this Id associated with the tags field like this:

    var taxManager = TaxonomyManager.GetManager();
    var taxon = taxManager.GetTaxa<FlatTaxon>().Where(t => t.Name == "tag").Single();
    var taxonID = taxon.Id;
    var content = App.WorkWith().Documents().Where(d => ((IList<Guid>)d.GetValue("Tags")).Contains(taxonID)).Get();

    2. How can I set the tag for uploaded documents - can you, please, take a look at this page from our Developers Guide.

    Greetings,
    Boyan Barnev
    the Telerik team

  3. AFTR
    AFTR avatar
    22 posts
    Registered:
    05 Oct 2010
    18 Apr 2011
    Link to this post
    --wrong thread--
  4. Solomon Shaffer
    Solomon Shaffer avatar
    6 posts
    Registered:
    30 Jan 2014
    24 Apr 2014 in reply to Boyan Barnev
    Link to this post

    Can you update the link on this page? It is returning a 404.

  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    02 Dec 2016
    29 Apr 2014
    Link to this post
    Hello Solomon,

    Thnak you for your note,please find the correct link below:

    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/taxonomies


    Regards,
    Boyan Barnev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
5 posts, 0 answered