Wednesday, 14 January 2015

Asp.net HttpClient POST Method call API

string response = null;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BASE_URL);
                var content = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair<string, string>("param1", value1),
                        new KeyValuePair<string, string>("param2", value2),
                    });
                var result = client.PostAsync(API_URL, content).Result;
                response = result.Content.ReadAsStringAsync().Result;
              

            }


here BASE_URL is some thing like www.mastermoin.com


and API_URL is looking like /api/helloservice

Asp.net HttpClient GET Method call API


public string getResponse()
        {
            string response= String.Empty;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BASE_URL);
                var result = client.GetAsync(API_URL).Result;
                response= result.Content.ReadAsStringAsync().Result;
            }
            return response;

        }


here BASE_URL is some thing like www.mastermoin.com

and API_URL is looking like /api/helloservice

Tuesday, 13 January 2015

Asp.net sorting DataTable row in ascending or descending order by DefaultView

Ascending  

DataTable table = "Query to get DataTable from database";
      table.DefaultView.Sort = "FieldName ASC";
      repeater1.DataSource = table.DefaultView;
      repeater1.DataBind();

Descending  

DataTable table = "Query to get DataTable from database";
      table.DefaultView.Sort = "FieldName DESC";
      repeater1.DataSource = table.DefaultView;
      repeater1.DataBind();

Asp.net Regular expression for from validation

RegExp_Alphabet = "^[a-z A-Z]+";

RegExp_AlphaNumeric = "^[a-z A-Z 0-9]+";

RegExp_Number = "^\\d+$";

RegExp_Decimal = "^\\d+$.d+$";
        
RegExp_Email = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";

RegExp_Weibsite = "^(ht|f)tp(s?)\\\\:\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\'\\/\\\\\\+&amp;%\\$#_]*)?$";

RegExp_Date = "(((0[123456789]|1[0-9]|2[0-9]|3[0-1])(/)(0[123456789]|10|11|12)(/)(([1][9][0-9][0-9])|([2][0][0-9][0-9]))))";

RegExp_DateTime = "(((0[123456789]|1[0-9]|2[0-9]|3[0-1])(/)(0[123456789]|10|11|12)(/)(([1][9][0-9][0-9])|([2][0][0-9][0-9]))) (0[123456789]|10|11|12)(:)([0-5][0-9])(:)([0-5][0-9]) (AM|PM))";

RegExp_IndianPostalcode = "([0-9][0-9][0-9][0-9][0-9][0-9])";

Angularjs set float decimal point by $filter


Filter at angular script

$filter('number')(val, fractionSize)

Reference  : https://docs.angularjs.org/api/ng/filter/number

Filter at html

<span>{{val | number:0}}</span>

we can apply filter at both end either  at script or at html expression base on requirements


Monday, 12 January 2015

AngularJS String to numeric (integer / float) Conversion


integer 

$scope.intValue = parseInt($scope.stringParameter);

float

$scope.floatValue = parseFloat($scope.stringParameter);

see some filter if required after conversion in float to set fraction decimal points



http://code2run.blogspot.ca/2015/01/angularjs-set-float-decimal-point-by.html


AngularJS, Work with $watch


$watch will help to process some logic base on scope variable change.

Its just like as onChange event of drop down / text box control


$scope.$watch('scopeVariable', function() {

          // Some Task

}


Set Cache location in Asp.net on Client / proxy server / both ends

@ Client Side

<%@ OutputCache Location ="Client" Duration="3600" VaryByParam="none" %>


@ proxy server

<%@ OutputCache Location ="Downstream" Duration="3600" VaryByParam="none" %>


@ proxy server

<%@ OutputCache Location ="ServerAndClient" Duration="3600" VaryByParam="none" %>

Remove Asp.net Page from browser cache



HttpResponse.RemoveOutputCacheItem(Page.ResolveUrl("~/page.aspx"));

Page.Response.Redirect("~/page.aspx");

Creating Cache Profile in asp.net

This will help us to all the time write all parameter in cache

duration = seconds for active cache profile 

@ web.config

<system.web>
    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="CATCHPROFILE_NAME" duration="3600" varyByParam="none"></add>
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
</system.web>

 @ All Page write as 

<%@ OutputCache CacheProfile="CATCHPROFILE_NAME" %>

Saturday, 10 January 2015

How Do i Show DataRow Collection in asp:repeater

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
<%#((System.Data.DataRow)Container.DataItem)[0]%>
    <ItemTemplate>
</asp:Repeater>

-------------------------------------OR------------------------------------

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
<%# Eval("[0]")%>  
   <ItemTemplate>
</asp:Repeater>

File Download From Asp.net C#

 string strURL = “URL”;
 string FileName = string.Empty;

 FileName = strURL.Substring(strURL.LastIndexOf('/') + 1);

 WebClient req = new WebClient();
 HttpResponse response = HttpContext.Current.Response;
 response.Clear();
 response.ClearContent();
 response.ClearHeaders();
 response.Buffer = true;

 response.AddHeader("Content-Disposition""attachment;filename=\"" + FileName + "\"");

 byte[] data = req.DownloadData(Server.MapPath(strURL));

 response.BinaryWrite(data);

 response.End();

Thursday, 8 January 2015

Change User as Admin And Run NPM INSTALL from MAC

SU adminUserName
password

sudo npm install

for app  or

sudo npm "install" "." "--force" "--global"

for global

Saturday, 3 January 2015

loading screen at center

<style type="text/css">
.loading-background{
    background: none repeat scroll 0 0 rgba(22, 22, 22, 0.3);
    height: 100%;
    left: 0;
    margin: 0;
    padding: 0;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 100;
}
.loading-wrapper {
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
    border: 0 none;
    height: 100px;
    left: 50%;
    margin-left: -50px;
    margin-top: -50px;
    position: fixed;
    top: 50%;
    width: 100px;
    z-index: 9999999;
}
.loading-contain {
    background-color: #FFFFFF !important;
    border-radius: 13px;
    display: block;
    height: 100px;
    line-height: 100px;
    margin: 0;
    padding: 1px;
    text-align: center;
    width: 100px;
}
    </style>


__________________________________

<div class="loading-background">
    <div class="loading-wrapper">
        <span class="loading-contain">Please Wait <br/> Loading....</span>
    </div>
</div>