Saturday, September 15, 2012



Unix file operation Commnads

appent to file cat >> cat >> file1
combine 2 files cat cat file1 file2 > file3
copy files cp cp myfile copymyfile
create a file cat cat > newfile
edit files vi vi file
list files ls ls bin/
move a file mv mv file1 doc/chapter1
remove a file rm rm unwantedfile
rename a file mv mv oldfilename newfilename
view files cat cat file pg pg file2 file3 more less view view file6 file7
change to another directory cd cd folder1/folder2/
create a directory mkdir mkdir myfolder
find out where you are pwd
go to your home directory cd
remove an emplty eirectory rmdir rmdir junk

Redirection of Output or Input

> redirects the output of a command to a file
>> redircts the output of a command to the end of an existing file
< takes the input of a command form a file, not the terminal

Summary of Basic Commands

cal cal 1 display a calendar
cal [month] year
month number between 1 and 12 year number between 1 and 9999
Examples:
cal 2012 print calendar for year 2012
cal 1 2012 print calendar for January 2012

Unix command to view files, create files, append to files and combine files

cat cat(1) concatenate and display files
cat [options] [files]
Examples:
cat files read file(s)
cat > file create file (reads form terminal )
cat >> file append to file (reads form terminal )
cat file2 >> file1 appends contents of file2 to file1
cd cd(1) shell built-in functions to change the current working directory
chdir cd(1) shell built-in functions to change the current working directory
chgrp chgrp(1) change the group ownership of a file
chmod chmod(1) change the permissions mode of a file
chown chown(1) change owner of file
clear clear(1) clear the terminal screen
cp cp(1) copy files
date date(1) print and set the date
dc dc(1) arbitrary precision desktop calculator
dos2unix dos2unix(1) convert text file from DOS format to ISO format
eject eject(1) eject media such as CD-ROM and floppy from drive
exit exit(1) shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps
file file(1) file(1B) determine the type of a file by examining its contents
head head(1) display first few lines of files

