/* This event is used to Import all suggestion in the form of CSV format*/ protected void btnUpload_Click(object sender, EventArgs e) { string BreedName, StrPet, StrStatus; int PetType; int Status; string Error = string.Empty; StoreFront ObjStoreFront = new StoreFront(); DataSet ds = new DataSet(); string strExtension; strExtension = Path.GetExtension(flUpload.Value); if (strExtension == ".CSV" || strExtension == ".csv") { string fileName; string line; string fileDir; StreamReader sr; fileDir = Server.MapPath("../StoreData/"); fileName = fileDir + "/" + Convert.ToString(DateTime.Now.Ticks) + ".txt"; flUpload.PostedFile.SaveAs(fileName); sr = File.OpenText(fileName); int recordCount = 0; while (sr.Peek() != -1) { line = sr.ReadLine(); string[] recordArray; char[] splitter = { ',' }; recordArray = line.Split(splitter); if (recordArray[0].Replace(",", "") == "BreedName") { continue; } else { if (recordArray.Length == 3) { BreedName = (recordArray[0].Trim().Replace('#', ',')); StrStatus = recordArray[1].Trim().Replace('#', ','); if (StrStatus == "Active") { Status = 1; } else if (StrStatus == "Inactive") { Status = 0; } else { Status = 1; } StrPet = (recordArray[2].Trim().Replace('#', ',').ToLower()); if (StrPet == "cat") { PetType = 0; } else { PetType = 1; } int Dup = ObjStoreFront.AddBreedExcel(BreedName, PetType, Status); if (Dup == 0) { if (Error == "") { Error = "Duplicate Breed name - " + BreedName; } else { Error = Error + ", " + BreedName; } } recordCount++; } else { Error = "coloumn count does not match"; } } } if (Error == "") { SuccesfullMessage("Record Added successfully."); } else { ErrMessage(Error); } } else { ErrMessage("Sorry, File Format Not Supported. You can upload files in .csv format only."); } BindGrid(PetTypeID); }