Stacks

 

Whenever i get time from my work or personal life I try to solve the questions posted in Stacksoverflow. It help me to keep update every time. As there are big brains out their who implement new things or do the same thing in some interesting ways.  And also I can recall and share few implementation of my self answering related questions.

And YES….I do also ask question whenever i done with enough googling. The best thing in stack is it will provide correct answer within few minutes and only correct answers are promoted by the users.

My account link : Suresh Kamrushi
Listing below some of the questions and answer in which i have participated.

User Suresh Kamrushi - Stack Overflow

most recent 30 from stackoverflow.com

how each user will receives 10 emails?
Author: Suresh Kamrushi
Posted: April 20, 2018, 8:47 am
A detailed blog with sample code :sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:39 am
A detailed blog with sample code :sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:38 am
A detailed blog with sample code :sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:38 am
A detailed blog with sample code :sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:38 am
A detailed blog with sample code :sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:37 am
A detailed blog with sample code :sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:37 am
A detailed blog with sample code :sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:36 am
A detailed blog with code sample : sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:35 am
A detailed blog with code sample :sforsuresh.in/export-csv-file-using-asp-mvc
Author: Suresh Kamrushi
Posted: April 18, 2018, 6:35 am

You can validate using Javascript like below:

var b = url.search(/(?:https?|ftp):\/\/[\n\S]+/g);

Fiddle : https://jsfiddle.net/uzo8j806/9/

Author: Suresh Kamrushi
Posted: April 9, 2018, 8:12 am

do something like this:

$(document).on('change','#startdate',function () { 
alert('h');
});

As per your comment you can try like:

$('#startdate').on('change','#startdate',function () { 
alert('h');
});
Author: Suresh Kamrushi
Posted: April 6, 2018, 8:57 am

For C# MVC 4.5 you need to do like this:

Response.Clear();
Response.ContentType = "application/CSV";
Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + ".csv\"");
Response.Write(dataNeedToPrint);
Response.End();
return new EmptyResult();  //this line is important else it will not work.
Author: Suresh Kamrushi
Posted: March 27, 2018, 11:35 am

You can try something like below:

string Text="22/11/2009";
DateTime date = DateTime.ParseExact(Text, "dd/MM/yyyy", null);              
Console.WriteLine("update date => "+date.ToString("yyyy-MM-dd"));
Author: Suresh Kamrushi
Posted: March 23, 2018, 10:07 am

None of the above answer worked for me. Sharing what worked:

string Text="22/11/2009";
DateTime date = DateTime.ParseExact(Text, "dd/MM/yyyy", null);              
Console.WriteLine("update date => "+date.ToString("yyyy-MM-dd"));
Author: Suresh Kamrushi
Posted: March 23, 2018, 10:04 am

you can try somethig like this:

   $datetime1 = date_create($date_1);
    $datetime2 = date_create($date_2);

    $interval = date_diff($datetime1, $datetime2);   
    $interval->format($differenceFormat);

reff :http://php.net/manual/en/function.date-diff.php

Author: Suresh Kamrushi
Posted: February 26, 2018, 4:07 am

You need to add following attribute to the link or button where you want add this functionality:

 data-dismiss="modal" data-toggle="modal" id="forgotPassword" data-target="#ModalForgotPassword"

A detaile blog: http://sforsuresh.in/bootstrap-modal-window-close-current-open-new-modal/

Author: Suresh Kamrushi
Posted: February 13, 2018, 6:00 am

I am getting error: tried using like: "useClass: ApidataService" or "ApidataService" in providers and also remove public from the service constructor.

Failed to compile.

C:/wamp64/www/angular/project/src/app/app.module.ts (33,69): Argument of type '{ declarations: (typeof AppComponent | typeof ViewComponent | typeof AboutComponent | typeof News...' is not assignable to parameter of type 'NgModule'.
  Types of property 'providers' are incompatible.
    Type '{ provide: InjectionToken<string>; useValue: string; ApidataService: typeof ApidataService; }[]' is not assignable to type 'Provider[]'.
      Type '{ provide: InjectionToken<string>; useValue: string; ApidataService: typeof ApidataService; }' is not assignable to type 'Provider'.
        Object literal may only specify known properties, and 'ApidataService' does not exist in type 'Provider'.

My service is:

import { Injectable } from '@angular/core';

@Injectable()
export class ApidataService {

  public  constructor() { }
    cars = ['cars','bycycle','van'];
    mydata(){
        return "this is from apidata";
    }
}

And app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { ViewComponent } from './view/view.component';
import { AboutComponent } from './about/about.component';
import { RouterModule, Routes} from '@angular/router';
import { NewsComponent } from './news/news.component';
import {APP_BASE_HREF} from '@angular/common';
import { FormsModule } from '@angular/forms';   //for 2way binding

//SERVICES SAMPLE
import {ApidataService} from './apidata.service';

@NgModule({
  declarations: [
    AppComponent,
    ViewComponent,
    AboutComponent,
    NewsComponent    
  ],
  imports: [
    HttpModule,
    BrowserModule,
    FormsModule,
    RouterModule.forRoot([
        {path:'About',component:AboutComponent},
        {path:'News',component:NewsComponent}
    ])
  ],
    providers: [
        {provide: APP_BASE_HREF, useValue: 'http://localhost:4200/',ApidataService}
     ],
  bootstrap: [AppComponent]
})

export class AppModule { }
Author: Suresh Kamrushi
Posted: February 9, 2018, 6:15 am

With angular 4 you can fix this issue by updating app.module.ts file as follows:

Add import statement at the top as below:

import {APP_BASE_HREF} from '@angular/common';

And add below line inside @NgModule

providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]

Reff: https://angular.io/api/common/APP_BASE_HREF

Author: Suresh Kamrushi
Posted: February 2, 2018, 12:20 pm

working example of jsgrid date field

var db = {

    loadData: function(filter) {
        return $.grep(this.users, function(user) {
            return (!filter.Name || user.Name.indexOf(filter.Name) > -1);
        });
    },

    insertItem: function(item) {
        this.users.push(item);
    },

    deleteItem: function(item) {
        var index = $.inArray(item, this.users);
        this.users.splice(index, 1);
    }

};

window.db = db;

db.users = [
    {
        "Account": "D89FF524-1233-0CE7-C9E1-56EFF017A321",
        "Name": "Prescott Griffin",
        "RegisterDate": "2011-02-22T05:59:55-08:00"
    },
    {
        "Account": "06FAAD9A-5114-08F6-D60C-961B2528B4F0",
        "Name": "Amir Saunders",
        "RegisterDate": "2014-08-13T09:17:49-07:00"
    },
    {
        "Account": "EED7653D-7DD9-A722-64A8-36A55ECDBE77",
        "Name": "Derek Thornton",
        "RegisterDate": "2012-02-27T01:31:07-08:00"
    },
    {
        "Account": "2A2E6D40-FEBD-C643-A751-9AB4CAF1E2F6",
        "Name": "Fletcher Romero",
        "RegisterDate": "2010-06-25T15:49:54-07:00"
    },
    {
        "Account": "3978F8FA-DFF0-DA0E-0A5D-EB9D281A3286",
        "Name": "Thaddeus Stein",
        "RegisterDate": "2013-11-10T07:29:41-08:00"
    }
];

var MyDateField = function (config) {
    jsGrid.Field.call(this, config);
};

MyDateField.prototype = new jsGrid.Field({

    sorter: function (date1, date2) {
        return new Date(date1) - new Date(date2);
    },

    itemTemplate: function (value) {
        return new Date(value).toDateString();
    },

    insertTemplate: function (value) {
        return this._insertPicker = $("<input class='date-picker'>").datetimepicker();
    },

    editTemplate: function (value) {
        return this._editPicker = $("<input class='date-picker'>").datetimepicker();
    },

    insertValue: function () {
        return this._insertPicker.data("DateTimePicker").useCurrent();
    },

    editValue: function () {
        return this._editPicker.data("DateTimePicker").useCurrent();
    }
});

jsGrid.fields.date = MyDateField;

$("#jsGrid").jsGrid({
    height: "90%",
    width: "100%",

    inserting: true,
    filtering: true,
    editing: true,
    paging: true,

    autoload: true,

    controller: db,

    fields: [
        { name: "Account", width: 150, align: "center" },
        { name: "Name", type: "text" },
        { name: "RegisterDate", type: "date", width: 100, align: "center" },
        { type: "control", editButton: false }
    ]
});

Refference: http://jsfiddle.net/tabalinas/L6wbmvfo/

Author: Suresh Kamrushi
Posted: January 30, 2018, 8:05 am

It might be silly to ask but still i am not able to google it correctly. Below is my code to print "selected" in view:

<option value="0" @if(ViewBag.country == 0)  { @:selected } >NO</option>

it is giving me error like

Parser Error Message: The if block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

Referred :https://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/

Author: Suresh Kamrushi
Posted: December 28, 2017, 9:53 am

I am able to get like this:

System.Configuration.ConfigurationManager.AppSettings.Get("KEY").ToString();
Author: Suresh Kamrushi
Posted: December 6, 2017, 8:43 am