ls      list the contents of a directory
ls [options] [directories]
the current working directory used if no directories specified
 few options:
           -a list all entries includeing hidden files (starting with .)
           -i print inode numbers
           -l long list (mode, links, owner, group, size, timeof last modification, and name
           -t sort by modification time
           -x multi-column list, sorted across each row

Mail, mailx mailx(1), mail mail(1) rmail interactive message processing system to read mail or send mail to users

mail [options] users
Examples:
mail with no options, to read your mail
mail user to send mail to user
mail user < filename mail a file to another user
mkdir mkdir(1) make directories
more more(1) browse or page through a text file
mv mv(1) move files
pg pg(1) files perusal filter for CRTs
pr pr(1) print files
ps ps(1) ps(1B) display the status of current processes
pwd pwd(1) working directory name
rm rm(1) remove files or directories
rmdir rm(1) remove files or directories
spell spell(1) find spelling errors
tail tail(1) deliver the last part of a file
umask umask(1) shell built-in function to restrict read/write/execute permissions
unix2dos unix2dos(1) convert text file from ISO format to DOS format
vi vi(1) screen-oriented (visual) display editor based on ex
view vi(1) screen-oriented (visual) display editor based on ex


w w(1) who is logged in, and what are they doing
wc wc(1) display a count of lines, words and characters in a file
which which(1) locate a command; display its pathname or alias
who who(1) who is on the system
whoami whoami(1B) display the effective current username
whois whois(1) Internet user name directory service
write write(1) write to another user

Sunday, October 3, 2010

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

I had a issue with one of my application in which asp.net throwing error like "A potentially dangerous Request.Form value was detected from the client". In my error it was showing error with encrypted viewstate value on the form.This error can not be reprodiced on IE other than IE6.
If you are receiving the A potentially dangerous Request.Form value was detected from the client error while a PostBack occurs it is because of in the PostBack content, there are HTML or HTML-like tags. This is ASP.NET's defense mechanism that prevents the users of a website to try and inject code into forms, as a way to hack into the websites.

To fix this, you can set the validateRequest attribute to false, either for the entire ASP.NET web application, or just for one page. To disable validateRequest for a single page, go to that page's Page attribute (located at the top of the markup), and set validateRequest to false, as you can see at the end of the example below:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SamplePage.aspx.cs" MasterPageFile="master1.master" Inherits="default" ValidateRequest="false" %>


If you prefer to set this value for all the pages in your ASP.NET web application, open (or create) the web.config file and add the tag inside the system.web tag, as shown in the example below:








Thursday, June 25, 2009

WCF concepts

WCF concepts include ABC i.e,

A - Address
B - Binding
C – Contract
Services are building on windows communication foundation’s System.ServiceModel assembly in location


C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation.

I found some useful resources from MSDN when i searched the web.


You'll get samples from MSDN, Download Samples


MSDN Tutorial for WCF,

How to: Define a Windows Communication Foundation Service Contract
How to: Implement a Windows Communication Foundation Service Contract
How to: Host and Run a Basic Windows Communication Foundation Service
How to: Create a Windows Communication Foundation Client
How to: Configure a Basic Windows Communication Foundation Client
How to: Use a Windows Communication Foundation Client

Monday, June 22, 2009

Creating the Web Service Proxy using wsdl

Creating the Web Service Proxy

A client and a Web service can communicate using SOAP messages, which encapsulate the input and output parameters as XML. A proxy class maps parameters to XML elements and then sends the SOAP messages over a network. In this way, the proxy class frees you from having to communicate with the Web service at the SOAP level and allows you to invoke Web service methods in any development environment that supports SOAP and Web service proxies.

There are two ways to add a proxy class to your development project using the Microsoft .NET Framework: with the WSDL tool in the .NET Framework, and by adding a Web reference in Microsoft Visual Studio. The following sections discuss this subject in further detail.

Adding the Proxy Using the WSDL Tool
The .NET Framework SDK includes the Web Services Description Language tool (Wsdl.exe), which enables you to generate a Web service proxy for use in the.NET Framework development environment. The most common way to create a client proxy in languages that support Web services (currently C# and Microsoft Visual Basic) is to use the WSDL tool.

To add a proxy class to your project using Wsdl.exe

From a command prompt, use Wsdl.exe to create a proxy class, specifying (at a minimum) the URL to the Report Server Web service.
For example, the following command prompt statement specifies a URL for the management endpoint of the Report Server Web service:
Copy Code
wsdl /language:CS /n:"Microsoft.SqlServer.ReportingServices2005" http://myserver/reportserver/reportservice2005.asmx?wsdl
The WSDL tool accepts a number of command-prompt arguments for generating a proxy. The preceding example specifies the language C#, a suggested namespace to use in the proxy (to prevent name collision if using more than one Web service endpoint), and generates a C# file called ReportingService2005.cs. If the example had specified Visual Basic, the example would have generated a proxy file with the name ReportingService2005.vb. This file is created in the directory from which you run the command.

Compile the proxy class into an assembly file (with the extension .dll) and reference it in your project, or add the class as a project item.
Note:
When you add a proxy class to your project manually, you need to add a reference to System.Web.Services.dll. If you add the proxy using a Web reference in Visual Studio .NET, the reference is automatically created for you. For more information, see "Adding the Proxy Using a Web Reference in Visual Studio" later in this topic.

Friday, June 19, 2009

Creating Proxy Class with Visual Studio .NET 2005

Creating Proxy Class with Visual Studio .NET 2005
Visual Studio .NET 2005 provides the capability to create class files that contain the proxy code utilized to access the web services. The WSDL tool is used to generate proxy code from WSDL files. The generated class is used to instantiate objects for communicating with the Web services via SOAP messages.

Creating Proxy Class in C#
1) From within your Visual Studio 2005 folder in your start menu, select "Visual Studio Tools"

2) Within the "Visual Studio Tools" menu select "Visual Studio 2005 Command Prompt".

Note
This shortcut automatically loads up all of the environment variables needed to access special tools in Visual Studio .Net without having to specially modify the operating system variables.

3) Within the command prompt, change the directory to the directory of your application.

Note
If you do not change your directory, the default location for your file will be:


C:\Program Files\Microsoft Visual Studio 8\VC
4) Within the command prompt window, type the following command:


wsdl http://jlab.calumet.purdue.edu/thegateway/v2/0/pathwaygateway.asmx?wsdl
Note The filename "GatewayPathway.CS" will be in the location you specified in step 3.

5) Within your Visual Studio 2005 project, open Solution Explorer.

6) Within the Solution Explorer right click on the project name and select "Add Existing Item..." and the "Add Existing Item" dialog box will appear


7) Within the "Add Existing Item" dialog box, browse to the location of your file if not in the project folder, and select the file "PathwayGateway.cs" you created in step 4.

Note
The File has now been added to your project and will be listed in your Solution Explorer.

Creating Proxy Class in VB.NET
1) From within your Visual Studio 2005 folder in your start menu, select "Visual Studio Tools"

2) Within the "Visual Studio Tools" menu select "Visual Studio 2005 Command Prompt".

Note
This shortcut automatically loads up all of the environment variables needed to access special tools in Visual Studio .Net without having to specially modify the operating system variables.

3) Within the command prompt, change the directory to the directory of your application.

Note
If you do not change your directory, the default location for your file will be:

C:\Program Files\Microsoft Visual Studio 8\VC
4) Within the command prompt window, type the following command:


wsdl http://jlab.calumet.purdue.edu/thegateway/v2/0/pathwaygateway.asmx?wsdl /language:VB
Note The filename "GatewayPathway.vb" will be in the location you specified in step 3.

5) Within your Visual Studio 2005 project, open Solution Explorer.

6) Within the Solution Explorer right click on the project name and select "Add Existing Item..." and the "Add Existing Item" dialog box will appear


