How to remove specific session in asp.net




You can set session element to null.

Example:-

Session["sessionname"] = null;

Posted in | 0 comments

How to parse html in C#?

First

You Can use Html Agility Pack
Details is availbale at 
http://html-agility-pack.net/?z=codeplex

This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).

Second

using Fizzler that takes a jQuery/Sizzler approach to selecting HTML elements. It's based on HTML Agility Pack.Details available at below location.

https://code.google.com/archive/p/fizzler/

Posted in | 0 comments

Sending mail from my gmail account through .Net

Below is sample to send mail from your gmail account.

We will use System.Net.Mail to send mail from gmail account.

using System.Net;
using System.Net.Mail;
var fromAddress = new MailAddress("fromaddress@gmail.com", "Your Name");
var toAddress = new MailAddress("toaddress@example.com", "Receipt Name");
const string fromPassword = "YourPassword";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}

Posted in | 0 comments

Difference between ScriptManager and ScriptManagerProxy in asp.net

You can only have one script manager per page but you can have multiple ScriptManagerProxy.

Used ScriptManagerProxy if you have the script manager in your master for instance which will go across all pages but you want a script manager reference in an underlying page or user control. 

In that instance you would add the proxy. If you added another script manager the page would error.

Posted in | 0 comments

Run First Application in Angular 2 (Angular 2 base project).


Run First Application in Angular 2 (Angular 2 base project).


è    Need to install node.js from below location.
(Install Latest version of node.js)

è    Run below command from node.js command prompt

npm install –g @angular/cli

ng new myapp

cd myapp

ng serve

Now you will see blow output.




Now run your application from localhost:4200  (mention in above command output). You may see different output base on version.



Posted in Labels: | 0 comments

How to upgrade Node.Js to latest version

How to upgrade Node.Js to latest version.

For Linux/Max

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

Instead of stable you can also specify a desired version.

Sudo n 0.8.21

For windows

You can update npm using below command.

npm update npm -g

However to update node.js better you will reinstall from node.js website.

Posted in Labels: | 0 comments

Common Error in Angular2. Can't bind to 'ngModel' since it isn't a known property of 'input'

Common Error in Angular2. 
Can't bind to 'ngModel' since it isn't a known property of 'input'

This error you will received if you didn't included FormModule in your module.

Better way to resolve this defect is include FormModule in app.module.ts


import { FormsModule } from '@angular/forms';


@NgModule({

  imports: [

    FormsModule

  ],

})


Posted in Labels: | 1 comments

Angular 2 trigger change detection.

There are three way to implement change detection in Angular 2.

1. ChangeDetectorRef.detectChanges() 

   This is most common used.
   This will Checks only in component and its children.
   Details of class can be read at
   https://angular.io/api/core/ChangeDetectorRef#!#detectChanges-anchor

2. ApplicationRef.tick()

   It will check for full component tree.
   Details of class can be read at
   https://angular.io/api/core/ApplicationRef#!#tick-anchor

3. NgZone.run(callback)

   It will check the full component tree after executing the callback function.
   Details of class can be read at
   https://angular.io/api/core/NgZone#!#run-anchor

You can choose one method from above.

inject ApplicationRef, NgZone, or ChangeDetectorRef into your component

Hope this will be help full.

Posted in Labels: | 0 comments

Share value from one component to another component in Angular 2.

Hello,

You can share value between components using Shared service.

Below is sample code for it.

in Share Service.



export class SharedService {
  private name = '';

  savedata(str){
    this.name=str; 
  }

  getData:string()
  {
    return this.name;
  }
} 


In First Component.



@Component({
  template: `
    
<input #myVal type="text" />
<button (click)="send(myVal.value)>Send</button>
`, }) export class FirstComponent{ constructor(service:SharedService){ this.service=service; } send(str){ this.service.saveData(str); } }

In Second Component



export class SecondComponent   {

  constructor(service:SharedService)
  {
    this.service=service;   
    this.myName=service.getData();
  }

}

Hope this will help you.

Posted in Labels: | 0 comments

Scroll to top of page in Angular 2 (Using routing)

Hello,

Sometime we need to move on next page using clicking on page bottom link.


In Angular 2 there is a problem. Next page will not move directly to the top of the page.


This may give bad impression to end user.


Below is one way to move focus on top of the page.


register a listener of route change on main component and scroll to 

top on route changes.

Shown in below example.



 


import { Component, OnInit } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';

@Component({
    selector: 'main-app',
    template: '',
})

export class MainComponent implements OnInit {
    constructor(private router: Router) { }

    ngOnInit() {
        this.router.events.subscribe((evt) => {
            if (!(evt instanceof NavigationEnd)) {
                return;
            }
            window.scrollTo(0, 0)
        });
    }
}




You can also used document.body.scrollTop = 0. 

 Hope this will helpful.

Posted in Labels: | 0 comments

Generate Guid In Angular 2 Application (type Script)

Generate Guid In Angular 2 Application (type Script)


Hello,

Below is code block to generate GUID in angular 2 application.


 function newguidgen() {  
  function id() {  
   return Math.floor((1 + Math.random()) * 0x10000)  
    .toString(16)  
    .substring(1);  
  }  
  return id() + id() + '-' + id() + '-' + id() + '-' +  
   id() + '-' + id() + id() + id();  
 }  

Posted in Labels: | 0 comments

Could not load file or assembly 'system.web.http' or one of its dependencies. The located seembly's manifest definition does not match the assemblr reference (Exception from HRESULT : 0x80121040)

Hello,

Sometime we receive below error message.

Could not load file or assembly 'system.web.http' or one of its dependencies. The located seembly's manifest definition does not match the assemblr reference (Exception from HRESULT : 0x80121040)



Solution :-
It will be fix with reinstall of Package.
Run below command in Package manager.


Update-Package Microsoft.AspNet.WebApi -reinstall

Posted in | 2 comments

Error in Upgrade of Node.JS

Hello,

Below is command use to upgrade node.js.

npm install npm@latest -g  (Upgrade node.js)

Sometime we get the error in upgrade like



In most of cased the problem with Proxy setting.

To check proxy try to access below url.

https://registry.npmjs.org/

if it works then your proxy is fine else some problem with proxy.


After resetting my proxy it's work fine.



Hope this will helpful..

Enjoy!!!

Posted in Labels: | 0 comments