Popular Posts

Thursday, November 10, 2011

Refer to parent URL from iFrame contained in parent URL's page


set your URL in "javascript:window.parent.location" for refer to parent URL.

Example:

<a href="javascript:window.parent.location='http://www.xyz.com'">
<img src="./imgslide/1.jpg" height="250px" width="420px" />
</a>

Monday, October 31, 2011

Download images

public static void downloadFile(System.Web.UI.Page pg, string filepath)
    {
        pg.Response.AppendHeader("content-disposition", "attachment; filename=" + new FileInfo(filepath).Name);
        pg.Response.ContentType = getContentType(new FileInfo(filepath).Extension);
        pg.Response.WriteFile(filepath);
        pg.Response.End();
    }



   public static string getContentType(string Fileext)
    {

        string contenttype = "";
        switch (Fileext)
        {
            case ".xls":
                contenttype = "application/vnd.ms-excel";
                break;
            case ".doc":
                contenttype = "application/msword";
                break;
            case ".ppt":
                contenttype = "application/vnd.ms-powerpoint";
                break;
            case ".pdf":
                contenttype = "application/pdf";
                break;
            case ".jpg":
            case ".jpeg":
                contenttype = "image/jpeg";
                break;
            case ".gif":
                contenttype = "image/gif";
                break;
            case ".ico":
                contenttype = "image/vnd.microsoft.icon";
                break;
            case ".zip":
                contenttype = "application/zip";
                break;
            default: contenttype = "";
                break;
        }
        return contenttype;
    }

calling:


downloadFile(this.Page, Server.MapPath("~/images/layout_web.jpg"));

Random value/Image from Javascript Array



For load Random Images

var arrName = new Array(2);
  arrName[0] = "http://abc.com/1.png";
  arrName[1] = " http://abc.com/2.png";

for link on Images

var arrLink = new Array(2);
  arrLink[0] = "http://abc.com/xyz.aspx?id=1";
  arrLink[1] = " http://abc.com/xyz.aspx?id=2";


  var firstRandomNumber = (Math.round((Math.random()*14)+1))

Load Randon Image and Link.

  document.write("<a href="+arrLink[firstRandomNumber]   +"> "+"<img src= "  + arrName[firstRandomNumber]+">");


Sunday, September 11, 2011

Remove Iframe Border in IE

when we are using Iframe then  Iframe border are showing in IE not in Firefox,for resolve this we have to set FrameBorder=0.

<iframe src="../navigation.aspx" style="margin-bottom: 0px; height: 34px; width: 90%;
                        margin-top: 0px; padding-bottom: 0;" scrolling="no" frameBorder="0" ></iframe>


Monday, September 5, 2011

Delete,Edit record from Gridview

Edit record from Gridview in ASP.Net using RowEditingg Event.
 protected void Gridview1 _RowEditing(object sender, GridViewEditEventArgs e)
    {
             strId= gv.Rows[e.NewEditIndex].Cells[0].Text;
    }


Delete record from Gridview in ASP.Net using RowDeleting Event.


protected void gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string ReferralId = (gv.Rows[e.RowIndex].Cells[0]).Text;
        Delete("usp_DeleteCisomer " + ReferralId + "");
        lblError.Text = "Record Delete Successfully!";
 }

Thursday, August 18, 2011

Delete Duplicate record from Table.

create table t1(id int,na varchar(30))
Go
insert into t1 select 1,'Jon'
insert into t1 select 2,'Raj'
insert into t1 select 1,'Jon'
insert into t1 select 3,'SK'
GO
select * from t1
GO
delete top(1) from t1 where id=1

Tuesday, July 26, 2011

Permission to User

Give permission to user for execute object in SQL server.

grant execute on OBJECT_NAME to USERNAME

Example:-
grant execute on usp_store to user_jasraj

Permission on Table
grant insert on tblName to user_JasRaj




Thursday, June 2, 2011

Insert data in SQL Table from XML




--select * from sp_help  tbl_Web_Fdbk_Answers
--select * from tbl_Web_Fdbk_Feedback

create proc usp_AnswerInsert
@RetrieveXMLDoc xml   
AS
declare @docHandler int
exec sp_xml_preparedocument @docHandler output,@RetrieveXMLDoc
declare @error nvarchar(max)
set @error = '0'
begin tran
    declare @FeedbackID int = null
    declare @QuestionID int = null
    declare @DateSubmitted date = null
    declare @Score int
    declare @chk bit
         --set @InsertId=SCOPE_IDENTITY()
    select @FeedbackID =MAX(FeedbackID ) from tbl_Web_Fdbk_Feedback
   
        select identity(int,1,1)SNo,QuestionID,Score into #tempOpt from openxml (@docHandler,'DocumentElement/Questions',2)
        --select * from #tempOpt
       
            with(QuestionID int,Score int)       
            declare @NewSNo int
            set @NewSNo =1
            select    @QuestionID=QuestionID,@Score=Score from #tempOpt where SNo = @NewSNo
            select @QuestionID
        while @@rowcount > 0
        begin
        select 'Right2'
                Insert into tbl_Web_Fdbk_Answers(FeedbackID,QuestionID,Score,DateSubmitted)Values(@FeedbackID,@QuestionID,@Score,GETDATE())
   
                set @NewSNo = @NewSNo + 1
                select    @QuestionID=QuestionID,@Score=Score from #tempOpt where SNo = @NewSNo   
        end
        commit tran
--if @error = '0'
--begin
--    select 'Right'
--    commit tran
--end
--else
--begin
--    select 'Fail'
--    rollback tran
--end



--===========
usp_AnswerInsert '<DocumentElement>
  <Questions>
    <QuestionID>1</QuestionID>
    <Score>2</Score>
  </Questions>
  <Questions>
    <QuestionID>2</QuestionID>
    <Score>4</Score>
  </Questions>
  <Questions>
    <QuestionID>3</QuestionID>
    <Score>6</Score>
  </Questions>
  <Questions>
    <QuestionID>4</QuestionID>
    <Score>8</Score>
  </Questions>
  <Questions>
    <QuestionID>5</QuestionID>
    <Score>6</Score>
  </Questions>
  <Questions>
    <QuestionID>6</QuestionID>
    <Score>4</Score>
  </Questions>
</DocumentElement>'

Sunday, May 29, 2011

Change Object Owner in MS SQL Server

SELECT  'exec sp_changeobjectowner ''' + name + ''', ''dbo''' FROM    sysobjects WHERE   type = 'U'     AND uid != 1 ORDER BY name

after execute this result
 

Friday, May 27, 2011

Google Sandbox URL

 https://sandbox.google.com/checkout/sell/
https://www.secpay.com/java-bin/services/SECCardService?wsdl

Monday, May 23, 2011

Encryption and Decryption in VB.Net

Public Class clsCrypto
    Private bytIV() As Byte = {121, 241, 10, 1, 132, 74, 11, 39, 255, 91, 45, 78, 14, 211, 22, 62}
    Private Const chrKeyFill As Char = "X"c
    Private Const strTextErrorString As String = "#ERROR - {0}"
    Private Const intMinSalt As Integer = 4
    Private Const intMaxSalt As Integer = 8
    Private Const intHashSize As Integer = 16
    Private Const intKeySize As Integer = 32
    Public Function EncryptString128Bit(ByVal strPlainText As String, ByVal strKey As String) As String
        Try
            Dim bytPlainText() As Byte
            Dim bytKey() As Byte
            Dim bytEncoded() As Byte
            Dim objMemoryStream As New MemoryStream
            Dim objRijndaelManaged As New RijndaelManaged

            strPlainText = strPlainText.Replace(vbNullChar, String.Empty)
            bytPlainText = Encoding.UTF8.GetBytes(strPlainText)
            bytKey = ConvertKeyToBytes(strKey)
            Dim objCryptoStream As New CryptoStream(objMemoryStream, _
                objRijndaelManaged.CreateEncryptor(bytKey, bytIV), _
                CryptoStreamMode.Write)
            objCryptoStream.Write(bytPlainText, 0, bytPlainText.Length)
            objCryptoStream.FlushFinalBlock()
            bytEncoded = objMemoryStream.ToArray
            objMemoryStream.Close()
            objCryptoStream.Close()
            Return Convert.ToBase64String(bytEncoded)
        Catch ex As Exception
            Return String.Format(strTextErrorString, ex.Message)
        End Try
    End Function

    Public Function DecryptString128Bit(ByVal strCryptText As String, ByVal strKey As String) As String
        Try
            Dim bytCryptText() As Byte
            Dim bytKey() As Byte
            Dim objRijndaelManaged As New RijndaelManaged

            bytCryptText = Convert.FromBase64String(strCryptText)
            bytKey = ConvertKeyToBytes(strKey)

            Dim bytTemp(bytCryptText.Length) As Byte
            Dim objMemoryStream As New MemoryStream(bytCryptText)
            Dim objCryptoStream As New CryptoStream(objMemoryStream, _
                objRijndaelManaged.CreateDecryptor(bytKey, bytIV), _
                CryptoStreamMode.Read)
            objCryptoStream.Read(bytTemp, 0, bytTemp.Length)
            objMemoryStream.Close()
            objCryptoStream.Close()
            Return Encoding.UTF8.GetString(bytTemp).Replace(vbNullChar, String.Empty)
        Catch ex As Exception
            Return String.Format(strTextErrorString, ex.Message)
        End Try

    End Function

    Public Function ComputeMD5Hash(ByVal strPlainText As String, Optional ByVal bytSalt() As Byte = Nothing) As String
        Try
            Dim bytPlainText As Byte() = Encoding.UTF8.GetBytes(strPlainText)
            Dim hash As HashAlgorithm = New MD5CryptoServiceProvider()

            If bytSalt Is Nothing Then
                Dim rand As New Random
                Dim intSaltSize As Integer = rand.Next(intMinSalt, intMaxSalt)
                bytSalt = New Byte(intSaltSize - 1) {}
                Dim rng As New RNGCryptoServiceProvider
                rng.GetNonZeroBytes(bytSalt)
            End If
            Dim bytPlainTextWithSalt() As Byte = New Byte(bytPlainText.Length + bytSalt.Length - 1) {}
            bytPlainTextWithSalt = ConcatBytes(bytPlainText, bytSalt)
            Dim bytHash As Byte() = hash.ComputeHash(bytPlainTextWithSalt)
            Dim bytHashWithSalt() As Byte = New Byte(bytHash.Length + bytSalt.Length - 1) {}
            bytHashWithSalt = ConcatBytes(bytHash, bytSalt)
            Return Convert.ToBase64String(bytHashWithSalt)
        Catch ex As Exception
            Return String.Format(strTextErrorString, ex.Message)
        End Try
    End Function

    Public Function VerifyHash(ByVal strPlainText As String, ByVal strHashValue As String) As Boolean
        Try
            Dim bytWithSalt As Byte() = Convert.FromBase64String(strHashValue)
            If bytWithSalt.Length < intHashSize Then Return False
            Dim bytSalt() As Byte = New Byte(bytWithSalt.Length - intHashSize - 1) {}
            Array.Copy(bytWithSalt, intHashSize, bytSalt, 0, bytWithSalt.Length - intHashSize)
            Dim strExpectedHashString As String = ComputeMD5Hash(strPlainText, bytSalt)
            Return strHashValue.Equals(strExpectedHashString)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Private Function ConcatBytes(ByVal bytA() As Byte, ByVal bytB() As Byte) As Byte()
        Try
            Dim bytX() As Byte = New Byte(((bytA.Length + bytB.Length)) - 1) {}
            Array.Copy(bytA, bytX, bytA.Length)
            Array.Copy(bytB, 0, bytX, bytA.Length, bytB.Length)
            Return bytX
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Private Function ConvertKeyToBytes(ByVal strKey As String) As Byte()
        Try
            Dim intLength As Integer = strKey.Length
            If intLength < intKeySize Then
                strKey &= Strings.StrDup(intKeySize - intLength, chrKeyFill)
            Else
                strKey = strKey.Substring(0, intKeySize)
            End If
            Return Encoding.UTF8.GetBytes(strKey)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class

Thursday, May 19, 2011

Remove Char from String

CREATE FUNCTION UFRemoveChar
(
@String nvarchar(20) )
RETURNS nvarchar(20)
AS
BEGIN 
 DECLARE @Point INTEGER
 SELECT @Point = PATINDEX('%[^a-zA-Z0-9_]%', @String) 
     WHILE @Point > 0  
     BEGIN  
      SELECT @String = STUFF(@String, @Point, 1, '')  
      SELECT @Point = PATINDEX('%[^a-zA-Z0-9_]%', @String)  
     END 
 RETURN @String 
END

Sunday, May 8, 2011

Delete Duplicate Char from String


create FUNCTION DeleteDuplicateCharFromAtring(@String AS varchar(max))
RETURNS varchar(max)
AS
BEGIN
   DECLARE @Index int
   SET @Index = LEN(@String)
   WHILE @Index > 1
       BEGIN
           IF CHARINDEX(SUBSTRING(@String, @Index, 1), @String) < @Index
               BEGIN
                   SET @String = STUFF(@String, @Index, 1, '')
               END
           SET @Index = @Index - 1
       END
   RETURN @String
END

Read Log file of SQL Server

             There are two types log file maintain SQL Server database (1) SQL server Log file and (2) SQL Agent log file.

we can read both log files by using inbuilt SP.
this SP using 4 type parameter.

(1)0-for SQL server log file (2) 1-for SQL Agent log file

Default parameter : SQL server 
 xp_readerrorlog 0

we can find log record by keyword.
   xp_readerrorlog 0,1,'Backup'


other we can know log file size by date.
same parameter 0,1.

sp_enumerrorlogs 1



Tuesday, May 3, 2011

Get Duplicate Record from SQL Table


1) SELECT ContactEmailAddress, COUNT(ContactEmailAddress) AS NumOccurrences FROM CustomerMaster GROUP BY ContactEmailAddress HAVING ( COUNT(ContactEmailAddress) > 1 )


2) SELECT ContactEmailAddress FROM CustomerMaster GROUP BY ContactEmailAddress HAVING ( COUNT(ContactEmailAddress) = 1 )

Friday, April 29, 2011

Get data in XML format from SQL

this return data in XML   format

select * from sales  for xml auto

Add unique Field in select statement


SELECT FieldName = IDENTITY(int, 1, 1),barcode,stockid  INTO NewTable FROM sales

select * from NewTable

Thursday, April 28, 2011

Get Last Inserted Identity value

create table invoice(id int identity,amt numeric(18,2))

insert into invoice  select 25000

SELECT SCOPE_IDENTITY() 

Wednesday, April 27, 2011

Remove HTML Tag Function


create FUNCTION udfRemoveHTMLTag
(
@vrHTMLString VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @firstIndex INT
DECLARE @LastIndex INT
DECLARE @TotalLength INT
DECLARE @firstIndex2 INT
DECLARE @LastIndex2 INT
DECLARE @TotalLength2 INT

SET @firstIndex = CHARINDEX('<',@vrHTMLString)
SET @LastIndex = CHARINDEX('>',@vrHTMLString,CHARINDEX('<',@vrHTMLString))
SET @TotalLength = (@LastIndex - @firstIndex) + 1

WHILE @firstIndex > 0 AND @LastIndex > 0 AND @TotalLength > 0
    BEGIN
        SET @vrHTMLString = STUFF(@vrHTMLString,@firstIndex,@TotalLength,'')
        SET @firstIndex = CHARINDEX('<',@vrHTMLString)
        SET @LastIndex = CHARINDEX('>',@vrHTMLString,CHARINDEX('<',@vrHTMLString))
        SET @TotalLength = (@LastIndex - @firstIndex) + 1
    END
SET @firstIndex2 = CHARINDEX('&',@vrHTMLString)
SET @LastIndex2 = CHARINDEX(';',@vrHTMLString,CHARINDEX('&',@vrHTMLString))
SET @TotalLength2 = (@LastIndex2 - @firstIndex2) + 1

WHILE @firstIndex2 > 0 AND @LastIndex2 > 0 AND @TotalLength2 > 0
    BEGIN
        SET @vrHTMLString = STUFF(@vrHTMLString,@firstIndex2,@TotalLength2,'')
        SET @firstIndex2 = CHARINDEX('&',@vrHTMLString)
        SET @LastIndex2 = CHARINDEX(';',@vrHTMLString,CHARINDEX('&',@vrHTMLString))
        SET @TotalLength2 = (@LastIndex2 - @firstIndex2) + 1
    END
RETURN LTRIM(RTRIM(@vrHTMLString))
END

Monday, April 25, 2011

Recursive Store Procedure


create proc [dbo].[dba_1]
@agentcode varchar(20),
@level int,
@parentagent varchar(20),
@fromdate datetime,
@uptodate datetime
as
set nocount on
DECLARE @custtable TABLE
( Custcode varchar(20))

DECLARE @agenttable TABLE
( id int identity(1,1),agentcode varchar(20),parentagent_t varchar(20) )

insert into @custtable select na from cust where acode=@agentcode

declare @amt numeric(18,3),@ID  int,@agent_code_local varchar(20)

select @amt=sum(instlamt) from gstockch where na=@agentcode and childna in (selecT * from @custtable)
and dt between @fromdate and @uptodate insert into dba_table
select @agentcode,@amt,@level,@parentagent

set @level=@level+1

insert into @agenttable select na,@agentcode from agent where imme=@agentcode

declare @intloop int,@intuptoloop int,@parentagentttt varchar(20)
set @intloop=1
set @intuptoloop=(SELECT count(1) FROM @agenttable)
while @intloop<=@intuptoloop
begin
    select @agent_code_local=agentcode,@parentagentttt=parentagent_t from @agenttable where id=@intloop
    EXEC dba_1 @agent_code_local,@level,@parentagentttt,@fromdate,@uptodate
    set @intloop=@intloop+1
end