Pages

Showing posts with label sharepoint. Show all posts
Showing posts with label sharepoint. 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

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.

Saturday, November 30, 2013

How to bind LINQ data to DataGrid

Let's assume we have a Web Service which will return the results as an object for IN and OUT data records.
The following will explain how to use LINQ to query and then bind the results to the asp:DataGrid


C# code:
//query to get currunt month data ordered by LOCAL_TIME then TYPE
 var thisMonthData = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.OrderByDescending(o2 => o2.TYPE)
.Where(m => m.DATE.Substring(0, 6)
== DateTime.Today.ToString("yyyyMM", arCulture));
 
//Bind Data
eDataGrid.DataSource = thisMonthData;
eDataGrid.DataBind();
 
//query to get currunt month data ordered by LOCAL_TIME for TYPE=IN
var thisMonthDataIn = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.Where(r => r.TYPE == "IN")
.Where(m => m.DATE.Substring(0, 6) == DateTime.Today.ToString("yyyyMM", arCulture));
 
//Bind Data
eINDataGrid.DataSource = thisMonthDataIn;
eINDataGrid.DataBind();
 
//query to get currunt month data ordered by LOCAL_TIME for TYPE=OUT
var thisMonthDataOut = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.Where(r => r.TYPE == "OUT")
.Where(m => m.DATE.Substring(0, 6) == DateTime.Today.ToString("yyyyMM", arCulture));
 
//Bind Data
eOUTDataGrid.DataSource = thisMonthDataOut;
eOUTDataGrid.DataBind();

 

Markup:


                     
<asp:DataGrid CssClass="gvTbl" ID="eINDataGrid" runat="server"  AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>
 
<asp:DataGrid CssClass="gvTbl" ID="eOUTDataGrid" runat="server"  AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>
<asp:DataGrid CssClass="gvTbl" ID="eDataGrid" runat="server"  AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>

Tuesday, September 3, 2013

Passing url parameters to webpart in SharePoint

To pass the URL parameters to a webpart page in SharePoint, we can't use the "Page Viewer" webpart because it does not allow us to use the parameters in the URL.

So we use teh "Content Editor" webpart since it allows us to embed javascript code in it. We can then use an "iframe" with a generated URL from a JavaScript with URL parameters from the webpart page's URL.

First, create a webpart page, then insert a content editor webpart in it with the following code:
<script type="text/javascript">
    function getQueryStringRegExp(name) {
        var reg = new RegExp("(^|\\?|&)"
+ name + "=([^&]*)(\\s|&|$)", "i");
        if (reg.test(location.href))
return unescape(RegExp.$2.replace(/\+/g, " "));
        return "";
    }
    document.write("<iframe src='http://www.sitename.com/default.aspx?param1="+ getQueryStringRegExp('param1') + "' width=100% height=100%></iframe>");
</script>

The function getQueryStringRegExp is used to retrieve the parameter value from the page url.

Referece:


Monday, October 31, 2011

How to find a control in a DataList?


How to find a control in a DataList?

Because DataList is databound control which repeats its item template as many times as there are rows in the data source. Therefore contents of
So, to locate a specific Label control, you’d first need to locate a specific dataList item, and run FindControl to it (for example DataList1.Items(0).FindControl(“label2″) ), and considering the databound nature, you’d probably want to loop through all items in the DataList’s Items collection to get to the every Label control.

VB
For Each dli as DataListItem in DataList1.Items
Dim currLbl As Label=DirectCast(dli.FindControl(“label2″),Label)
    '…
Next


C#
foreach(DataListItem dli in DataList1.Items)
{
Label currLbl = (Label) dli.FindControl(“label2″);
//…

}

Saturday, March 7, 2009

customize sharepoint List forms

SharePoint has always been good for basic business forms. A custom SharePoint list can be configured to collect any type of data and SharePoint automatically generates the forms for adding new items, editing items and viewing items. In SharePoint 2007, the workflow capabilities make SharePoint lists an even more attractive foundation for basic business forms.

By default, most SharePoint lists and libraries include forms that are displayed when you want to add an item to, or edit or display an item in, that list or library. With Microsoft Office SharePoint Designer 2007, you can easily replace any of the default list forms with a custom list form that you design to meet your specific needs. After you create the custom list form, including the fields that you want, you can make the new form the default form for that list or library.

In order to manage the data you collect from the form submitters, you will often have a few extra columns (e.g. status, notes, etc.) that you don't want the user to fill in when submitting the form. Using SharePoint Designer you can create a customised version of the form for adding new items that does not have your extra management columns on it.

  1. Open your site in SharePoint Designer.

  2. Browse to your list and open the 'NewForm.aspx' web form.

  3. Go File &gt; Save As... and give the form a new name such as 'NewForm2.aspx'.

  4. Delete the default List Form Web Part from the page.

  5. Go Insert &gt; SharePoint Controls &gt; Custom List Form.

  6. In the List or Document Library Form dialog, select the appropriate list, content type and type of form.

  7. Click OK and a new Data Form Web Part is added with controls representing all the fields from the list.

  8. In the newly added Data Form Web Part, delete the rows containing fields not to be shown to the user (ensure that fields being removed are not required fields without default values as this would prevent the user from submitting the form).
    At this point, you can do other customisation such as rearranging the fields or add styles if you wish.

  9. Save the site.

  10. To give users access to your new form, publish a link to the NewForm2.aspx page. By using the Source query string parameter you can direct users back to where they came from after submitting the form.
    For example, if you publish the link on 'http://portal.example.com' then the URL to the form would be 'http://portal.example.com/Lists/YourList/NewForm2.aspx?Source=http://portal.example.com'.