7) Within the "Add Existing Item" dialog box, browse to the location of your file if not in the project folder, and select the file "PathwayGateway.VB you created in step 4.

Note
The File has now been added to your project and will be listed in your Solution Explorer.

Wednesday, June 17, 2009

Using repeater control

I store the menu categories in a table called "Sub_Category" in SQL Server, so that if I ever need to add one, I just add it to the table and it will appear on the menu. There are two fields in the table: Sub_Category_ID, and Sub_Category_Text.
Step 1 - Create the Page and Insert the Repeater Control
The Repeater control allows you to create templates to define the layout of its content. The templates are:
ItemTemplate - Use this template for elements that are rendered once per row of data.
AlternatingItemTemplate - Use this template for elements that are rendered every other row of data. This allows you to alternate background colors, for example.
HeaderTemplate - Use this template for elements that you want to render once before your ItemTemplate section.
FooterTemplate - Use this template for elements that you want to render once after your ItemTemplate section.
SeperatorTemplate - Use this template for elements to render between each row, such as line breaks.
Here is a part of the Web Form (subcategories.aspx) that contains the Repeater:
.... jpg" width="91" height="28" class="bigtext">
" Text="<%#DataBinder.Eval(Container.DataItem, "Sub_Category_Text")%>" runat="server" target="mainFrame" ID="Hyperlink1" NAME="Hyperlink1"/>
....
The Repeater has a name of "catlist". It uses the HeaderTemplate to print out the Areas image. It then uses the ItemTemplate to display a Hyperlink control that has our data in it. We'll come back to this in Step Two.
The FooterTemplate is not necessary, but I put it in here for consistency.
Step 2 - Get the Data
Now let's look at the data retrieval. Here is the Page_Load event in the Code Behind file.
private void Page_Load(object sender, System.EventArgs e) { SqlConnection conDotNet = new SqlConnection "Server=xxxxxxx;UID=xxxx;PWD=xxxxx;Database=DotNetGenius"); string sSQL = "Select sub_category_id, sub_category_text from Sub_Category"; SqlCommand cmd = new SqlCommand(sSQL, conDotNet); conDotNet.Open(); SqlDataReader dtrCat = cmd.ExecuteReader(); catlist.DataSource = dtrCat; catlist.DataBind(); }
The first five lines open a database connection and retrieve the contents of the Sub_Category table. The last two lines bind our Repeater control to the DataReader. Now, let's look again at the ItemTemplate section:
" Text="<%#DataBinder.Eval(Container.DataItem, "Sub_Category_Text")%>" runat="server" target="mainFrame" ID="Hyperlink1" NAME="Hyperlink1"/>

Once the DataBind method of the Repeater control is called, ASP.NET will loop through the DataReader and populate the Repeater with the data we specify. The Databinder.Eval method uses reflection to parse and evaluate a data-binding expression against an object at run time, in this case the object is our Repeater. So this line of code:
NavigateUrl="<%# "mainframeset.aspx?CatType=" + DataBinder.Eval(Container.DataItem,"Sub_Category_ID")%>"
will render the contents of the "Sub_Category_ID" field for each row in the DataReader.
If you spend much time with ASP.NET, you will certainly be using this control often. I hope you find it handy!

Saturday, May 2, 2009

Pagination with MSSQL Server 2005

SQL Server 2005 introduced a beautiful new world of 'ranking functions', one of which we can use to easily perform pagination directly in SQL , Which will improve performance tremendously . Only page number and page size is to be passed for pagination to Stored procedure for implementing pagination . This is easy and fast . The code snippet below is showing how to implement the pagination with sql server native method.


CREATE PROCEDURE dbo.StoredProcedureName1
(
@pi_PageNumber INT , -- Required page number
@pi_PageSize INT , -- Total number of records ro be displayed o
)
AS

BEGIN

SET NOCOUNT ON


DECLARE @StartRow INT; --This will be rownumber of first row of required page number
DECLARE @EndRow INT; -- This will be last row of page



--This line will calculate first row of the required page
SELECT @StartRow = (@pi_PageNumber * @pi_PageSize) - @pi_PageSize + 1

--This line will calculate Last row of the required page

SELECT @EndRow = @StartRow + @pi_PageSize - 1


/*
Get the "row number" from a result set. This is the basis of pagination because you need to know what row you are on to begin demanding only a subset from SQL . Move the ORDER BY clause inside the OVER clause. Basically what this is doing is telling SQL how we want the ROW_NUMBER() function to number each record.
*/



SELECT
ColumnName1, ColumnName2, ColumnName3, ColumnName4
FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY ColumnName1, ColumnName2) AS RowNumber,ColumnName1, ColumnName2, ColumnName3, ColumnName4
from
TableName1
) AS TempTable
WHERE RowNumber between @StartRow and @EndRow



/* The first query is aliased and called it "TempTable". This basically treats that inner query as a VIEW so that I could pull out that first column by it's name, RowNumber
*/

RETURN 0;

END