I think in your particular case you are NOT trying to get IndexOf ... Instead, you need to use 0 because you are trying to create a key based on the file name if you understand correctly:
`ddlResources.Items.Add(new ListItem(file.Substring(0, file.LastIndexOf(".")), file ));`
Also, you have "{}" there, as in the new ListItem {...}, which will also throw a syntax error ... Anyway, look ..
source share