Thursday 12 September 2013

jQuery Tabs - multiple rows

<script>
$(function() {
$( "#tabs" ).tabs();
})

$(function() {
$( "#tabs2" ).tabs();
});
</script>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Title name 1</a></li>
<li><a href="#tabs-2">title name 2</a></li>
<li><a href="#tabs-3">title name 3</a></li>
</ul>
<div id="tabs-1">
<p> Your info 1 </p>
</div>
<div id="tabs-2">
<p> your info 2 </p>
</div>
<div id="tabs-3">
<p> your info 3 </p>
</div>
</div>
<div id="tabs2">
<ul>
<li><a href="#tabs-4">Title name 4</a></li>
<li><a href="#tabs-5">title name 5</a></li>
<li><a href="#tabs-6">title name 6</a></li>
</ul>
<div id="tabs-4">
<p> Your info 4 </p>
</div>
<div id="tabs-5">
<p> your info 5 </p>
</div>
<div id="tabs-6">
<p> your info 6 </p>
</div>

</div>



or




.tabSplit { clear: both; }

<div id="tabs">
      <ul>
            <li><a href="#tabs-1">Title name 1</a></li>
            <li><a href="#tabs-2">Title name 2</a></li>
            <li class="tabSplit"><a href="#tabs-3">Title name 3</a></li>
            <li><a href="#tabs-4">Title name 4</a></li>
      </ul>
      ...

Friday 13 July 2012

Using the AJAX Control Toolkit in SharePoint

The ASP.NET AJAX Control Toolkit provides a set of sample controls and extenders that makes it a snap to spice up your web site with rich functionality. Think about the Control Toolkit as a bunch of sexy controls which use the ASP.NET AJAX extensions, plus a framework to create a new even sexier control on your own. In this post I'll describe how you can make use of the Control Toolkit in your SharePoint 2007 sites, for example by using the SmartPart.

Actually SharePoint doesn't differ from any other ASP.NET web site to use the Control Toolit, there are only three things that you need to do:

  1. Make sure SharePoint has access to AjaxControlToolkit.dll
    You can do this in two ways: either you deploy the assembly to the Global Assembly Cache (GAC) or you put in the \BIN folder of the SharePoint site's folder.

  2. Add an assembly reference in the web.config (note: for the future versions of the Control Tookit, the version number can change!):
    <assemblies>
    ...
    <add assembly="AjaxControlToolkit, Version=1.0.10201.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
    ....
    </assemblies>

  3. Add the tagprefix for the Control Toolkit in the web.config:
    <controls>
    ...
    <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
    ....
    </controls>


That's it! Now you can make use of the Control Toolkit coolness in your SharePoint 2007 sites! If you want to test if the Control Toolkit is working on your installation: I've upload a very small example to CodePlex.

InfoPath 2010 – Error “The amount of data that was returned by a data connection has exceeded the maximum limit that was configured by the server administrator.”

the error message on the screen, (below is an example)

DataConnErr


So lets talk thru the issue.


Problem


So they are using SharePoint 2010 Enterprise, and InfoPath Form Services.  The form in question is a monster custom InfoPath form.  It uses every custom option you can think of, with popup tool tips, custom controls, workflows tied it, and has Java and .NET running some logic.  Generally a “WHY, WHY WOULD YOU DO IT” form.


The size of the form can also be huge when saved with about 5 different Rich Text fields that customers and Support folks put links, images, etc. in.  I have seen forms go in 12 mb in size. 


When they attempt to load these files, or open a view with all these files in it (7500 list items) the are getting that lovely warning.




“The amount of data that was returned by a data connection has exceeded the maximum limit that was configured by the server administrator. Form elements, such as drop-down lists may be blank.”



Solution


So this is an easy fix.


Go to Central Administration > General Application Settings > Configure InfoPath Form Services


Down on the page you are going to see a Data Connection Response Size.  It is defaulted to 1500 kilobytes.


033111_1610_DataConnect2

Change that setting to support your needs, in this case 4500 kilobytes solved the problem.

Once adjusted…..TADA it was reacting just fine, all was well and the Support team was back in action.

Conclusion

So you might ask was this the best solution.  NO, but this was a quick fix.  What additional information should you take from this use case…….FORM REWORK.

The form is out of control,  a new requirements gathering and analysis should be performed to determine a solution that will limit the risk of data size, large list sizes, and responses.  I do expect this content to be moved to a SQL Table, and the use of External Content Types, and Dataviews to support interaction in SharePoint.

Remember that there is a lot of size limitations and thresholds available in SharePoint Central Administration.  Any service you are using can run into this. It is important to have your service limitations documented, and have a running log of these error your SharePoint Admin can reference.  Also this change needs to be documented in the Governance Control documentation, and should be brought up in the next SharePoint Steering Committee.  Use it as an opportunity, not a scar.

URL Rewriting with URLRewriter.Net Simplest Way

URL Rewriting with URLRewriter.Net

URL Rewriting has lots of benefits, listing its main benefits

  • SEO Friendly URL

  • Secured URL

  • No need to change bookmark with change in site structure.


Before URL Rewriting my URL looks like
http://localhost:2661/URLRewrite2/DynamicPage.aspx?MyTitleId=1

After URL Rewriting URL is changed to
http://localhost:2661/URLRewrite2/Article/Asp-Net-website-paths-1.aspx


Lets Understand URL Rewriting with Simple Example

A Website displaying articles list in a gridview on clicking the article link, it will display dynamically generated article content.

Before URL Rewriting when you mouse-over 1st Article Link, "Asp.net Website Path" it uses query string to display the article content.


Dynamic page display Querysting, before URL Rewriting.



After URL Rewriting we will achieve how SEO Friendly URL is used to display article content.


Now, lets understand how we can achieve it.

For URL Rewriting we are using URLRewriter.Net which is available free. Download URLRewriter.Net

Step-by-Step Explanation

Step 1: Download Binary Files for URLRewriter.Net

Step 2: Add Reference to Binary Files, Right click project "Add Reference" and add binary files.


Step 3: Update Web.Config File to make URLRewriter.Net works.
<configuration>

<configSections>
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>

<system.web>

<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</httpModules>

</system.web>

<system.webServer>

<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>

<validation validateIntegratedModeConfiguration="false" />

</system.webServer>

<rewriter>
<rewrite url="~/Article/(.+)-(.+).aspx" to="~/DynamicPage.aspx?MyTitleId=$2"/>
</rewriter>

</configuration>

Step 4: Adding Function to Generate SEO Friendly URL from given Title

public static string GenerateURL(object Title, object strId)
{
string strTitle = Title.ToString();

#region Generate SEO Friendly URL based on Title
//Trim Start and End Spaces.
strTitle = strTitle.Trim();

//Trim "-" Hyphen
strTitle = strTitle.Trim('-');

strTitle = strTitle.ToLower();
char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
strTitle = strTitle.Replace("c#", "C-Sharp");
strTitle = strTitle.Replace("vb.net", "VB-Net");
strTitle = strTitle.Replace("asp.net", "Asp-Net");

//Replace . with - hyphen
strTitle = strTitle.Replace(".", "-");

//Replace Special-Characters
for (int i = 0; i < chars.Length; i++)
{
string strChar = chars.GetValue(i).ToString();
if (strTitle.Contains(strChar))
{
strTitle = strTitle.Replace(strChar, string.Empty);
}
}

//Replace all spaces with one "-" hyphen
strTitle = strTitle.Replace(" ", "-");

//Replace multiple "-" hyphen with single "-" hyphen.
strTitle = strTitle.Replace("--", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("-----", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("--", "-");

//Run the code again...
//Trim Start and End Spaces.
strTitle = strTitle.Trim();

//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
#endregion

//Append ID at the end of SEO Friendly URL
strTitle = "~/Article/" + strTitle + "-" + strId + ".aspx";

return strTitle;
}

Step 5: Changing DataBinder.Eval Function in .Aspx Page to reflect changes in URL of Grid.
Note: Learn more about DataBinder.Eval Function

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Width="788px">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<Columns>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:HyperLink ID="hlTitle" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Title")%>' NavigateUrl='<%#GenerateURL(DataBinder.Eval(Container.DataItem,"Title"),DataBinder.Eval(Container.DataItem,"Id"))%>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Description")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>

Now, Lets Check the stuff so far developed.

Assigning SEO Friendly URL in to grid.


On clicking URL inside grid it will point to Dynamically Generated Page with SEO Friendly URL, rather than QueryString.


Things to consider while URL Rewriting.

Problem 1: Page Postback, will turns User Friendly URL into Original URL.
Problem 2: CSS, Image Files pointing to URL Rewriting Page won't work, as they might be pointing with absolute path.

Problem 1: Page Postback for Page displaying URL Rewritten URL
Page Postback of Page displaying User friendly URL will turns into original state when same page postback occurs. In our example, I am adding one button and trying to make Page Postback. You will notice that Page Postback will turns the User Friendly URL into original URL containing QueryString.


For Resolving Page PostBack problem for Page displaying URL Rewritten URL

This article is inspired from Scott's URL Rewritten article. Adding two files as mentioned by scott. If you are developing code in VB download files from Scott's article, else for C# download files with Sourcecode at the end of this article.



Now, lets test the Page Postback by clicking on Button, you will notice this time, URL remains the same.




Problem 2: Image Display Problem
Now, lets display image on for this page and lets observe what problem we may run into. I have added following line to display image, but it won't works.

<img src="Images/article.gif" />



Resolve Problem, by refrencing file from root.
<img src="../Images/article.gif" />

Adding the left navigation menu to web part pages in SharePoint 2010

I taught a SharePoint 2010 super-user class last week, and the students experienced like so many before them that the web part page layouts which come with SharePoint 2010 removes the left hand navigation menu (the quick launch).
image
This is nothing new and it has been blogged about since 2007. But on my 15 minute Google spree this morning I could not find a recipe which worked 100% with SharePoint 2010,  so I will give it a try myself, and hopefully this can help some others in the future. I’m sure someone else has a complete post on this which I missed, but at least I have leveled up myself in the use of SharePoint Designer and modifying existing layouts instead of creating custom ones :)

Step 1 – Create a new web part page


Create a new web part page either via SharePoint or SharePoint Designer

Step 2 – Edit the page in SharePoint Designer


Edit your web part page in “Advanced Mode” in SharePoint Designer

image

Step 3 – Remove custom css


Around line 34 you will find a code block like the one below











1

2

3

4

5

6

7

8

9

10

11

12


<SharePoint:UIVersionedContent ID="WebPartPageHideQLStyles" UIVersion="4" runat="server">

<ContentTemplate>

<style type="text/css">

body #s4-leftpanel {

display:none;

}

.s4-ca {

margin-left:0px;

}

</style>

</ContentTemplate>

</SharePoint:UIVersionedContent>




Delete this code block.


Step 4 – Remove the overrides for the left column

Further down you will find three lines which prevents the left column for rendering.











1

2

3


<asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server"></asp:Content>

<asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"></asp:Content>

<asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>




Remove all three lines.


Step 5 –Save the page

Save and publish your page.


Step 6 – Preview your changes


image

Ajax Control Toolkit with SharePoint 2010

I had to use Ajax control toolkit with sharepoint and I had download the latest version from codeplex. We usually download latest versions of software because we believe that with latest version we can get more features and more bug-free. I had used Ajax Control Toolkit with SharePoint 2007 and it was much easier to configure and use Ajax Control Toolkit. With that belief in mind I had started using Ajax Control Toolkit in SharePoint 2010 downloading latest version for .net framework 3.5. But I failed  and after investigating I had found the following errors.


  • AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the ToolkitScriptManager in AjaxControlToolkit.dll.



  • Sys.registerComponent is not a function



The problem here is that latest versions of Ajax Control Toolkit is more optimized or targeted with .net framework 4.0. Even the Ajax control toolkit for .net framework 3.5 doesn’t work with SharePoint 2010. If you try to use Ajax Control Toolkit for 3.5 with SharePoint 2010, you may get the exceptions shown above.

How to make Ajax Control Toolkit working with SharePoint 2010?


Here are the steps to make Ajax Control Toolkit working with SharePoint 2010.

  1. Download Correct (compatible) version of Ajax Control Toolkit.Since current release of Ajax Control Toolkit doesn’t work with SharePoint 2010, you need to download previous release. Maybe Ajax Control Toolkit team will address this issue and we’ll be able to use current Toolkit version with SharePoint in future. Until the current release is made compatible, please download the SharePoint 2010 compatible Ajax Control Toolkit from here.

  2. Add AjaxControlToolkit.dll reference to your projectTo use the Ajax Control Toolkit in your SharePoint project, add reference to the AjaxControlToolkit.dll in your project. To use the Ajax Control Toolkit in any web part control add the following lines to register the Ajax Control Toolkit namespace at web.config
    <%@ Register Assembly="AjaxControlToolkit, Version=3.0.30930.28736,
    Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
    Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>


  3. Remember, here version 3.x version of Ajax Control Toolkit is used instead 3.5.

  4. Add Ajax Control Toolkit ScriptManager in master page.Open the Master page in SharePoint Designer. By default the v4.Master file is the default master page can be found “_catalogs/masterpage” folder. Before modifying the master page, keep a backup copy.

    • First register the Ajax Control Toolkit namespace in the masterpage file by putting the following line at the top of the file:
      <%@ Register Assembly="AjaxControlToolkit, Version=3.0.30930.28736,
      Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
      Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>


    • Then remove the ScriptManager registration from the master page by removing the following line:
      <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false"  
      EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true"/>


    • Finally Add the following line in place of the above line to register Ajax Control Toolkit
      <ajaxToolkit:ToolkitScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" 
      EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true"/>




  5. Register Ajax Control Toolkit namespaces in SharePoint package DesignerFinally, you need to register the Ajax Control Toolkit namespace with SharePoint Package designer. Registering Ajax Control Toolkit namespaces will add Ajax Control Toolkit namespaces in web.config’s safecontrol list. First open the Package designer in Visual Studio (Package usually exists under Package folder in Visual Studio). And then click the “Advanced” button in package designer window as shown in the image below. In that advanced tab you can add/edit assemblies to be registered safe as part of the deployment of the solution package. Click Add ==> “Add Existing Assembly”. The following image shows wizard to follow.

    image

    Figure 1: Package Designer’s Advance tab

     

    In the “Add existing Assembly” window, add the following namespaces for Ajax Control Toolkit.






































    NamespaceType NameAssembly Name
    AjaxControlToolkit*AjaxControlToolkit
    AjaxControlToolkit.Design*AjaxControlToolkit
    AjaxControlToolkit.HTMLEditor*AjaxControlToolkit
    AjaxControlToolkit.HTMLEditor.Popups*AjaxControlToolkit
    AjaxControlToolkit.HTMLEditor.ToolbarButton*AjaxControlToolkit
    AjaxControlToolkit.MaskedEditValidatorCompatibility*AjaxControlToolkit

    The following image shows the “Add Existing Assembly” window for AjaxControlToolkit dll.

    image

    Figure 2: Add/Edit Existing Assembly window

     

    Now you can build and deploy the package and as a result of deployment, Ajax Control Toolkit namespaces will be registered as safe controls in web.config.


Conclusion


Its really hard to believe that Ajax Control Toolkit’s  latest version doesn’t work with SharePoint. We expect to have the latest version of Ajax Control Toolkit to be compatible with SharePoint 2010. Until then we might have to use an old version of Ajax Control Toolkit.

Tuesday 10 July 2012

Database in recovery



If this is 2005, this might be what you need:

 
select der.session_id, der.command, der.status, der.percent_complete, *
from sys.dm_exec_requests as der


It works for other types of commands that have known progress indicators.  If not, then I really don't think it tells you.  You might also check the error log to see how long it took the previous time...

Monday 9 July 2012

String.Split does not support splitting by a string

error: The best overloaded method match for 'string.Trim(params char[])' has some invalid arguments

 

Lets say I have a multiline TextBox that I want to split into an array of String objects, each containing a line from the TextBox.

A logical way to do this would be:
String[] s = textBox1.Text.Split("\r\n");

This does not work.

A workaround is to use this:

String[] s = textBox1.Text.Split("\r\n".ToCharArray());

URL Rewriting in ASP.NET using global.asax and web.config

URL rewriting is very important for search engines like google, yahoo, etc. as we know website getting most of the traffic from search engines.


Here I am explaining 2 way to rewrite URL in asp.net.
URL rewrining using web.config and URL rewriting using global.asax


URL rewrining using web.config:
URL rewriting in web.config is only use for small number of pages. Here you have to rewrite every page manually in web.config. I am writing sample code for 4 urls.
xml version="1.0"?>
<configuration>
<urlMappings enabled="true">
<add url="~/About-company.aspx"
mappedUrl="~/index.aspx?id=1" />
<add url="~/About-products.aspx"
mappedUrl="~/index.aspx?id=2" />
<add url="~/Contact-us.aspx"
mappedUrl="~/index.aspx?id=3" />
<add url="~/our-team.aspx"
mappedUrl="~/index.aspx?id=4" />
urlMappings>
. . .
configuration>


URL rewriting using global.aspx:


This very simple way and very use full. In this way we can rewrite N number of pages and there is no need extra server configuration. Only you have to use Application_BeginRequest event. Inside this event use Context.RewritePath method to set which URL will execute internally in code behind. Here is the code:


void Application_BeginRequest(object sender, EventArgs e)
{
// Get the current path
string CurrentURL_Path = Request.Path.ToLower();

if (CurrentURL_Path.StartsWith("/news/"))
{

CurrentURL_Path = CurrentURL_Path.Trim("/");
string NewsID = CurrentPath.Substring(CurrentPath.IndexOf("/"));
HttpContext MyContext = HttpContext.Current;
MyContext.RewritePath("/news-show.aspx?News=" +  NewsID);
}
}

A potentially dangerous Request.Form value was detected from the client



Server Error in 'ASP.Net' Application.





A potentially dangerous Request.Form value was detected from the client (TextBox1"=<p>Hello</p>").

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (TextBox1="<p>Hello</p>").


 

Cause

ASP.Net By default validates all input controls for potentially unsafe contents that can lead to Cross Site Scripting and SQL Injections. Thus it disallows such content by throwing the above Exception. By default it is recommended to allow this check to happen on each postback.

 

Solution

On many occasions you need to submit HTML Content to your page through Rich TextBoxes or Rich Text Editors. In that case you can avoid this exception by setting the ValidateRequest tag in the @Page Directive to false.


<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest = "false"


 

This will disable the validation of requests for the page you have set the ValidateRequest flag to false. If you want to disable this check throughout your Web Application you’ll need to set it  false in your web.config <system.web> section


<pages validateRequest ="false " />


 

That’s it. Hope this helps you in getting rid of the above issue.