# FileSystemwatcher with Documents Indexing as Attachments (c#,Nest)

**URL:** <https://discuss.elastic.co/t/filesystemwatcher-with-documents-indexing-as-attachments-c-nest/51105>\
**Category:** Elasticsearch\
**Created:** [May 27, 2016, 2:11am UTC](https://discuss.elastic.co/t/filesystemwatcher-with-documents-indexing-as-attachments-c-nest/51105 "2016-05-27T02:11:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asn/32/10535_2.png) [@ASN](https://discuss.elastic.co/u/ASN)\
**Post date:** [May 27, 2016, 2:11am UTC](https://discuss.elastic.co/t/filesystemwatcher-with-documents-indexing-as-attachments-c-nest/51105/1 "2016-05-27T02:11:05Z")

</div>

Hi All,  
I'm trying to reproduce a console application which watches a folder and any new additions of documents to the folder are to be Indexed to ES .

It is working fine If I move/add 3-4 documents at a time and able to index. But if I move around 30 documents at a time, It is not indexing all the documents, instead indexing only one. But If I run the code with break points , then even 30 documents are also getting indexed.  
Can some one help me in solving this.

```
 static void OnCreated(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("File Created: Path: {0}, \n Name: {1}", e.FullPath, e.Name);
            Indexdoc(e.FullPath);
        }

```

If I dont call the Indexdoc(e.FullPath) method in the above code and instead print the changes, it is showing all the filenames added perfectly. so there is no problem with the filesystemwatcher. I think indexing documents is taking time to generate response and come back to onCreated method.

```
public static void Indexdoc(string newFilePath)
        {
            List<Document> list = new List<Document>(); //list of Document class objects
            List<string> filesList = new List<string>(); //list of files in the path received on method call
            string path = string.Empty;

            client = ConfigSettings.connection();
			
            if (newFilePath == null) //for FULL Indexing
            {
               //some code here
            }
            else //for new files indexing
            {
                filesList.Add(newFilePath); //adds only one file everytime the method is called.
                //the newFilePath will be of type C:/Documents/abc.txt
            }

            try
            {
                foreach (string file in filesList)
                {
                    Attachment attach = new Attachment
                    {
                        Name = Path.GetFileNameWithoutExtension(file),
                        Content = Convert.ToBase64String(File.ReadAllBytes(file)),
                        ContentType = Path.GetExtension(file)
                    };

                    var doc = new Document()
                    {
                        Title = Path.GetFileNameWithoutExtension(file),
                        FilePath = Path.GetFullPath(file), //added to get the path of the file
                        File = attach
                    };

                    list.Add(doc);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
            
			var response = client.IndexMany(list, "trial");
		}

```

Can some one help me in solving this.

TIA

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:48pm UTC](https://discuss.elastic.co/t/filesystemwatcher-with-documents-indexing-as-attachments-c-nest/51105/2 "2017-07-05T22:48:40Z")

</div>


