vb.net - How to check for empty file in the folder? -


i have code updates sql database using files in folder , delete them after update giving me exception whenever blank file found in folder. gives error " object reference not set instance of object" . want before processing each file need check each file if blank delete otherwise process it. code :

any appreciated.

dim dirinfo5 directoryinfo         dim allfiles5() fileinfo         dirinfo5 = new directoryinfo("e:\update\")         allfiles5 = dirinfo5.getfiles("*.csv")         thread.sleep(1000)         if allfiles5.length <> 0             try                 each fl5 fileinfo in allfiles5                     'msgbox(fl.fullname.tostring())                     dim con sqlconnection = new sqlconnection(sql_con2)                     dim sr streamreader = new streamreader(fl5.fullname)                     dim line string = sr.readline                     dim value() string = line.split(microsoft.visualbasic.chrw(44))                     dim dt datatable = new datatable                     dim row datarow                     each dc string in value                         dt.columns.add(new datacolumn(dc))                     next                      while not sr.endofstream                         value = sr.readline.split(microsoft.visualbasic.chrw(44))                         if (value.length = dt.columns.count)                             row = dt.newrow                             row.itemarray = value                             dt.rows.add(row)                         end if                      end while                     dim bc sqlbulkcopy = new sqlbulkcopy(con.connectionstring, sqlbulkcopyoptions.tablelock)                     bc.destinationtablename = "[db].[dbo].[ldata]"                     bc.batchsize = dt.rows.count                     con.open()                     bc.writetoserver(dt)                     bc.close()                     con.close()                     sr.close()                     system.io.file.delete(fl5.fullname)                     sr.dispose()                 next             catch ex exception                 msgbox(ex.message)             end try         end if 

you can use file.readalltext method: returns string can check .length.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -