Start index cannot be larger than the length of the string

asp.net-mvc-4 c# entity-framework

Question

I'm trying to check if a foldername doesn't have a extension.
Because I want to change the name of the folder.
But you can also change the name of a file.

And I get this error:

"startIndex cannot be larger than length of string.\r\nParameter name: startIndex"}

By this line:

 string newFilenameExtension = Path.GetExtension(model.FileName.Trim()).Substring(1);

How to check if the foldername has no extension?

1
0
5/23/2016 9:18:08 AM

Accepted Answer

You should have code in following way -

string newFilenameExtension = Path.GetExtension("Sample".Trim());
string extn = string.Empty;

if (!String.IsNullOrWhiteSpace(newFilenameExtension))
{
      extn = newFilenameExtension.Substring(1);
}

if(!String.IsNullOrWhiteSpace(extn))
{
      // Use extn here
}
1
6/19/2015 7:38:10 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow