c# - Cast issue 'System.String' to type 'System.Web.UI.HtmlControls.HtmlInputFile' -


i have list box contains paths specific files in directory code reads , parses data , ohter stuff it. error unable cast object of type 'system.string' type 'system.web.ui.htmlcontrols.htmlinputfile' , i'm not sure how overcome this.

i have html input control of type file function directory path becuase directory not same. split postedfile.filename looks c:\temp\2013\03-2013\calib 100 29 mar 13\211jd13100.txton '\' string array. reasseble path in string adding array elements less last index , use param 'directory.getfiles(string) files in directory. again, don't know of anohter way directory information. anyway i'll post code, easier understand.

static public arraylist hif = new arraylist(); static string[] filepaths;   protected void btnaddfile_click(object sender, system.eventargs e)  {                     if (page.ispostback == true)     {                     stringbuilder sb = new stringbuilder();          string[] dirlocation = fileupload.postedfile.filename.split('\\');                     (int = 0; < dirlocation.length - 1; i++)         {             sb.append(dirlocation[i].tostring() + "\\");         }          // assenbled directory path being used files.         filepaths = directory.getfiles(sb.tostring());          (int = 0; < filepaths.length; i++)         {             hif.add(filepaths[i]);             lbxselectedfiles.items.add(filepaths[i]);         }     } } 

the method above loads listbox , filepath array file path , name. method below takes care of parsing before takes place need files , error happens foreach statement between parents ().

    foreach (system.web.ui.htmlcontrols.htmlinputfile hif in hif)     {         try         {             file = hif.postedfile;             streamreader data = new streamreader(hif.postedfile.inputstream);             pathfilename = file.filename.tostring();              directoryinfo directory = new directoryinfo(pathfilename);             directory = directory.parent.tostring();             .             .             .          }     } 

it looks "hif" arraylist of strings because adding file paths it.
because contains strings objects pulled out of use in loop variable strings.
line:

 foreach (system.web.ui.htmlcontrols.htmlinputfile hif in hif) 

should change

 foreach (string hif in hif) 

you have file path name , can use path open file , actual file object want work with.

cast specify doesn't work because hif doesn't have type of object in it.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -