Select Document Tags

Posted by Community Admin on 03-Aug-2018 18:09

Select Document Tags

All Replies

Posted by Community Admin on 13-Apr-2011 00:00

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

Posted by Community Admin on 14-Apr-2011 00:00

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

Posted by Community Admin on 18-Apr-2011 00:00

--wrong thread--

Posted by Community Admin on 24-Apr-2014 00:00

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

Posted by Community Admin on 29-Apr-2014 00:00

Hello Solomon,

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

www.sitefinity.com/.../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
 

This thread is closed