Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 13, 2014 @ 13:20
    Fuji Kusaka
    0

    Converting to Int64 Failed

    Anyone can tell what is wrong here ? I cant convert to Int64 and my cshtml file keeps giving me an ugly error message.

     

    int Id = Convert.ToInt32(library.GetDictionaryItem("as"));
        var folder = new Media(Id);
    
         IEnumerable<Media> fd = folder.GetChildMedia();
            <div class="docCn-"> 
                <div id="docMnu-">
                  <ul>
                    @foreach(var p in fd){
                        @foreach(var p in fd){
    
                              var bytes = Convert.ToInt64(@p.getProperty("umbracoBytes").Value);
    
    
    
                    }
                    </ul>
                </div>
            </div>
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 13, 2014 @ 13:53
    Dennis Aaen
    0

    Hi Fujl,

    Is it meant that you should have two foreach loops or should you only have one like this:

    int Id = Convert.ToInt32(library.GetDictionaryItem("as"));
        var folder = new Media(Id);

        IEnumerable<Media> fd = folder.GetChildMedia();
            <div class="docCn-">
                <div id="docMnu-">
                  <ul>
                  @foreach(var p in fd){
    var bytes = Convert.ToInt64(@p.getProperty("umbracoBytes").Value);
                    }
                    </ul>
                </div>
            </div>

    /Dennis

     

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 13, 2014 @ 13:58
    Fuji Kusaka
    100

    Dennis i just happened to notice that some of the Media Items dont have any file attached to it and so fails.

    @if(p.getProperty("umbracoBytes").Value != String.Empty){
        var bytes = Convert.ToInt64(@p.getProperty("umbracoBytes").Value);
         var x = ((Math.Round(Convert.ToDecimal(@bytes) / 1048576, 1)).ToString() + "MB");
         var y = ((Math.Round(Convert.ToDecimal(@bytes) / 1024, 1)).ToString() + "KB");
        var z = (bytes>= 1048576)? x:y;
    
        <a href="@p.getProperty("newsUpload").Value" target='_blank'>
        Download File  <span class="sizedoc">&nbsp;&nbsp;{  @z  }</span>
        </a>
    }
  • Charles Afford 1163 posts 1709 karma points
    Feb 15, 2014 @ 23:39
    Charles Afford
    0

    You should really use Int64.TryParse  It wont throw an execption :)  Charlie

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies