Wednesday, November 30, 2011

SQL Server tips and tricks

Here are some sql server tips and tricks.
To get all the Tables Information in SQL Server


SELECT * from SYS.Tables
To get all the views information in SQL Server


Select * from sys.views  OR

To get only view names
Select Name from sys.views

To get all stored procedure names

How to export gridview data to excel in asp.net?

Here we will discuss how to export the gridview data into excel. There might be a chance that you have a lot of columns in your dataset or datatable but you want to show only those records that are showing in the gridview only. So here is the code to export gridview data to excel in asp.net.

protected void btnExport_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds = GetDataForGridView();
        string attachment = attachment = "attachment; filename=MyExcelSheetName_" + DateTime.Now.ToString() + ".xls";
        if (ds.Tables.Count > 0)
        {
            DataTable dt = ds.Tables[0];

Saturday, November 26, 2011

SharePoint Oppenings at Accenture

Requirement: SharePoint Server.
Job Description:
Very good knowledge on SharePoint basics (WSS and SPS features, Administration, Knowledge on lists and document library) and working experience on Application programming, development, configuration, deployment and maintenance (Site configuration, back up, restore and template manipulation). Should have at least 1 year of work experience on SharePoint and its related technologies. He also should have fair knowledge

Monday, November 21, 2011

System.MissingMethodException: No parameterless constructor defined for this object error in custom pagelayout

In this post we will discuss how to resolve error: System.MissingMethodException: No parameterless constructor defined for this object error in custom pagelayout.

Also you can check out my previous posts on:

- Programmatically get SharePoint Themes

- Signin as different user is missing in SharePoint 2013

- Change "Add New Item" link text in list in SharePoint 2010

I got this error "System.MissingMethodException: No parameterless constructor defined for this object " while trying to add a custom web part to a custom page layout using Visual Studio 2010 in SharePoint 2010. I was getting the error when I am changing the page layout to my custom page layout.

My problem was with the 4 part assembly name that I was getting by following this link.

Actually that was giving me the wrong 4 part assembly name that I was using in my elements.xml file. So I have changed the 4 part assembly name and that worked !!! The best way to get 4 part assemble is by following this article.

Friday, November 18, 2011

How to find the ID for associated content type when adding a page layout?

If you are working in SharePoint 2010 with pagelayout by using Visual Studio 2010, then while deploying the layout template you will need the content typeid. You need the id in the element.xml file in PublishingAssociatedContentType tag.

Then PublishingAssociatedContentType  should be in form ';#;#. The Content type name is the name of the content type that your page layout based on. Suppose you are making a publishing pagelayout and your content type is based on Welcome Page content type. Then to get the content type id go to Site Actions -> Site Settings then from Galleries section Select Site content types. Then choose your content type from the list of content types. I am choosing her Welcome Page from Page Layout Content Types section  as shown in the figure below.



Now check the URL as shown in the figure below in the ManageContentType page. Your id is after ctype= and before &Source= in the URL. You can copy that and paste in the Elements.xml file as shown below.


<Property Name="PublishingAssociatedContentType" Value=";#Welcome Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4;#" />

Thursday, November 17, 2011

Delete custom page layout in SharePoint 2010

Here we will discus how we can delete a custom page layout in SharePoint 2010.

Also you can check out:

- Create Page Layout using SharePoint Designer 2010

- Get default page layout of a publishing web site in SharePoint 2010

- Programmatically add or assign user to User Group in SharePoint

Sometime you will need to delete your custom page layout in SharePoint 2010. For this go to Site Actions -> Site Settings -> then under Galleries. Go to Master pages and page layouts. Then select your page layout and delete as shown in the figure below.

Why does the Visual Studio editor show dots in blank spaces?

I got dots in blank spaces in my Visual Studio 2010 editor, I have tried to reset the Visual studio 2010 but that also did not help me out. When I search in google, I saw I have configured to show white space.
To resolve this you can go to Edit menu in visual studio then Advanced ->unSelect View White Spaces as shown in the figure below.

Also you can use the shotcut key  Ctrl+R, Ctrl+W.
Sometimes shotcut keys are also dangerous !!!

Only Content controls are allowed directly in a content page that contains Content controls in sharepoint 2010 page layout

In this post we will discuss how to resolve error: Only Content controls are allowed directly in a content page that contains Content controls in sharepoint 2010 page layout.

Also you can check out my previous posts on:

- How to Configure SSRS for SharePoint Integration Mode in SharePoint 2010?

- Call jQuery to SharePoint page using Content Editor web part

- Script editor web part in SharePoint 2013

I got the error "Only Content controls are allowed directly in a content page that contains Content controls in sharepoint 2010 page layout" while creating page layout using visual studio 2010. What I was doing is I am copying the layout page content from a layout page from SharePoint 2010 designer. so when I was coping and pasting the content, My tags are coming like below

<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
 <SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
</asp:Content>

Please look at the capital letter C in Content, which was causing the problem.

so I have changed the code to small c as below and it works fine.

<asp:content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
 <SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:content>
<asp:content ContentPlaceholderID="PlaceHolderMain" runat="server">
</asp:content>

Monday, November 14, 2011

Get all security group names using SharePoint object model

In this post we will discuss about how to get all security group names using SharePoint object model.

Also you can check out:

- Delete custom page layout in SharePoint 2010

- Enable Sign in as Different User Option in SharePoint 2013

- SharePoint: Custom Media Video Player using JQuery

You can get the security group names using SharePoint object model by using the SPGroup class.

Here is the code below:

using (SPSite siteCollection = new SPSite("Ur Site collection URL"))
{
using(SPWeb site = siteCollection.OpenWeb)
{
foreach(SPGroup group in site.Groups)
{
string groupName=group.Name;
}
}
}

It will give you all the group names available in the current site inside the site collection. Also one thing to remember is that you can not create a Group at the site level, always you have to create in the Site collection.

The below code shows how to add a group to a site collection:

site.SiteGroups.Add("NewSecurityGroup",site.CurrentUser,site.CurrentUser,"A new group");

Sunday, November 13, 2011

URL Rewritting in asp.net

Here we will discuss about URL rewriting in asp.net. Though MVC has built in facility of URL rewritting but classic asp.net does not have.

Why it is necessary?
A SEO user friendly URL is necessary for the SEO purpose.
For example:
http://www.fewlines4biju.com/Blog.aspx?BlogID=5 URL is not a SEO user friendly URL.
http://www.fewlines4biju.com/Blogs/Details/another-article-by-bijay-kumar-for-seo-5.aspx , but this URL is a SEO friendly URL. So it is always better to have a URL like the above.

So we will discuss the steps below:
First of all we will check the web.config entries, I am writting the entries with the parent tag. You have to replace your folder structure accordingly.
web.config:

Unrecognized configuration section rewriter

This error occurs while implementaining URL Rewritting in asp.net by using Intelligencia.UrlRewriter.dll. Here the web.config entries are very much important.

This comes if you are using the below tag before defining the rewriter tage in .
<rewriter>
<rewrite url="~/Articles/Details/(.+)-(.+).aspx" to="~/Articles/sharepoint-article-details.aspx?ArticleID=$2"/>
</rewriter>
So your web. config entries should be like below.

<configSections>

Could not load type formrewritercontroladapter

This error ususally comes when you will try to implement postback thing in URL rewritting by adding App_Browsers and putting the Form.browser inside the App_Browsers folder.
If this error comes while implementing URL rewritting then, Download the class from this URL and put it inside the App_Code folder. You can download the whole files here.

Thursday, November 10, 2011

Download asp.net mvc book pdf free

You can download Apress.Pro.ASP.NET.MVC.2.Framework.2nd.Edition pdf free here.

Wednesday, November 9, 2011

How to create datatable at runtime in asp.net using c#.net?

Here is the code to create a datatable at runtime in asp.net using C#.Net.

Also you can check out some posts on:

- AllowUnsafeUpdates in SharePoint 2010

- How to Create a Content Type using Visual Studio 2010 in SharePoint 2010?

- Show SharePoint list data in repeating table in infopath 2010 using SharePoint object model

Below is the namespace needed.

using System.Data;
// Create a DataTable instance
DataTable dataTable = new DataTable("DataTableName");
// Create a DataColumn instances
DataColumn dtCol1 = new DataColumn();
DataColumn dtCol2 = new DataColumn();
dtCol1.ColumnName = "Id";
dtCol1.DataType = Type.GetType("System.Int32");
dtCol2.ColumnName = "Name";
dtCol2.DataType = Type.GetType("System.String");

// Add these DataColumns into the DataTable
dataTable.Columns.Add(dtCol1);
dataTable.Columns.Add(dtCol2);

// Create a DataRow Instance from the table we create above, with NewRow();
DataRow row = dataTable.NewRow();

row["Id"] = 1;
row["Name"] = "Fewlines4Biju";

// Add the row into the table
dataTable.Rows.Add(row);

Authentication, Authorization and Identities in SharePoint 2010

Security is very much important in a business solution. Because business needs, if a user does not have permission he should not be able to view, edit or delete sensitive pages. And also if a user has permission, he should able to visit pages, items or documents.

Authentication: It is the process of getting the identity of a user. You can authenticate people with the use of Windows account stored in Active directory. This authentication happen when a user logged in to the computer. Once authenticated we can retrieve name as below:
WindowsIdentity identity = WindowsIdentity.GetCurrent;

Tuesday, November 8, 2011

What is Performance Testing?

In Performance testing we are checking we are concentrating on speed in processing of  a software by checking below factors:

Ø  Execution of as s/w under customer expected configuration and customer expected load to calculate speed in processing, is called as Load Testing. Here load means number of concurrent users using our s/w.
Ø  Execution of our s/w under customer expected configuration and more than customer expected load to estimate reliability is called as Stress Testing.
Ø  Execution of our s/w under customer expected configuration and sudden increments of load to estimate reliability is called as Spike Testing.

Ø  Execution of our s/w under customer expected configuration and continuous load long time to estimate durability is called as Endurance/Durability/ Longuity Testing.

    Friday, November 4, 2011

    We are blind or closed our eyes !!! Lets Support Anna Hazare !!!

    The Anna Hazare, 74 year old man again raised his voice after 19 days maun vrat. He said fight for Janlokpal Bill will continue. You can check here. Hazare had threatened to launch another hunger strike if a strong Lokpal Bill is not passed in Parliament's Winter Session.
    Another Team member of Anna Hazare Arvind Kejriwal returns 9 lakh dues to government
    He also wrote to PM  "I am enclosing a cheque for Rs 9,27,787. This does not mean that I have accepted the mistake. When I don't know what was the mistake I committed, then there is no question of accepting it. I am

    Wednesday, November 2, 2011

    How to add read more in blogger blog?

    To add Read More link in blogger blog is easy in the new advanced editor provided by google. Simple you need to click on the Insert jump break icon in the line on which you want the read more.

    Write text file in UTF8 format using MemoryStream

    Below is the code to write text in UTF8 format using memorystream using c#.net
    Response.Clear();
    MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes("This is the text you want to write in text file"));
    Response.AddHeader("Content-Disposition", "attachment; filename=filename.txt");          
    Response.ContentType = "text/plain";
    Response.ContentEncoding = System.Text.Encoding.UTF8;
    memoryStream.WriteTo(Response.OutputStream);
    Response.End();