Friday, April 29, 2011

Protect image from being copied

Hello Friends,

Many times I am asked to protect some copyrighted images over web,
so finally I have found a better way to protect from being copied.
There are some cases by which we can copy the image
Here I have taken care of following cases
  • Right click on image and Save the Image
  • Save the Entire page and all images displayed on page will be downloaded to its Data Folder
  • in mozila Firefox, We can save the media files by following steps
    1. Right click on Page, select “View Page Info”
    2. ViewSourceSandeep
    3. It will open a window, Select “Media” tab, here a list of all files will be available
    4. select particular file and click on “Save As” button to save the media
    5. SavemediaSandeep


Now Let’s Start our main topic,that is protect image from being copied
There is a concept called Data URI scheme.
Generally to display any image on page, we use Relative_URL and if we display image using this, the images can be easily copied.
Here we will save image in database and retrieve the same
To Create table
CREATE TABLE [dbo].[Images](
 [ImageID] [int] IDENTITY(1,1) NOT NULL,
 [ImageName] [varchar](50) NULL,
 [Image] [image] NULL,
 [ext] [varchar](50) NULL,
 CONSTRAINT [PK_Images] PRIMARY KEY CLUSTERED 
(
 [ImageID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

Now,

the aspx page will be very simple like


Monday, April 4, 2011

Fetch Data from Control Without Loop- Best Use of LINQ

Hi friends….

Many times I need to generate collection type Data from GridView or Repeater or any other control.. and in that case I used to loop through each rowitem of particular control..

here each row of repeater is listitem of LINQ query.

same way you can perform for all DataBound Controls like GridView, Repeater, DataList, DropDownlist, CheckboxList, Radiobuttonlist etc…

but after using LINQ, I am able to do that very easily

here is sample of Repeater control to Get List of data

List ctrls = (from item in rptctrlList.Items.Cast()
                                    where ((CheckBox)item.FindControl("chkctrl")).Checked
                                    select new ctrlInfo()
                                    {
                                        ctrlId = Convert.ToInt32(((HiddenField)item.FindControl("hdnctrlId")).Value),
                                        UserctrlId = Convert.ToInt64(((HiddenField)item.FindControl("hdnUserctrlId")).Value),
                                    }).ToList();


now I can pass XML to database from this List<ctrlInfo> using


 



var ctrlXML = from ctrl in ctrls
                          select new XElement("ctrl",
                          new XElement("UserId", ctrl.UserId),
                          new XElement("ctrlId", ctrl.ctrlId),
                          new XElement("UserctrlId", ctrl.UserctrlId));
            ctrlsXML.Add(ctrlXML);





Now…. You can pass the XML to Stored Procedure. and in Stored Procedure


using


SELECT 
c.value('ctrlId[1]','int') As ctrlId
, c.value('UserId[1]','BigInt') As UserId
, c.value('UserctrlId[1]','BigInt') As UserctrlId
FROM @ctrlIdListXML.nodes('/ctrls/ctrl')e(c)




you can have Table of selected records of Repeater control.


using merge statement you can perform operation.


 


Hope this Helps


All the Best

Friday, April 1, 2011

Apply Frame to Image with CSS

Hello

Many times we need to display image like profile image or advertisements

and at that time we need to decorate it within frame…

 

Here we have a simplest way to apply frame which will help to set frame to any size image and unique for all..


here I have a sample code for it

<html>
<head>
<style>
img {
    background: url("shadow.gif") no-repeat scroll right bottom transparent;
    border-color: #EEEEEE -moz-use-text-color -moz-use-text-color #EEEEEE;
    border-right: medium none;
    border-style: solid none none solid;
    border-width: 1px medium medium 1px;
    padding: 4px 10px 10px 4px;}
</style>
</head>
<body>
     <img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxKSyD46sNlLs8yYLBFMz_YGOiYANzbKSUPo5YT5f2K34QvZgGOWTWF_s_aWPoe4zuVafRytM6346dkW7bkjptRImMMCLWyaCxtGgAjPD97wa7HWZ_l94H2uWxlU8V2UKIJPgvyj7sTO5x/s220/Sandeep.JPG'>
</body>
</html>



and the you can have any kind of frame image


here I am uploading a sample image


shadow


and the output you will get is


output


All the Best