Exemplo n.º 1
0
        protected void btnProcess_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                var reader   = new StreamReader(FileUpload1.FileContent);
                var document = reader.ReadToEnd();
                reader.Close();
                string fileName = tbFileName.Text;
                bool   success  = gen.saveDocument(document, path, fileName, fileName);
                if (success)
                {
                    int batchSize     = 1000;
                    var isCustomBatch = int.TryParse(tbBatchSize.Text, out batchSize);
                    if (isCustomBatch)
                    {
                        lblBatchSize.Text = string.Format("Batch Size {0}", batchSize);
                    }
                    var docList = gen.splitDocument(document, batchSize, true);

                    // update dictionary entry
                    MasterDictionary.UpdateEntry(fileName, true, 0);

                    int docCount = 1;
                    foreach (var doc in docList)
                    {
                        var name = fileName + "_" + docCount.ToString();
                        gen.saveDocument(doc, path, fileName, name);
                        docCount++;
                    }

                    lblProcess.ForeColor = System.Drawing.Color.Green;
                    lblProcess.Text      = "Done: Sucess!";
                }

                else
                {
                    lblFileUpload.ForeColor = System.Drawing.Color.Red;
                    lblFileUpload.Text      = "Upload Failed: File not stored to server";
                }
            }
            else
            {
                lblFileUpload.ForeColor = System.Drawing.Color.Red;
                lblFileUpload.Text      = "Upload Failed: File not found";
            }
        }