You can run both server simultenously by changing port number of Apache or IIS.
A) How you can change Apache port number:

1) Open “httpd.conf” file located in folder “C:\wamp64\bin\apache\apache2.4.23\conf”. You can also open file directly from system try if your wamp is running.
2) Search for “listen” text in file and update the default port 80 to 8080.
3) Now Restart the WAMP server to make new port number effective.
4) Open the browser with url “http://localhost:8080/” wamp will show home page.
Reff: http://sforsuresh.in/iis-and-wamp-servers-on-the-same-system/

B) How you can change IIS port:
1) Go start and type IIS.
2) IIS Manager will open. click on “Default Web Site” on left hand side.
3) click on “bindings…” from the right side action section.
4) Popup will open with 80 port listed. select it and click the edit button.
5) Update the port and restart the server.Now try to access using browser.

Reff: http://sforsuresh.in/change-iis-port-windows/

Author: Suresh Kamrushi
Posted: November 24, 2017, 6:28 am

you can do something like below:

$oldtime = "20:30pm - 23:30pm";
$newtime = explode(" - ", $oldtime);
foreach($newtime as $k => $t) {
$time[$k] = DateTime::createFromFormat('H:iA', $t);
echo $time[$k]->format('H:i:s');  //or any other format you want
}

You can get more info : http://php.net/manual/en/datetime.createfromformat.php

Author: Suresh Kamrushi
Posted: November 23, 2017, 9:26 am

Set value as :

<option class="form-control" value="{{$play->id}}**{{$play->unit}}" >{{$play->attribute}}</option>

You will get both values after submit. You need to explode() like:

$attribute = $_POST['attribute'];
$values = explode("**", $attribute);
echo $values[0];  //will contain id
echo $values[1];  // will contain unit

I am using "**" as a separator, you can use anything.

Author: Suresh Kamrushi
Posted: November 23, 2017, 6:05 am

You can use event scheduler to perform the task like below:

DELIMITER //
CREATE EVENT eventName
ON SCHEDULE EVERY 1 WEEK
STARTS 'Some Date to start'
ENDS 'End date If any' 

DO
BEGIN
   DELETE FROM NeoTec_test WHERE NOW() > Expiry
END//
DELIMITER ;
Author: Suresh Kamrushi
Posted: November 16, 2017, 6:34 am

You can do like this:

$( "button" ).click(function() {
  $( this ).attr("id");
});

Or alternatively you can also use prop() method:

$( "button" ).click(function() {
  $( this ).prop("id");
});

for documentation you can reff:
https://api.jquery.com/attr/
https://api.jquery.com/prop/

Author: Suresh Kamrushi
Posted: November 16, 2017, 6:28 am

enter image description hereIf you are using phpmyadmin do the following steps:
1) select the database
2) Select search from the top links
3) Now you will get text box to enter what to search
4) Select the table in which you want to search. It will search whole database get the result

Author: Suresh Kamrushi
Posted: November 16, 2017, 5:54 am

For this issue you can try either of below solutions:
1) It is permission issue with android 6. So to fix the issue configure platform to android 5.0.

OR if you are using MI note 4 you can try below additional steps:

There is another permission required in MIUI secruity system and after enabling it, camera started working.
Following are the steps you can follow to update the setting:
1) Go to Security.
2) Click on “Permissions” and again select “Permissions”
3) Now from the list, click on “Camera”.
4) It will list all the apps installed. Look for your app and enable the permission.

Reff: http://sforsuresh.in/cordova-sorry-android-camera-encountered-problem/

Author: Suresh Kamrushi
Posted: November 8, 2017, 6:20 am

In MIUI 8.5 it gives the error like you mention while enabling "install via USB", to resolve the error you need to make WIFI off and make mobile data on and then enable the option “Install via USB”. it will work for you.

A detailed blog: http://sforsuresh.in/xiaomi-mi-note-4-install-via-usb-device-temporarily-restricted/

Author: Suresh Kamrushi
Posted: October 18, 2017, 8:20 am

Now in updated MIUI 8 in Xaomi Redmi Note 4, "Install via USB" is moved to "developer option". So go to setting => additional Settings => Developer Options => update "Install via USB".

Few more details in blog: click here

Author: Suresh Kamrushi
Posted: October 13, 2017, 12:41 pm

Better you can do like this:

$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}

Code copied from :http://php.net/manual/en/function.fgetcsv.php
alternatively : http://php.net/manual/en/function.str-getcsv.php

Author: Suresh Kamrushi
Posted: September 26, 2017, 10:11 am

You can update "urlAddLocalhost" variable in "wamp64/wampmanager.conf" file to on/off. By default it is "off".
My wamp version is 3.0.6.

urlAddLocalhost = "off" 

enter image description here

Author: Suresh Kamrushi
Posted: September 21, 2017, 8:36 am

Getting error as "npm ERR! errno -4058". and at the end it showing like "Please include the following file with any support request:" whatever solution i got from google and stacks is not working out for me. Any help appreciated.

ant -f C:\\wamp64\\www\\mobileApp\\cordova\\HTML5Application\\nbproject "-Dupdate.task.jar=C:\\Program Files\\NetBeans 8.2\\webcommon\\ant\\extra\\org-netbeans-modules-cordova-projectupdate.jar" -Dandroid.project.activity=HTML5Application -Dsite.root=www -Dstart.file=index.html -Dandroid.sdk.home=E:\\Suresh\\Projects\\BillonDeal\\adt-bundle-windows-x86_64-20140702\\sdk -Dandroid.target.device.arg=run -Dcordova.version=7.0.1-0.0.0 -Denv.DISPLAY=:0.0 "-Dios.certificate.name=iPhone Developer" -Dandroid.build.target=android-16 -Dconfig=android_1 sim-android
check-android-template:
check-cordova-version:
check-cordova-project:
upgrade-to-cordova-project:
create-android:
update-plugins:
cordova.cmd plugins 
cordova.cmd -d plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git
No scripts found for hook "before_plugin_add".
Calling plugman.fetch on plugin "https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git"
saving
Running command: cmd "/s /c ""C:\Program Files\nodejs\npm.cmd" install https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git --save""
Command finished with error code 4294963238: cmd /s /c ""C:\Program Files\nodejs\npm.cmd" install https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git --save"
Error: Failed to fetch plugin https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: cmd: Command failed with exit code 4294963238 Error output:
npm ERR! not a package C:\Users\ADMINI~1\AppData\Local\Temp\npm-1476-73df7ab4\git-wip-us.apache.org\repos\asf\cordova-plugin-dialogs.git
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git" "--save"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! path C:\Users\ADMINI~1\AppData\Local\Temp\npm-1476-73df7ab4\unpack-d65611f4\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\ADMINI~1\AppData\Local\Temp\npm-1476-73df7ab4\unpack-d65611f4\package.json'
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\ADMINI~1\AppData\Local\Temp\npm-1476-73df7ab4\unpack-d65611f4\package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     C:\wamp64\www\mobileApp\cordova\HTML5Application\node_modules\npm-debug.log
C:\wamp64\www\mobileApp\cordova\HTML5Application\nbproject\build.xml:235: exec returned: 1
BUILD FAILED (total time: 9 seconds)
Author: Suresh Kamrushi
Posted: September 20, 2017, 9:28 am

You can try something like this:

$date = DateTime::createFromFormat('YmdHis', '20170912131313');
$date->add(new DateInterval('P10D'));
echo $date->format('Y-m-d');

For more information: http://php.net/manual/en/datetime.add.php

Author: Suresh Kamrushi
Posted: September 12, 2017, 8:12 am

How to increase the size of the Clipboard:

  1. Click the Start button. Type sysdm.cpl into the search box and press the Enter key.
  2. Click the Advanced tab in the System Properties window. Click the Settings button under the Performance label header.
  3. Click the Advanced tab in the Performance Options window. Under the Virtual Memory header, click the Change... button.
  4. Clear the check box next to the Automatically manage paging file size for all drives option. This disables automatic "Virtual Memory" settings in Windows.
  5. Enter a value for the size of the new paging file. Enter a value larger than the current paging file size in the "Maximum Size" field (enter the value in megabytes). Click the Set button and then OK.
  6. Restart the computer for the new "Virtual Memory" settings to take effect. The Windows Clipboard now stores more data when copying and pasting between applications.

Reference: I need to increase the clip board size in Word

A detailed blog with screenshots :http://sforsuresh.in/increase-size-clipboard-of-windows-10-7/

Author: Suresh Kamrushi
Posted: January 8, 2014, 6:55 am

How can I increase the size of the clipboard in Windows 7?

While copying large amounts of data, I get the following error:

Item to large for Clipboard.

Author: Suresh Kamrushi
Posted: December 31, 2013, 9:31 am

Go to the Sql tab run one of the below query:

delete from tableName;

Delete: will delete all rows from your table. Next insert will take next auto increment id.

or

truncate tableName;

Truncate: will also delete the rows from your table but it will start from new row with 1.

A detailed blog with example: http://sforsuresh.in/phpmyadmin-deleting-rows-mysql-table/

Author: Suresh Kamrushi
Posted: August 16, 2013, 11:13 am