Skip to content Skip to sidebar Skip to footer

2sxc | Removing File Path By Trimming W/ Javascript Method

I have the following file path displaying: And I want to display only file name 'Doc1' (minus path and extension). I have tried unsucessfully the following and would appreciate a

Solution 1:

You're actually just using Substring the wrong way. You probably want

publicstaticstringSplitWord(string text, int length)
{
    int slash = text.LastIndexOf("/");
    int dot = text.LastIndexOf(".");
    return text.Substring(slash + 1, dot - slash);
}

Give it a try - might need another +1 or -1 on one of the values, but that should do the trick.

Solution 2:

You were right (with a minor tweak as you said)....

I also tried to integrate a date field so no matter what date a user selects, it will always display current date (of upload).

Is there a string to enter into the default value for datepicker field to display 'Today' as opposed to user having to click it in picker? (mixing questions again :) )

@functions{

    publicstaticstringSplitWord(string text,DateTime datetime)
    {

        int slash = text.LastIndexOf("/");

        int dot = text.LastIndexOf(".");

        dot--;

        var data = text.Substring(slash + 1, dot - slash);

        return data + " " + datetime.ToLongDateString();

    }

}
@{
    var all = AsDynamic(App.Data["CatFilter"]);
}
<ol>
    @foreach (var q inAsDynamic(App.Data["CatFilter"]))
    {
    <li class="sc-element faq-set faq-setOne" data-tags="@String.Join(",", ((List<DynamicEntity>)q.Categories).Select(a => AsDynamic(a).EntityId))">
        @q.Toolbar @Edit.Toolbar(actions: "edit,new", contentType: "CatFilter")
        <a class="faq-question" style="cursor: pointer">
            @if(!String.IsNullOrEmpty(q.LinkText))
            {

        @q.LinkText
            } else {
                @SplitWord(q.Link,q.Date);
            }
        </a>
    </li>
    }
</ol>

UPDATE

This is another template of yours that I applied the SplitWord function to but results in an error. I can't see any difference from code which works fine above.

This is the code I'm referring to:

@usingToSic.SexyContent

@* put all necessary link/script tags here *@
@RenderPage("_Shared - Assets.cshtml", new { parts = "styles,scripts,height"})

@{
    // get helper commandsvarHelpers = CreateInstance("_Helpers.cshtml");
}
    @functions{
        publicstaticstringSplitWord(string text)
        {
            int slash = text.LastIndexOf("/");
            var data = text.Substring(slash + 1);
            return data;
        }
    }
<div class="clearfix">
    <divclass="co-container-outer"><divclass="co-container-inner row co-navigation co-navigation-@(Dnn.Module.ModuleID) co-navigation-icon co-navigation-text">
            @foreach (var Content in AsDynamic(Data["Default"].List))

            {
                var linkInfo = Helpers.LinkInfos(Content.Link, Content.Window, Content.Icon);

                <divclass="col col-xs-12 col-sm-6 col-md-4 sc-element">
                    @Edit.Toolbar(Content)
                    @if(linkInfo.Found)
                    {
                        @:<aclass="co-link-box"title="@Content.Title"href="@Content.Link"target="@linkInfo.Window">
                    }
                    <divclass="row"><divclass="col-xs-2 text-center"><iclass="co-icon text-primary co-icon fa @linkInfo.Icon"aria-hidden="true"></i></div><divclass="col-xs-10"><h3>@Content.Link</h3><divclass="co-ul"><aclass=""title="@Content.Link"href="@Content.SubpageOne">@SplitWord(Content.SubpageOne)</a></div>
                            @if(!String.IsNullOrEmpty(Content.Link))
                            {
                                <ahref="@Content.Link)"><spanclass="text-primary"><!--<i class="glyphicon glyphicon-chevron-right text-primary" aria-hidden="true"></i>&nbsp;-->
                                    @Content.LinkText</span></a>
                            }
                        </div></div>
                    @if(linkInfo.Found)
                    {
                        @:</a>
                    }
                </div>
            }
        </div></div>
</div>

<script>/* Call syncHeightResponsive here - makes sure that sync height also works after ajax reload */
    $(".co-navigation-@(Dnn.Module.ModuleID) .col").syncHeightResponsive();
</script>

Post a Comment for "2sxc | Removing File Path By Trimming W/ Javascript Method"