Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Markus 33 posts 58 karma points
    Aug 07, 2012 @ 10:04
    Markus
    0

    Upload media to virtual directory: "startIndex cannot be larger than length of string"

    I downloaded Umbraco 4.8 and unpacked it on my box, created a site in IIS (.NET 4.0, integrated), everything works fine.

    The I deleted the /media folder and added a virtual directory pointing to an other directory on the disk instead.

    Whenever I try to upload an image, I get the following error:


    startIndex cannot be larger than length of string.
    Parameter name: startIndex

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string.
    Parameter name: startIndex

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [ArgumentOutOfRangeException: startIndex cannot be larger than length of string.
    Parameter name: startIndex]
       System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +12687407
       umbraco.cms.businesslogic.Files.UmbracoFile.Save(Byte[] file, String fullFileName) +211
       umbraco.cms.businesslogic.Files.UmbracoFile.Save(Stream inputStream, String fullFileName) +173
       umbraco.cms.businesslogic.datatype.FileHandlerData.set_Value(Object value) +459
       umbraco.editorControls.uploadField.Save() +678
       umbraco.controls.ContentControl.saveClick(Object Sender, ImageClickEventArgs e) +185
       System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +187
       System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +165
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707
    



    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

    I tried the following:

    • Adding umbracoMediaPath to the web.config
    • Adding all kinds of permissions to the media directory 
    • Setting ResolveUrlsFromTextString to false or true

    I found this issue un codeplex: http://umbraco.codeplex.com/workitem/30937 but though I get the same error, my problem is not related to the browser.

    Some people mentioned that I should use the web installer, but I don't see why that should change anything.

    Is there a web.config setting I am missing? What are the steps to place the media outside of the web site root?

     

  • Markus 33 posts 58 karma points
    Aug 07, 2012 @ 15:44
    Markus
    0

    Looks like I can't update my post: Still not working, but adding a symbolic link

    mklink /D media c:\mymedia

    seems to work - I'm not yet sure what other problems this will create...

     This may be linked to this issue: http://umbraco.codeplex.com/workitem/30947

     

  • Markus 33 posts 58 karma points
    Sep 17, 2012 @ 21:25
    Markus
    0

    Codeplex issues are gone, the issue was kindly migrated to the new issuetracker: http://issues.umbraco.org/issue/U4-626

    Looks like the code responsible for this does not exists anymore. I'll check as soon as I get to upgrade a project...

  • Avraham Kahana 22 posts 56 karma points
    Apr 26, 2015 @ 16:39
    Avraham Kahana
    0

    In case others can benefit... I was facing this exception in trying to add a media via IMediaService.CreateMedia()... and IMedia.SetValue(). Set Value was throwing "startIndex cannot be larger than length of string". My scenario is I am receiving files attached in http requests, and am looping over this.UmbracoContext.HttpContext.Request.Files to create Medias out of them in Umbraco. The stream I was providing to IMedia.SetValue was this.UmbracoContext.HttpContext.Request.Files["myFile"].InputStream.

    I could not figure out what the problem was. But - the process works if I use one of the other overloads of IMedia.SetValue. More specifically, the one that receives a HttpPostedFileBase object.

    Hoping you could benefit from this too.

  • Alain 73 posts 520 karma points c-trib
    May 19, 2015 @ 13:45
    Alain
    2

    Avraham Kahana,

    I got the same issue (Umbraco 7.2.4) and was wondering why the method

    SetValue(this IContentBase content, string propertyTypeAlias, string fileName, Stream fileStream)

    sometime works properly and other times throws the exception "startIndex cannot be larger than length of string"

    After digging a little bit in the Umbraco source code it seems that the problem is the filename. The filename needs to have an extesion, if not so then the following statement will fail:

    https://github.com/umbraco/Umbraco-CMS/blob/813f1a1f2dd83464ab557c9be8023ff13f255fe6/src/Umbraco.Core/Models/ContentExtensions.cs (line 524)

    var extension = Path.GetExtension(filename).Substring(1).ToLowerInvariant();

    I hope that helps someone.

  • Avraham Kahana 22 posts 56 karma points
    May 19, 2015 @ 13:48
    Avraham Kahana
    0

    Thanks for sharing Alain!

  • Ben McKean 272 posts 549 karma points
    Oct 14, 2015 @ 14:36
    Ben McKean
    0

    Helped me too, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft