Copied to clipboard

Flag this post as spam?

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


  • Danny Blatant 91 posts 358 karma points
    Oct 20, 2014 @ 18:22
    Danny Blatant
    0

    Errors Saving an Image from byte[] (from SQL Server)

    Hi all,

    I do hope someone can supply me with a nice quick and consise answer to my issue...

    In a nutshell, I'm getting the error :

    An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code Additional information: startIndex cannot be larger than length of string.

    within this function on the SetValue line :

        private bool CacheImage(byte[] bytes, string filename){
            //get the Media Service and create the node
            IMediaService _mediaService = ApplicationContext.Current.Services.MediaService;
            IMedia _mediaItem = _mediaService.CreateMedia(filename, 1159, "Image");
            //load the bytes as a stream and apply to the node
            MemoryStream mStream = new MemoryStream(bytes);
            mStream.Position = 0;
            _mediaItem.SetValue("umbracoFile", filename, mStream);
            //save the media node
            _mediaService.Save(_mediaItem);
            return true;
        }
    

    I've seen a bunch of posts about similar problems but nothing seems to supply me with a 100% solution. Can anyone give me a hint?

    One question that springs to mind is 'what string'? we're dealing with a stream here right??

    Thanks in advance

    Danny "Blatant"

  • Danny Blatant 91 posts 358 karma points
    Oct 20, 2014 @ 19:12
    Danny Blatant
    100

    Nevermind, clue is in the error...

    It's not a problem with the stream, but the filename (2nd parameter). It requires the extension on the filename (of course) but the saved filename I was using was devoid of it!

Please Sign in or register to post replies

Write your reply to:

Draft