Recent News

URL Rewriting using URL Rewriter


Hi All,

     Everyone knows about the url rewriting. If we are using URL rewriting by defalut then we need to for IIS or other wise we need add rules at our web.config. But that is some difficult to understand to somebody. To over come this we can use third party tool like UrlRewritingNet.UrlRewriter.dll.

Here I have given the screen shot for simple understanding purpose…



Create Data Table Dynamic

Hi All,
     We can create a data table dynamically. That is we can get particular columns from the dataset where as the dataset having all columns/many columns. From that dataset we can get our necessary columns.

private DataTable GetInitalTable(DataSet ds)


{
//Instatiate the data table
DataTable dt = new DataTable();

//Initialise the column names
dt.Columns.Add("Id");
dt.Columns.Add("firstname");

//loop
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

{
//Assign/Adding the Rows from dataset
dt.Rows.Add(ds.Tables[0].Rows[i]["Id"], ds.Tables[0].Rows[i]["firstname"]);

}
// Return the data table!
return dt;

}
 
 
The input is the whole dataset records. But the we can get out put only with two columns as per the above example...
 
 
Happy Coding!!!!!!!
No Pain!... No Gain!!

SQL connection string

Hi All,

 we are all know how to connect the SQL Database from our C#. I am just given the syntax of Connection String which is used to connect the SQL.

connectionstring = "Data Source=DBName;Initial Catalog=Test;User Id=sa;Password=123;"



Thanks,
Sarav





MULTI FILE UPLOAD USING JQUERY

Herewith I have explained and given the code for multiple file upload using jquery.
We know all the normal upload functionality. But someone of us wants the multiple file upload in .NET. Here jquery makes that very easy.
We just use the same asp:fileupload control. If you want to accept only jpg,png only you no need to go for a customvalidator tocheck the file extension. You just add the accept="jpg|png". Thats it. It allows only files which has the extension of above.
Ok let us see the code below,

HEAD SECTION:
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="Scripts/jquery.MultiFile.js" type="text/javascript"></script>
 
BODY TAG:
<div>

<asp:FileUpload ID="fupImage" runat="server" class="multi" accept="" />
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload All" OnClick="btnUpload_Click" />
</div>

Thats it about in the UI page(aspx).
Let us see the code behind page,

the following code should be inside in the upload button event,

try

{
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
Guid newid = new Guid();
newid = System.Guid.NewGuid();
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
hpf.SaveAs(Server.MapPath("Files") + "\\" +
System.IO.Path.GetFileName(newid + hpf.FileName));
Response.Write("Uploaded Successfully <br/>");
}
}
}
catch (Exception ex)
{
// ERROR OCCURED
}
 
Feel free to post your comments here!... If any one wants the whole solution post your mailid here. I will send mail to you personally.....
 
“You have to dream before your dreams can come true.” - A P J


Radio Button Event

Here I have explained the events of radio button with javascript.
Let me explain the scenarion first,
We are having two radio button say radioobtn1 and radiobtn2. If I click on the button 1 then I need to show one DIVor FORM. same as when I click on radiobtn 2. I have given the code for the above scenarion.

<script>
function show()
{
if(document.getElementById('radiobtn1').checked)
{
document.form1.style.display='block';
document.form2.style.display='none';
}
else
{
document.form1.style.display='none';
document.form2.style.display='block';
}
}
</script>


<input type="radio" checked="checked" onClick="javascript:show()" name="radiobtn1" id="radiobtn1" value="radiobtn1" /> Radiobtn1
<input type="radio" name="radiobtn2" onClick="javascript:show()" id="radiobtn2" value="radiobtn2" /> radiobutton2

<form action='#url' name="form1" METHOD='POST'>
<table>
<tr class="displaynone">
<td>THIS IS FORM1
contents goes here
</td>
</table>
</form>


<form action='#url' class="displaynone" name="form2" METHOD='POST'>
<table>
<tr class="displaynone">
<td>THIS IS FORM2:

contents goes here

</td>
</table>
</form>
 
 
Hope this should help for freshers and even for all.....
 
Happy Coding!!!!!!!!!
 
 
 

Expand DIV using jquery

Hi All,

     Here you can get the idea about the expanding of div inside an master page or any other pages. This has some animation. That is if you click on the Login Link then the below login tab will be open with some animation.
    Here you may find the style used for this sample in style tag. Please have a look at the following coding,

This should be inside the head tag.

<script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
<style type="text/css" media="screen">
#expand
{
display: none;
background-color: Transparent;
position: absolute;
z-index: 100; /* padding: 16px;
background-color: Blue;
z-index: 1000;
width:350px; */
}

.expandInfo
{
background-color: Transparent;
margin: 0;
padding: 0px;
}
</style>
 

<script type="text/javascript">
<!--
$(function () {
$('.expandInfo a').click(function () {
$('#expand').slideToggle(1500);
return false;
});
})
//-->
</script>

<script type="text/javascript">
<!--
$(function () {
$('.expandInfoClose a').click(function () {
$('#expand').slideToggle(1500);
return false;
});
})
//-->
</script>
 
Then the body content may be as follows,
 
<div class="bg">
<p class="expandInfo">
<a href="#home" title="Login" class="login" style="width: 100px; height: 100px;">Login</a>
</p><br />
<br />
<div id="expand"><table cellpadding="0" cellspacing="0" class="loginbg">
<tr>
<td valign="top" style="padding-left: 30px">
<div style="float: right; padding-right: 10px">
<p class="expandInfoClose">
<a href="#home" title="Close">
<asp:Image runat="server" ID="imgcloselog" SkinID="imgLoginBoxClose" />
</a>
</p>
</div>
<asp:Panel runat="server" ID="pnlLoginMaster" DefaultButton="btnLogin">
<table cellpadding="4" cellspacing="4" align="left" style="margin-top: 60px;">
<tr>
<td align="left" valign="top">
<%--// CONTENTS--%>
cellspacingcellspacingcellsp acingcellspacing cellspacing cellspacingcells pacingcellspacingcellspacing
cellspacing cellsp acing cellspa cingcellspa cingcel lspacingce llsp acing
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
</div>
</div>

You can download the jquery here
If you have any questions please feel free to post comments....
Suggessions always welcome ..........Happy coding!!!!!!!

Meet you again!!!!!!!!

Get Top 1 Record from Dataset

Hi Guys,

     Many of them in need of getting the Top 1 or Top 10 records from a Dataset without going to SQL query. It is possible to do from Code Behind. I have given the code below,
     The below code is to get single record from a Dataset. Also I have given for getting 8 records at Green Color.

  public DataSet GetTopTen(DataSet ds)
{
try
{
DataView dv = ds.Tables[0].DefaultView;
dv.Sort = "ModifiedDatetime DESC";
DataSet dss = new DataSet();
DataTable dt = dv.Table.Clone();
dss.Tables.Add(dt);

// This is To get 8 records
//int counter = 0;
//if (dv.Count > 8)
// counter = 8;
//else
// counter = dv.Count;
//for (int i = 0; i < counter; i++)
//{
// DataRow dv = dv[i].Row;
// dss.Tables[0].ImportRow(dv);
//}

// This is for Getting only one Record
DataRow dv = dv[0].Row;
dss.Tables[0].ImportRow(dv);
dss.AcceptChanges();
return (dss);
}

catch (Exception e)
{
throw e;
}
}

Hope this will help you Guys.... Please touch with this blog... I will update regularly....



Email Validation from Codebehind

This is for check the email address from codebehind using regular expression.

if (System.Text.RegularExpressions.Regex.IsMatch(txtNewsletter.Text, "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{1,3})$") == false)
{
Page.RegisterStartupScript("GetType", "<script language='javascript'>alert('Please enter valid email address!')</script>'");
}

watermark textbox using Ajax control

This is pretty simple compared to jquery. Since we need refer a dll only. we dont want any script for this. we just include that reference into our website.

Please have a look at the coding.......

<asp:TextBox runat="server" ID="txtSearch"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="twSearch" runat="server" TargetControlID="txtSearch"
WatermarkText="Search Products..." />
<span class="search_button">
<asp:ImageButton ID="butSearch1" runat="server" ImageAlign="Right" OnClick="butSearch1_Click"
Height="30px" />
</span>

Watermark Textbox using jquery

Here is the coding for Watermark inside a textbox. That is initially the message will show inside the textbox. Once you click on the textbox it will disappear. This is used by jquery.

CSS:

<style type="text/css" media="screen">
.water
{
font-family: Tahoma, Arial, sans-serif;
color: blue;
}
</style>

 
SCRIPT:
 
        <script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
 
DESIGN:
  <div>


<h2>

Watermarked TextBox </h2>

<br />
<asp:TextBox ID="txtFirstName" class="water" Text="Enter First Name" ToolTip="Enter First Name" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtLastName" class="water" Text="Enter Last Name" ToolTip="Enter Last Name" runat="server"></asp:TextBox> <br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="vgNews" /></div>



 
Please give your comments if you need any clarification.... Also I will post watermark using ajax in the next post... Happy Coding!!!

If you need this Jquery please click here to download

Create XML file

Hi All,
   Here I have given the sample code to create a simple XML from .NET.
Please post your comments after review this....

string strfile = Server.MapPath("~/App_Data/simplexmlcreation.xml");
XmlTextWriter writexml = new XmlTextWriter(strfile, System.Text.Encoding.UTF8);
try
{
// write the top element and encode type
writexml.WriteStartDocument();
// write the starting element or root element
writexml.WriteStartElement("IPL");
// write first set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Chennai Super Kings");
writexml.WriteAttributeString("Points", "40");
writexml.WriteAttributeString("Captain", "Raina");
writexml.WriteString("CSK HAS MATHEW HAYDEN");
writexml.WriteEndElement();

//// write Second set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Kolkatta Knight Riders");
writexml.WriteAttributeString("Points", "45");
writexml.WriteAttributeString("Captain", "Saurav");
writexml.WriteString("KKR HAS Saurav Ganguly");
writexml.WriteEndElement();

//// write Third set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Royal Challangers Bangalore");
writexml.WriteAttributeString("Points", "55");
writexml.WriteAttributeString("Captain", "Kumble");
writexml.WriteString("KKR HAS Kalis");
writexml.WriteEndElement();

// Close the root Element
writexml.WriteEndElement();
//close the XML DOC
writexml.WriteEndDocument();
}

catch
{
throw;
}

finally
{
writexml.Close();
}



Thanks for reading my POST..... Keep Coding!!!!!!!

AUTHENTICATION and AUTHORIZATION

The web.config file has all of the configuration settings on an Application.
Authentication is the process of determining the authenticity of a user based on the user’s credentials.
Whenever a user logs in to an application, the user is first authenticated and then authorized.

1. Forms Authentication
2. Windows Authentication
3. Passport Authentication


You can set it in the web.config file as below,

or or

1. Forms Authentication:

This type of authentication is based on cookies. The username and password is stored in Database.This Forms authentication supports both Session and Cookies.
If the cookie isn't present, ASP.NET redirects the user to a web form you provide.
SYNTAX:


2. Windows Authentication:

This type of authentication is default one. Here a user can authenticated by their own windows account. So that this kind of Authentication is used only for Intranet not for web.
SYNTAX:


3. Passport Authnetication:
This passport authentication is the authentication service that uses the Microsoft's Passport Services. It allows the user to create a single sign in name and password to authenticated.

SYNTAX:


AUTHORIZATION:

It is the process of finding the accessibilty for a previously authenticated user.Authorization is only works with the Authenticated User/Person.

Download a Folder or File from .NET

Hi All,

  The below code is used to download the files from our .net coding...

#region downloadfile



public static bool downloadfile(string filename, string path)


{


try


{


FileStream sourceFile;


HttpResponse response = HttpContext.Current.Response;


response.ContentType = "application/x-rar-compressed";


response.AddHeader("content-disposition", "attachment; filename=" + filename + Path.GetExtension(path).ToString());


sourceFile = new FileStream(path, FileMode.Open);


long FileSize;


FileSize = sourceFile.Length;


byte[] getContent = new byte[(int)FileSize];


sourceFile.Read(getContent, 0, (int)sourceFile.Length);


sourceFile.Close();


sourceFile.Dispose();


response.BinaryWrite(getContent);


response.Flush();


response.Clear();


response.Close();


return true;


}


catch (Exception ex)


{


return false;


}


}


#endregion
 
 
 Happy Coding!!!!!!!

SQL JOIN QUERIES

JOIN QUERIES:

INNER JOIN:

select col1,col2 from tablename1 as aliasname1 inner join tablename2 as aliasname2 on aliasname1.field1 = aliasname2.field1

eg: here I have given the detaild explanation below,

to use the join queries we need atleast two tables. We need a common field in both tables. otherwise we can say like, we need a forign key table and primary key table.
Let us take a tbl_user table has primary key of userid. and let us take another table tbl_Item has the foregn key of same userid which has refered by tbl_Item.
If we need to get item which has been uploaded by a particular user. for this scenario we can use below query,

select I.itemid,I.itemname,U.username,U.Firstname,U.Lastname from tbl_User U INNER JOIN tbl_Item I on I.userid = U.userid

This inner join query is used to get the records or data present in the both column refered by a common column or field.
There are many other joins like left outer join, right outer join.
These type of joins is used to get the whole values including the common values.
Let me explain with a simple scinario.

Let us take we are showing a item listing page. In this page we are showing all the items with item name, item description along with total sales count of the particular item.
Here you may not use INNER JOIN. Since if you are using inner join we can get only the details which the item sales more than one time.
So the net result is we can not showing the items which has 0 sales count. For this you can use the Left outer join or Right Outer Join instead of INNER JOIN.
So it will give the results including the 0 sales count.

GET DATE:

If you need to get the currentdate then you can use the following query,

select getdate() as DATETIME

DATEADD:
If you need to get the past 6 Months record you can use the following,

SELECT * FROM tbl_User WHERE createddate > DATEADD(m, -6, current_timestamp);

SORTING:

Keyword: desc ----> It will give the records in DESCENDING

select ItemID, UserID, Name,Description from tbl_item where isfeatured = 1 order by CreatedDate DESC

Keyword: ASC ----> It will give the records in ASCENDING

select ItemID, UserID, Name,Description from tbl_item where isfeatured = 1 order by CreatedDate ASC


LIKE QUERY:

SELECT * FROM tbl_Item WHERE itemname like @sql+'%';

or

SELECT * FROM tbl_Item WHERE itemname like 'saravan%';

In this Like condition we should use LIKE and %. That is these two are the main key words.
From the above Query if we are using % at last with the parameter, then it will give all the values which starts with the parameter.
If you see the second example you can get the clear idea about this.

SELECT * FROM tbl_Item WHERE itemname like '%'+@sql+'%';

Here you can get the values which has contain the word @sql or parameter as an Output.

You can also show the records which has not start with some particular letters.

eg: SELECT * FROM tbl_Item WHERE itemname not like 'H%';

also you can use the query to get the values with some exclude data like,

NOT EQUAL TO:(<>)

SELECT Company, Country FROM Customers WHERE Country <> 'USA'

Here you can get the company name and country name from customers except USA.

Simple Basic Queries

In this post I have explained some simple queries with an explanation. This may help ful for beginners.

SELECT QUERY:

select fieldname(s) from tablename

eg: select itemid,itemname,itemdesc from tbl_Item

UPDATE QUERY:

update tablename set col1=@param1,col2=@param2

eg: update tbl_Item set itemname = @itemname,itemdesc = @desc where itemid = @itemid

Here you can use the where condition to update a particular column in the table. If you need to update the values without any condition then you can have the same query but with out the where condition. Please see below for your reference,

eg: update tbl_Item set itemname = @itemname,itemdesc = @desc

Note: @itemname,@desc are the parameter.

DELETE QUERY:

delete from tablename

eg: delete from tbl_Item where itemid = @itemid

here you can delete the particular rows of a table. Thats is you can delete rows or data for particular itemid. But you can delete whole table with out anycondition you can use the same with out where condition.

TRUNCATE TABLE:

truncate table tablename

eg: truncate table tbl_Item

DIFF BETWEEN DELETE AND TRUNCATE:


Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command. Simply said it will reset the table with the new one. But it wont affect the structure of the table.

INSERT QUERY:

insert into tablename(col1,col2,col3) values(@param1,@param2,@param3)

eg:  insert into tbl_Item(itemname,desc) values(@itemname,@desc)

Interview Questions Collections

Here I have given the collections of Interview questions which I have collected.... You can read it and give me your feed back and suggestion. Also please send me the questions if you any then I can post them also to here. So easily an Reader learn lot from this.... Please read more at Questions and Answers

1. What is .NET Framework?
The .NET Framework has two main components: the common language runtime and the .NET Framework class library.
You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that ensure security and robustness.
The class library, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.
Click for more

What is DataSet ?

A DataSet is an in memory representation of data loaded from any data source. Even though the most common data sourceis database, we can use DataSet to load data from other data sources including XML files etc. In this article, we will talk about the role of DataSet in manipulating data from database.

In .NET, a DataSet is a class provided by the .NET Framework. The DataSet class exposes several proeprties and methods that can be used to retrieve, manipulate and save data from various data sources.

Followers

Top Commentators

Recent Comments | Recent Posts


bottom