More in this section
Forums / Developing with Sitefinity / Documents & Files Search Index not working for programmatically uploaded document

Documents & Files Search Index not working for programmatically uploaded document

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Zepp
    Zepp avatar
    22 posts
    Registered:
    19 Aug 2015
    09 Nov 2017
    Link to this post

    Hi,

    When I upload & publish a document through Sitefinity Backend, the search widget returns the uploaded document.

    When I do the same pro-grammatically, as I have a form that the user will fill in through a front-end page & will upload a document from there which i then upload & publish to the Document Library of Sitefinity through custom code, the search widget does not return that document(.docx, txt files).

    When I manually unpublish the document uploaded programmatically & re-publish it through Sitefinity Backend, the document then appears in the search index results. 

    Why is that happening? I am uploading the document through normal procedure & its even in published state, why is it not being returned by Search Index when I upload it through LibrariesManager api through custom controller code.

    Any help would be appreciated, we are using out-of-the box search service of Sitefinity. Sitefinity version is 8.2

     

    Thanks.

  2. Zepp
    Zepp avatar
    22 posts
    Registered:
    19 Aug 2015
    09 Nov 2017 in reply to Zepp
    Link to this post

    Following is the code I am using to upload the document programmatically - These uploaded document are not being returned by SearchIndex - When I manually Unpublish/Republish them they start appearing: 

     private readonly LibrariesManager _librariesManager = LibrariesManager.GetManager();
    Document document = _librariesManager.CreateDocument(Guid.NewGuid());
    _librariesManager.Provider.SuppressSecurityChecks = true;
    DocumentLibrary documentLibrary = _librariesManager.GetDocumentLibraries().Where(d => d.Title == "xxxx").SingleOrDefault();
    document.Parent = documentLibrary;
    string Title =  "xxx"
    string docTitle =  "xxx"
    document.Title =  "xxx"
    document.DateCreated = DateTime.UtcNow;
    document.PublicationDate = DateTime.UtcNow;
    document.LastModified = DateTime.UtcNow;
    document.ApprovalWorkflowState = "Published";
    document.UrlName = "xxx"
    document.MediaUrl =  "xxx"

    _librariesManager.Upload(document, file.InputStream, Title.Substring(Title.LastIndexOf(".")));
    _librariesManager.RecompileAndValidateUrls(document);
    _librariesManager.Lifecycle.Publish(document, new CultureInfo(cultureName));
    //_librariesManager.Lifecycle.CheckIn(document);
    _librariesManager.SaveChanges();
    document.SetWorkflowStatus(_librariesManager.Provider.ApplicationName, "Published", new CultureInfo(cultureName));

    //For Publishing Live document
    // var bag = new Dictionary<string, string>();
    // bag.Add("ContentType", typeof(Document).FullName);
    //  WorkflowManager.MessageWorkflow(document.Id, typeof(Document), null, "Publish", false, bag);

2 posts, 0 answered