Pages

Showing posts with label solved. Show all posts
Showing posts with label solved. Show all posts

Monday, March 16, 2015

How-To remove HTMLTags to display plain text using XSLT


In this post i will be showing how you can use XSLT to strip out HTML tags from HTML data sources (Rss, sharepoint list item, database field ... etc) and display plain text

Below is the function to remove HTML tags:

  <xsl:template name="removeHtmlTags">
    <xsl:param name="html"/>
    <xsl:choose>
      <xsl:when test="contains($html, '&lt;')">
        <xsl:value-of select="substring-before($html, '&lt;')"/>
        <!-- Recurse through HTML -->
        <xsl:call-template name="removeHtmlTags">
          <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$html"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

You can see that the function name is removeHtmlTags which accepts one argument / parameter named as html which is my Description field that contains HTML Tags.
Logic is simple, its a recursive function which finds for '&lt;' that is '<' means starting of any HTML Tag and take out the substring after this '<' Tag using substring-before() function as substring-before($html, '&lt;') and again call the function with the rest of the string left after  '&gt;' that is '>' Tag.

This is how this function will be called:

    <xsl:template name="RssCell">
        <xsl:variable name="pureText">
            <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="DescriptionField" />
            </xsl:call-template>
        </xsl:variable>

        <div height='40' class='blog_text'>
            <xsl:value-of disable-output-escaping="yes"  select="substring($pureText, 0, 175)"/>
        </div>
    </xsl:template>

One Variable is declared as pureText. removeHtmlTags() function will strip out the HTML Tags and return the Plain Text values in this pureText variable.
I am passsin DescriptionField that is my DB Field with HTML Tags.

Finally, I am displaying max 175 chars of Plain Text as substring($pureText, 0, 175) inside a DIV.

Thats It!


Reference

Thursday, October 9, 2014

How To: Using asp.net Validation Controls to be used with Custom Usercontrols

To use asp.net Required Field Validator, Range Validator ..., etc you must have a ValidationProperty attribute that specifies which value from your custom user control the validation controls to be validated validate.

So.. In your custom usercontrol  class add the ValidationProperty attribute and a property that returns the data in a format that is suitable for the validation controls.

Usercontrol
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="jpTimeChooser35UC.ascx.cs"
    Inherits="jpTimeChooser35UC" %>
<table cellpadding="0" cellspacing="0" dir="rtl" style="text-align: center;">
            <tr>
                <td>
                    <asp:TextBox ID="minTxtBx" MaxLength="2" runat="server" Width="30px" CssClass="tblField" Text="30" Style="text-align: center" >
                    </asp:TextBox>
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="hourTxtBx" runat="server" MaxLength="2" Width="30px" CssClass="tblField" Text="07" Style="text-align: center" >
                    </asp:TextBox>
                </td>
                <td style="padding-right: 5px">
                    <asp:DropDownList ID="timeDDL" CausesValidation="false" Font-Size="10pt" Width="50px" runat="server" CssClass="tblField">
                        <asp:ListItem Selected="True">ص</asp:ListItem>
                        <asp:ListItem>م</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr style="color: Gray; text-align: center; padding: 0px; font-family: Tahoma; font-size: 9pt;">
                <td>
                    دقيقة
                </td>
                <td></td>
                <td>
                    ساعة
                </td>
            </tr>
        </table>
        
 
Preview 



