Wednesday, December 3, 2014

Convert HTML to Plain Text

 public string HTMLToText(string HTMLCode)
        {
            // Remove new lines since they are not visible in HTML
            HTMLCode = HTMLCode.Replace("\n", " ");

            // Remove tab spaces
            HTMLCode = HTMLCode.Replace("\t", " ");

            // Remove multiple white spaces from HTML
            HTMLCode = Regex.Replace(HTMLCode, "\\s+", " ");

            // Remove HEAD tag
            HTMLCode = Regex.Replace(HTMLCode, "", "" , RegexOptions.IgnoreCase | RegexOptions.Singleline);

            // Remove any JavaScript
            HTMLCode = Regex.Replace(HTMLCode, "

Monday, March 3, 2014

Test Your Love


Test Your Love How much it is pass or acquire marks.

http://lovetest.singlessalad.com/?cid=4581&ax=1&clickid=0053618368096869236&ext_inv_code=103883&dfpid=102103883&oid=7813

Tuesday, February 25, 2014

Kill All Process in database sql while restoring



If there is any problem that database currently in use and you are not able to restore database than you can run this query for block all processes currently running.

Use Master
Go

Declare @dbname sysname

Set @dbname = 'CDM_HVMS'

Declare @spid int
Select @spid = min(spid) from master.dbo.sysprocesses
where dbid = db_id(@dbname)
While @spid Is Not Null
Begin
        Execute ('Kill ' + @spid)
        Select @spid = min(spid) from master.dbo.sysprocesses
        where dbid = db_id(@dbname) and spid > @spid
End
print 'done'

Monday, October 21, 2013

Check Existing record by join two tables using Linq

//Use this code to check existing record from two tables using Linq .

Chrome_VINEquipment existequipment = db.Chrome_VINEquipments.Where(x => x.VINPatternID == VinPatternID && db.WS_GenericEquipments.Any(c => c.StyleId == car.StyleId)).FirstOrDefault();

Monday, July 8, 2013

Find Item in DropDownlist


Find Item in dropdown if item find then selected or its ignored .with this code.....
ddlBody.SelectedIndex = ddlBody.Items.IndexOf(ddlBody.Items.FindByValue(Convert.ToString(lst[0].BodyId)));

Tuesday, June 25, 2013

Update row by row any field without cursor



WITH myTable2 AS
    (
    SELECT vinid, ROW_NUMBER() OVER (ORDER BY vinid) AS sequence
    FROM VehicleDescription
    )
   


UPDATE genericequipment
SET VinID = VehicleDescription.vinid
FROM VehicleDescription
JOIN genericequipment on VehicleDescription.VinPattern = genericequipment.vinPattern;

Saturday, March 9, 2013

Custom Paging in Datalist or repeater


This is a very simple custom paging technique for a developer where ha can do paging in datalist and repeater in only 5 minutes.enjoy code.....

  public void BindPhoto()
        {
            GalleryModuleController objCommentModules = new GalleryModuleController();

            List cmi;
            cmi = objCommentModules.PhotoList(0);
            if (cmi.Count > 0)
            {
                dlphotogallery.DataSource = cmi;
                dlphotogallery.DataBind();
                pds.DataSource = cmi;
                pds.AllowPaging = true;

                //to set the paging change the number 3 to your desired value

                pds.PageSize = 4;

                pds.CurrentPageIndex = CurrentPage;

                lnkbtnNext.Enabled = !pds.IsLastPage;

                lnkbtnPrevious.Enabled = !pds.IsFirstPage;

                dlphotogallery.DataSource = pds;

                dlphotogallery.DataBind();

                doPaging();
            }
        }


        protected void lnkbtnPrevious_Click(object sender, EventArgs e)
        {

            CurrentPage -= 1;
            BindPhoto();

        }

        protected void lnkbtnNext_Click(object sender, EventArgs e)
        {

            CurrentPage += 1;

            BindPhoto();

        }

        protected void dlPaging_ItemCommand(object source, DataListCommandEventArgs e)
        {

            if (e.CommandName.Equals("lnkbtnPaging"))
            {
                CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
                BindPhoto();
            }

        }

        protected void dlPaging_ItemDataBound(object sender, DataListItemEventArgs e)
        {

            LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl("lnkbtnPaging");
            if (lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
            {
                lnkbtnPage.Enabled = false;
                lnkbtnPage.Font.Bold = true;
            }

        }

        public int CurrentPage
        {
            get
            {
                if (this.ViewState["CurrentPage"] == null)

                    return 0;

                else

                    return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());

            }

            set
            {

                this.ViewState["CurrentPage"] = value;

            }

        }



        private void doPaging()
        {

            DataTable dt = new DataTable();

            dt.Columns.Add("PageIndex");

            dt.Columns.Add("PageText");

            for (int i = 0; i < pds.PageCount; i++)
            {

                DataRow dr = dt.NewRow();

                dr[0] = i;

                dr[1] = i + 1;

                dt.Rows.Add(dr);

            }

            dlPaging.DataSource = dt;

            dlPaging.DataBind();

        }

Open PopUp using jquery css and jqeury code.

This is the open popup code using jquery with appplying css .this is a very simple and attractive pop up window just applied on div.

 $(document).ready(function () {
        $('open').click(function () {
            alert('hi');
            load();
        });

        $('.close').click(function () {
            unload();

        });
    });


 function unload() {    // TO Unload the Popupbox

        $('.popup').fadeOut("slow");
        $("#container").css({ // this is just for style      
            "opacity": "1"
        });
    }

    function load() {    // To Load the Popupbox
        $('.popup').fadeIn("slow");
        $("#container").css({ // this is just for style
            "opacity": "0.3"
        });

    }


style type="text/css"
    .popup {
        display: none; /* Hide the DIV */
        position: absolute;
        _position: absolute; /* hack for internet explorer 6 */
        height: 325px;
        width: 325px;
        background: #FFFFFF;
        left: 80px;
        top: 100px;
        z-index: 100; /* Layering ( on-top of others), if you have lots of layers: I just maximized, you can change it yourself */
        margin-left: 15px;
        /* additional features, can be omitted */
        border:2px solid #ff0000;
        padding:15px;
        font-size: 15px;
        -moz-box-shadow: 0 0 5px #ff0000;
        -webkit-box-shadow: 0 0 5px #ff0000;
        box-shadow: 0 0 5px #ff0000;
     
    }
 
    #container {
        width: 100%;
        height: 100%;
    }

    a {
        cursor: pointer;
        text-decoration: none;
    }

    /* This is for the positioning of the Close Link */
    #popupBoxClose {
        font-size: 20px;
        line-height: 15px;
        right: 5px;
        top: 5px;
        position: absolute;
        color: #6fa5e2;
        font-weight: 500;
    }
   /style

