Documents & Files Search Index not working for programmatically uploaded document - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Documents & Files Search Index not working for programmatically uploaded document

  • Documents & Files Search Index not working for programmatically uploaded document
  • 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.

  • 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);