1

Closed

ArgumentOutOfRangeException when parsing filepaths during upload

description

Reference : https://github.com/leniel/elFinder.Net/issues/2
When I try to upload a file it is giving me an error like the one below.
There seems to be a problem with the way you are using the filepaths in CreateDTO

string parentPath = info.Directory.FullName.Substring(root.Directory.FullName.Length);

info -> points to the info of uploaded file
root -> points to the rootDir of the elFinder

why are you trying to take the substring from one with the index value from another?
should it not be just info.Directory.FullName for the parent path?

root.Directory.FullName = "C:\Users\Manish\Downloads\elFinder.Net-master\elFinder.Net-master\elFinder.Net.Web\Files\MyFolder"
info.Directory.FullName = "C:\Users\Manish\Documents\Dev\elf"

I am not entering path anywhere explicitly right now. Just chose a file in the system to upload.

System.ArgumentOutOfRangeException was unhandled by user code
HResult=-2146233086
Message=startIndex cannot be larger than length of string.
Parameter name: startIndex
Source=mscorlib
ParamName=startIndex
StackTrace:
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex)
at ElFinder.DTO.DTOBase.Create(FileInfo info, Root root) in c:\Users\Manish\Downloads\elFinder.Net-master\elFinder.Net-master\elFinder.Net\DTO\DTOBase.cs:line 67
at ElFinder.FileSystemDriver.ElFinder.IDriver.Upload(String target, HttpFileCollectionBase targets) in c:\Users\Manish\Downloads\elFinder.Net-master\elFinder.Net-master\elFinder.Net\Facade\FileSystemDriver.cs:line 430
at ElFinder.Connector.Process(HttpRequestBase request) in c:\Users\Manish\Downloads\elFinder.Net-master\elFinder.Net-master\elFinder.Net\Facade\Connector.cs:line 149
at elFinder.Net.Web.Controllers.FileController.Index(String folder, String subFolder) in c:\Users\Manish\Downloads\elFinder.Net-master\elFinder.Net-master\elFinder.Net.Web\Controllers\FileController.cs:line 37
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.b__41()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.b__49()
InnerException:
Closed Sep 25, 2014 at 2:34 PM by EvgenyNoskov

comments

codetantra wrote Jun 6, 2013 at 9:02 AM

The problem is in the FileSystemDriver.

Line 377 string path = Path.Combine(dest.Directory.FullName, file.FileName);

should be
Line 377 string path = Path.Combine(dest.Directory.FullName, Path.GetFileName(file.FileName));

EvgenyNoskov wrote Jun 16, 2013 at 5:54 PM

Can you, please, provide the file name of uploaded file? Is it something special? What value you get in 'file.FileName'? Is it the full path or just a file name with extension?

leniel wrote Jul 7, 2013 at 5:39 AM

Evgeny,

You can see the paths here:

root.Directory.FullName = "C:\Users\Manish\Downloads\elFinder.Net-master\elFinder.Net-master\elFinder.Net.Web\Files\MyFolder"

info.Directory.FullName = "C:\Users\Manish\Documents\Dev\elf"

gcarrier wrote Sep 10, 2014 at 10:28 PM

Now September 2014. Looks like the proposed change to use Path.GetFileName( ) is in the latest ElFinder.Net 0.95 September 2013 by Evgeny, so Status should be changed to Resolved.

wrote Sep 25, 2014 at 2:34 PM