Tuesday, February 26, 2013

Send mail comman code


public static void Send(string[] To, String Subject, String Body,bool IsBodyHtml)
    {
        try
        {
            var smtp = new SmtpClient
            {
                Host = Host,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(SMTPUser, Password),
            };

            var message = new MailMessage()
            {
                Subject = Subject,
                Body = Body
            };

            foreach (var vv in (from s in To select (new MailAddress(s))))
            {
                message.To.Add(vv);
            }
           
            message.From = new MailAddress(From);
            message.IsBodyHtml = IsBodyHtml;
            smtp.Send(message);
        }
        catch
        {
        }
    }

Wednesday, February 13, 2013

Remove item from array list of multiple column.


This problem occured when i was doing project in dotnetnuke 5.6.3 so in arraylist there have multiple columns and I and remove row which contains particular value of type.this is the code for solve this problem.

DotNetNuke.Entities.Users.UserController oUserController = new DotNetNuke.Entities.Users.UserController();
           
            ArrayList listroles = oUserController.GetUsers(this.PortalId, true, true);
            int j = 0;

            for (int i = 0; i < listroles.Count; i++)
            {
                DotNetNuke.Entities.Users.UserInfo info = (DotNetNuke.Entities.Users.UserInfo)listroles[i];
                if (info.Username == UserInfo.Username)
                {
                    listroles.Remove(info);
                }
            }

Tuesday, January 22, 2013

Split function in sql server


I have created a function for spliting the string of any type with the required delimeter which you want to specify hope so this function will solve your splitting problem in sql server.

CREATE FUNCTION dbo.fnSplit(
    @sInputList VARCHAR(8000) -- List of delimited items
  , @sDelimiter VARCHAR(8000) = ',' -- delimiter that separates items
) RETURNS @List TABLE (item VARCHAR(8000))

BEGIN
DECLARE @sItem VARCHAR(8000)
WHILE CHARINDEX(@sDelimiter,@sInputList,0) <> 0
 BEGIN
 SELECT
  @sItem=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@sDelimiter,@sInputList,0)-1))),
  @sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@sDelimiter,@sInputList,0)+LEN(@sDelimiter),LEN(@sInputList))))

 IF LEN(@sItem) > 0
  INSERT INTO @List SELECT @sItem
 END

IF LEN(@sInputList) > 0
 INSERT INTO @List SELECT @sInputList -- Put the last item in
RETURN
END
GO

Tuesday, January 8, 2013

Write Div Content on new window


We want to open new window and write content on it which we want to write into it.
$("#adv").click(function () {
            var html = $("#dvcontent").html();
            var w = window.open();
            w.document.writeln(html);
       });

Monday, January 7, 2013

Integrate Google Map into our MVC application


This is the code for integrating google map into our all types application just u paste this code and pass the longitude and latitude into function it ll automtically take the location and show ur desired place to u and you can manage it urself as u want.enjoy.....
script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAVc
JQrx7VsumiP2heFwp
6URQLaiSrhXTkLq3m
A9rOmHpVsHwBjxT
g7C5-XXHl634dCROpHwK
MO9BzmQ&sensor=true_or_false"
            type="text/javascript" script




    script type="text/javascript"

        function initialize() {
            if (GBrowserIsCompatible()) {
                var map = new GMap2(document.getElementById("map_canvas"));
                map.setCenter(new GLatLng(20.593684, 78.96288), 13);
                map.setUIToDefault();
            }
        }

   script

  body onload="initialize()" onunload="GUnload()"
    div id="map_canvas" style="width: 500px; height: 300px">
  body

   

Sunday, December 30, 2012

Detect Browser Refresh to avoid events fired again in ASP.NET


If you have created an aspx page using C# and ASP.NET and have put a button on it. And in the Click event of this button if you are inserting some data in database , after click if user refresh the page than click event gets fired again resulting data insertion to database again, to stop events on the page getting fired on browser refresh we need to write bit of code to avoid it.

In this example I’ve put a Label and a Button on the page, on click the label Text becomes Hello and when I refresh the page label's text again becomes Hello

Markup




Now in the Page_Load event I m creating a Session Variable and assigning System date and time to it , and in Page_Prerender event I am creating a Viewstate variable and assigning Session variable's value to it than in button's click event I am checking the values of Session variable and Viewstate variable if they both are equal than page is not refreshed otherwise it has been refreshed 

  
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["CheckRefresh"] =
Server.UrlDecode(System.DateTime.Now.ToString());
}
}
protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
//Label2.Text = imgbtn.ToolTip;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
{
Label1.Text = "Hello";
Session["CheckRefresh"] =
Server.UrlDecode(System.DateTime.Now.ToString());
}
else
{
Label1.Text = "Page Refreshed";
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
ViewState["CheckRefresh"] = Session["CheckRefresh"];
}
}

Saturday, December 22, 2012

Code for update panel postback problem solving by using Jquery


 I have a grid when I postback this grid by linkbutton which is in this grid jquery function was not working in mouse over so I paste this code into update panel to avoid postback .

    script type ="text/javascript"
                var prm = Sys.WebForms.PageRequestManager.getInstance();
                prm.add_endRequest(function () {
                    grid();
                });
            script

Saturday, September 22, 2012

Refresh Page Issue in ASP.Net


Introduction

In Web Programming, the refresh click or postback is the big problem which generally developers face. So in order to avoid the refresh page issues like, if user refreshes the page after executing any button click event/method, the same method gets executed again on refresh. But this should not happen, so here is the code to avoid such issues.

Using the Code

Here the page's PreRender event and ViewState variable helps to differentate between the Button click event call or the Refresh page event call. For example, We have a web page having button to display text entered in text box to the Label.
So when page is first time loaded, then a session["update"] object is assigned by some unique value, and then thePreRender event is being called, where that session is assigned to the viewstate variable.
And on button click event, the session assigning code from page load will never called, as it is postback, so it directly calls the button click event where there is check whether the session and viewstate variables have same value. Here both values will be same. At the end of the click event method, the session variable is assigned with new unique value. Then always after click event, the PreRender event gets called where that newly assigned session value is assigned to viewstate variable.
So whenever the page is being refreshed, viewstate value will become previous value (previous value is taken from viewstate hidden control) which will never match with current session value. So whenever the control goes in button click event, the match condition never gets satisfied hence code related to button click never gets executed.

Points of Interest

Here we can understand the page events flow as well as Viewstate variable's workflow easily.
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack) // If page loads for first time
    {
        // Assign the Session["update"] with unique value
        Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString()); 
        //=============== Page load code =========================




        //============== End of Page load code ===================
    }
}

protected void btnDisplay_Click(object sender, EventArgs e)
{ 
    // If page not Refreshed
    if (Session["update"].ToString() == ViewState["update"].ToString())
    {
        //=============== On click event code ========================= 

        lblDisplayAddedName.Text = txtName.Text;

        //=============== End of On click event code ==================

        // After the event/ method, again update the session 

        Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString()); 
    }
    else // If Page Refreshed
    {
        // Do nothing 
    }
}

protected override void OnPreRender(EventArgs e)
{
    ViewState["update"] = Session["update"];
}

Saturday, July 7, 2012

One Simple Procedure for Cursor.


Procedure That make insertion into table according weekdays which weekday data I have in my one table.

ALTER PROC [dbo].[CRS_VehicleAdultChildPrice_Flat]        
@pk_VehiclePriceID int,      
@WEEKDAYID NVARCHAR (255),
@SeasonEndDate NVARCHAR(25),
@SeasonStartDate NVARCHAR(25)    
AS      
DECLARE @fkVehiclePriceID int      
DECLARE @SessionDate  NVARCHAR(25)        
DECLARE @ChildNo int
DECLARE @ChildMinAge int
DECLARE @ChildMaxAge int    
DECLARE @AdultPrice decimal(18,2)
DECLARE @ChildPrice decimal(18,2)        
DECLARE @TourDate datetime    
DECLARE @Culture nvarchar(10)      
DECLARE @CreatedBy nvarchar(255)      
DECLARE @ModifiedBy nvarchar(255)    
DECLARE @timings nvarchar(1000)  

DECLARE @CUR CURSOR      
DECLARE @CURDATE CURSOR        

SET @CUR = CURSOR FOR SELECT        
pk_VehiclePriceID    
,AdultPrice
,VMS_TBL_VehiclePrice.Culture      
,VMS_TBL_VehiclePrice.CreatedBy      
,VMS_TBL_VehiclePrice.ModifiedBy
,VMS_TBL_VehiclePrice.timing


 FROM VMS_TBL_VehiclePrice        
INNER JOIN VMS_VehicleAdultPrice_Detail ON VMS_VehicleAdultPrice_Detail.fkVehiclePriceId=VMS_TBL_VehiclePrice.pk_VehiclePriceID      
WHERE pk_VehiclePriceID=@pk_VehiclePriceID ORDER BY pk_VehiclePriceID    
OPEN @CUR      
FETCH NEXT      
FROM @CUR INTO        
@fkVehiclePriceID,    
@AdultPrice,      
@Culture,      
@CreatedBy,      
@ModifiedBy,
@timings      
 
WHILE @@FETCH_STATUS = 0      
BEGIN      
     
   SET @CURDATE = CURSOR FOR SELECT        
   DATE_NAME FROM TBL_DATE_WEEKDAY WHERE WEEKDAYID IN (SELECT * FROM DBO.SPLIT(@WEEKDAYID,',')) AND ( CONVERT(DATETIME,DATE_NAME)>=Convert(DATETIME,@SeasonStartDate) AND CONVERT(DATETIME,DATE_NAME) <=Convert(DATETIME,@SeasonEndDate))      
   OPEN @CURDATE      
   FETCH NEXT      
   FROM @CURDATE INTO @SessionDate      
   print @@FETCH_STATUS      
   WHILE @@FETCH_STATUS = 0      
   BEGIN      
   print @SessionDate      
         
     
         INSERT INTO VMS_VehicleAdultPrice_Flat(fkVehiclePriceID, AdultPrice,TourDate, Culture, CreatedBy, CreatedOnDate, ModifiedBy, ModifiedOnDate, Row_Guid, Row_Status,timings)      
          VALUES(@fkVehiclePriceID,@AdultPrice,@SessionDate ,@Culture,@CreatedBy,GETDATE(),@ModifiedBy,GETDATE(),NEWID(),1,@timings)          
     
           
     
   FETCH NEXT      
   FROM @CURDATE INTO @SessionDate    
   END      
   CLOSE @CURDATE      
   DEALLOCATE @CURDATE      
   
FETCH NEXT      
FROM @CUR INTO @fkVehiclePriceID,  
   
@AdultPrice,  

@Culture,      
@CreatedBy,      
@ModifiedBy,
@timings      
 
 
END    
CLOSE @CUR      
DEALLOCATE @CUR



SET @CUR = CURSOR FOR SELECT        
pk_VehiclePriceID    
,ChildNo
,ChildMinAge
,ChildMaxAge
,ChildPrice

,VMS_TBL_VehiclePrice.Culture      
,VMS_TBL_VehiclePrice.CreatedBy      
,VMS_TBL_VehiclePrice.ModifiedBy

 FROM VMS_TBL_VehiclePrice        
INNER JOIN VMS_TBL_ChildPrice_Detail ON VMS_TBL_ChildPrice_Detail.fkVehiclePriceId=VMS_TBL_VehiclePrice.pk_VehiclePriceID        
WHERE pk_VehiclePriceID=@pk_VehiclePriceID ORDER BY pk_VehiclePriceID    
OPEN @CUR      
FETCH NEXT      
FROM @CUR INTO        
@fkVehiclePriceID,
@ChildNo,      
@ChildMinAge,      
@ChildMaxAge,      
@ChildPrice,      
     
@Culture,      
@CreatedBy,      
@ModifiedBy      
 
WHILE @@FETCH_STATUS = 0      
BEGIN      
     
   SET @CURDATE = CURSOR FOR SELECT        
   DATE_NAME FROM TBL_DATE_WEEKDAY WHERE WEEKDAYID IN (SELECT * FROM DBO.SPLIT(@WEEKDAYID,',')) AND ( CONVERT(DATETIME,DATE_NAME)>=Convert(DATETIME,@SeasonStartDate) AND CONVERT(DATETIME,DATE_NAME) <=Convert(DATETIME,@SeasonEndDate))      
   OPEN @CURDATE      
   FETCH NEXT      
   FROM @CURDATE INTO @SessionDate      
   print @@FETCH_STATUS      
   WHILE @@FETCH_STATUS = 0      
   BEGIN      
   print @SessionDate      
         
       
       
     
        INSERT INTO VMS_VehicleChildPrice_Flat(fkVehiclePriceID, ChildNo, ChildMinAge, ChildMaxAge, ChildPrice, TourDate, Culture, CreatedBy, CreatedOnDate, ModifiedBy, ModifiedOnDate, Row_Guid, Row_Status)      
          VALUES(@fkVehiclePriceID, @ChildNo, @ChildMinAge, @ChildMaxAge,@ChildPrice,@SessionDate ,@Culture,@CreatedBy,GETDATE(),@ModifiedBy,GETDATE(),NEWID(),1)          
     
     
     
     
   FETCH NEXT      
   FROM @CURDATE INTO @SessionDate    
   END      
   CLOSE @CURDATE      
   DEALLOCATE @CURDATE      
   
FETCH NEXT      
FROM @CUR INTO @fkVehiclePriceID,  
@ChildNo,      
@ChildMinAge,      
@ChildMaxAge,  
 
@ChildPrice,
@Culture,      
@CreatedBy,      
@ModifiedBy      
 
 
END    
CLOSE @CUR      
DEALLOCATE @CUR

Time Drop Down Filling.


 public void GetTiming()
        {
            ArrayList aTime = new ArrayList();
            int interval = Convert.ToInt32(txtTimeInterval.Text);
            DateTime EndTime = Convert.ToDateTime(txtEndTime.Text);
            DateTime StartTime = Convert.ToDateTime(txtStartTime.Text);
           
            for (int i = interval; i <= 1440+1; i++ )
            {
                if (StartTime != EndTime)
                {
                  aTime.Add(StartTime.ToString("HH:mm"));
                  StartTime = StartTime.AddMinutes(interval);
               
                }
                else if (StartTime == EndTime)
                {
                    aTime.Add(StartTime.ToString("HH:mm"));
                    break;
                }
            }
            chkTiming.DDList.DataSource = aTime;
            chkTiming.DataBind();
            chktime.Visible = true;
           
        }

Regular Expression For Specific Time Format("HH:MM")


asp:TextBox ID="txtStartTime" runat="server" Width="100" asp:TextBox
                                                                                    asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="txtStartTime"
                                                                                            Display="None" ErrorMessage="Start Time missing" SetFocusOnError="True"
                                                                                            ValidationGroup="validComboAddGrp" asp:RequiredFieldValidator
                                                                                            asp:RegularExpressionValidator ID="regextxtSessionTime" runat="server"
    ControlToValidate="txtStartTime"
    ValidationExpression="^([0-1][0-9]|[2][0-3]):([0-5][0-9])$"
    ErrorMessage="You must enter a valid time. Format: HH:MM"
    Display="none"
    SetFocusOnError="true" ValidationGroup="validComboAddGrp"
  asp:RegularExpressionValidator