c# - I want to Optimize upload time of Excel file records saving to Database in asp.net mvc -


i want upload excel file of record 2500. process takes time more 5 minutes approximate. want optimize less minute maximum. find best way of optimization of code. using dbgeography location storing. file uploaded , save data properly. working find need optimization.

public actionresult upload(httppostedfilebase fileupload)     {         if (fileupload.contentlength > 0)         {             string filename = path.getfilename(fileupload.filename);             string ext = filename.substring(filename.lastindexof('.'));             random r = new random();             int ran = r.next(1, 13);             string path = path.combine(server.mappath("~/app_data/uploads"), datetime.now.ticks + "_" + ran + ext);             try             {                 fileupload.saveas(path);                 processcsv(path);                 viewdata["feedback"] = "upload complete";             }             catch (exception ex)             {                 viewdata["feedback"] = ex.message;             }         }          return view("upload", viewdata["feedback"]);     } 

here other method file uploaded , save database..

private void processcsv(string filename)     {         regex r = new regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");         streamreader sr = new streamreader(filename);         string line = null;         string[] strarray;         int iteration = 0;         while ((line = sr.readline()) != null)         {                  if (iteration == 0)                 {                     iteration++;                     continue;                   //because heading                 }                  strarray = r.split(line);                 storelocation store = new storelocation();                 store.name = strarray[0];                 store.storename = strarray[1];                 store.street = strarray[2];                 store.street2 = strarray[3];                 store.st_city = strarray[4];                 store.st_st = strarray[5];                 store.st_zip = strarray[6];                 store.st_phone = strarray[7];                 store.office_phone = strarray[8];                 store.fax = strarray[9];                 store.ownership = strarray[10];                 store.website = strarray[11];                 store.retailer = check(strarray[12]);                 store.warehousedistributor = check(strarray[13]);                 store.onlineretailer = check(strarray[14]);                 string temp_add = store.street + "," + store.st_city;                 try                 {                     var  point = new googlelocationservice().getlatlongfromaddress(temp_add);                     string points = string.format("point({0} {1})", point.latitude, point.longitude);                     store.location = dbgeography.fromtext(points);//lat_long                 }                 catch (exception e)                 {                     continue;                 }                 db.storelocations.add(store);                 db.savechanges();           } 

the obvious place start external call geo location service, looks doing each iteration of loop. don't know service, there way can build list of addresses in memory, , hit once multiple addresses, go , amend records need update?


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -