日期:2014-05-20  浏览次数:21195 次

startIndex不能大于字符长度,谁能告诉我这个异常该如何改
string filename = filepath.Substring(ServerPath.Length);

ServerPath是从数据库上读取出来的字符串:
ServerPath=C:\Documents and Settings\jeany\桌面\WindowsApplication1

然后呢还有一个值是ServerPath=F:\存储过程\存储过程

当我取ServerPath=F:\存储过程\存储过程时不爆错,但是当我取
ServerPath=C:\Documents and Settings\jeany\桌面\WindowsApplication1时
就会发生startIndex 不能大于字符串长度。
参数名: startIndex错误
谁能告诉我该怎么改啊!


------解决方案--------------------
string filename = filepath.Substring(ServerPath.Length);
这里filepath是什么值???
如果长度小于ServerPath肯定会报错的。
------解决方案--------------------
你这个和filepath有关系撒

filepath的长度小于ServerPath的长度

filepath.Substring(ServerPath.Length);
这样就会报你说的错了

建议你跟踪一下filepath的值