Usercontrol's Code:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
[ValidationProperty("TimeValue")]
public partial class TmeChooser35UC : System.Web.UI.UserControl
{
    public object TimeValue
    {
        get
        {
            string TimeString = this.ucHours+":"+this.ucMinutes+" "+this.ucTime;
            if (TimeString == ": ص")
            {
                return "";
            }
            else
            {
                return TimeString;
            }
        }
    }
    public string ucMinutes
    {
        get { return minTxtBx.Text.ToString(); }
        set { minTxtBx.Text = ucMinutes; }
    }
    public string ucHours
    {
        get { return hourTxtBx.Text.ToString(); }
        set { hourTxtBx.Text = ucHours; }
    }
    public string ucTime
    {
        get { return timeDDL.SelectedValue.ToString(); }
        set { timeDDL.SelectedValue = (timeDDL.Items.Contains(new ListItem(ucTime))) ? timeDDL.SelectedValue = ucTime : ""; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

 
and then use a RequiredFieldValidator and the Usercontrol  in a WebPage 
<%@ Page Language="C#" Culture="ar-sa" Title="Untitled Page" %>
<%@ Register Src="jpTimeChooser35UC.ascx" TagName="jpTimeChooser35UC"   TagPrefix="uc1" %>

<uc1:jpTimeChooser35UC ID="fromTimeUC"  runat="server" />
<asp:RequiredFieldValidator runat="server"ErrorMessage="ERROR_MESSAGE" 
ID="RequiredFieldValidator1" ControlToValidate="fromTimeUC" 
SetFocusOnError="True"></asp:RequiredFieldValidator>

<asp:Button ID="submitBtn" runat="server" Text="submit"
CssClass="tblButtons" Visible="true" OnClick="submitBtn_Click"/>
Preview 


  













That's It .. Hope this was helpful :)

Reference: Microsoft Support #310082

Saturday, August 16, 2014

How To: Load SharePoint web part User Control Inside another SharePoint web part without C# Coding

simple way to Load SharePoint web part User Control Inside another  SharePoint web part without C# Coding is done by :

  1. registering the user control
    <%@ Register src="webPartUC.ascx" tagname="webPartUC" tagprefix="uc" %>

  2. loading the user control <uc:webPartUC ID="webPartUC1" runat="server" />
if you wanted to pass webpart properties.. all you have to do is to specify the values as follows:
<uc:webPartUC ID="webPartUC1" LabelText="TEXT" runat="server" />

if you wanted to pass webpart properties from within a DataList Control Items .. all you have to do is to specify the values as follows making sure to add the below line inside the DataList:

 <asp:DataList ID="usersDL" runat="server" Width="100%" >
   <ItemTemplate>
         <uc:webPartUC ID="webPartUC1"
              LabelText=<%# Eval("userName")%> runat="server" />

    </ItemTemplate>
 </asp:DataList>


Thats it :)

    

Saturday, May 17, 2014

Embed PDF in HTML Page


To Embed PDF files in HTML Page You can use below snippet of code, It works in most browser versions (Chrome, Firefox, IE,... ).

if it is not supported, it shows the message "The PDF cannot be displayed."

<div id="pdf">
<object width="900" height="1000" type="application/pdf" data="/filepath/filename.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0" id="pdf_content">
<p>The PDF cannot be displayed. <a href="/filepath/filename.pdf" target="_top">download</a>.</p>
</object>
</div>

Above snippet of code sets the zoom to 85%, removes scrollbars, toolbars and nav panes.

Hope it helps J

SOLVED: 'Download Unsuccessful' Error Notification in Android

Problem:
For a while, it has been an exhausting issue to fix with website users that when trying to download pdf files through the android stock browser or android chrome browser or some other browsers.. 
they get a 'Download Unsuccessful' notification.

Solution:
Now it got clear once understood that android file type association requires certain applications to open specific file types..

As long as the file type you are trying to open\download (pdf, rar, zip, word, …) is unknown or not associated with an existing application.. it won't open\download..

So all you need to do is :
·        If you want to open\download pdf file, install Acrobat Reader first through android PlayStore.
·        If you want to open\download rar, zip etc.. download and install Archidroid from android PlayStore.
·        … and so on.

Conclusion:  
At the end it's not an issue in your website you have to fix.. just file association needs to be fixed in users devices.. that's all J

Tuesday, March 25, 2014

SOLVED: SharePoint Designer Workflow updates doesn't work!!

This time we faced an issue where even after updating workflow steps conditions and actions it doesn't seem to be applied on the server...
The solution was simple as it seems that SharePoint Designer saves local copies from your servers, and although everything seems OK, this prevents it from updating the workflow ..
To solve this issue:
  1. Close SharePoint Designer
  2. Go to
    %LOCALAPPDATA%\Microsoft\WebsiteCache
    Or, on older versions of windows:
    C:\Documents and Settings\%USER%\Local Settings\Application Data\Microsoft\WebSiteCache
  3. Delete either (choose one, based on how annoyed you are by now):
    1. All folders.
    2. The folder that "looks most like your site" (can be more than one: site, site(1), etc, and should be the bottom level site, not the root site)
    3. The relevant DLL in that folder.
  4. Start SharePoint Designer, save the workflow again, it should be ok.