Thursday, December 28, 2017

Upload Multiple Files Using FileUpload Control In ASP.NET 4.5 +

ASP.NET 4.5 and upper versions support this feature.

Now, FileUpload  control is built to support HTML 5, therefore it is only supported in browsers supporting HTML5. For other browsers it will work like a normal file upload control in ASP.NET.

A new Attribute introduces with the ASP.NET 4.5 FileUplaod control i.e. AllowMultipleIt takes either true or false.

In order to support multiple file uploads, set AllowMulitple="true" other than false.

<asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />

In addition to this control, some new properties have been included to support code-behind coding.


HasFilesCheck whether FileUpload control has multiple files or not.

PostedFilesBasically used to get all the files from the FileUpload control in the iteration.

Example code to upload files:

   <asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />  
   <asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />  

protected void uploadFile_Click(object sender, EventArgs e) {  
    if (UploadImages.HasFiles) {  
        foreach(HttpPostedFile uploadedFile in UploadImages.PostedFiles) {  
            //code to save files  
        }  
    }  
} 



Saturday, December 23, 2017

Wordpress - Change 'Add to cart' button text

Please add the below code to code the 'Add to cart' button text.

Change in Product Catalogue Page:
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );
function woo_archive_custom_cart_button_text() {
return __( 'ADD TO CART', 'woocommerce' );
}


Change in Single Product Page:
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 +
function woo_custom_cart_button_text() {
return __( 'ADD TO CART', 'woocommerce' );
}

Limit the number of cart Items in Woocommerce

There is 2 actions to check and to control if you want to limit cart items:

  1. Add to basket - When product  is added to cart
  2. Update Basket - When quantities are updated in cart page
Add a custom function hooked in woocommerce_add_to_cart_validation filter hook in function.php file of your active child theme (or theme), will allow customer to restrict the cart items to 'n' max and to display a custom message when this limit is exceeded:

  1. Checking and validating when products are added to cart:
    • Restrict Total Transaction Items:
      add_filter( 'woocommerce_add_to_cart_validation', 'only_n_items_allowed_add_to_cart', 10, 3 );
      function only_n_items_allowed_add_to_cart( $passed, $product_id, $quantity ) {
      $cart_items_count = WC()->cart->get_cart_contents_count();
      $total_count = $cart_items_count + $quantity;

      if( $cart_items_count >= n || $total_count > n ){
      // Set to false
      $passed = false;
      // Display a message
      wc_add_notice( __( "You can’t have more than n items in cart", "woocommerce" ), "error" );
      }
      return $passed;
      }
    • Restrict Item in a transaction:
      add_filter( 'woocommerce_add_to_cart_validation', 'only_five_items_allowed_add_to_cart', 10, 3 );
      function only_five_items_allowed_add_to_cart( $passed, $product_id, $quantity ) {

      //$cart_items_count = WC()->cart->get_cart_contents_count();

      foreach ( WC()->cart->get_cart() as $cart_item ) {
      if($cart_item['product_id'] == $product_id ){
      $cart_items_count = $cart_item['quantity'];
      break; // stop the loop if product is found
      }
      }

      $total_count = $cart_items_count + $quantity;

      if( $cart_items_count > 3 || $total_count > 3 ){
      // Set to false
      $passed = false;
      // Display a message
      wc_add_notice( __( "You can’t add more than 3 items in cart", "woocommerce" ), "error" );
      }
      return $passed;
      }

  2. Checking and validating when updating cart item quantities when products are added to cart
    • Restrict Total Transaction Items:
      add_filter( 'woocommerce_update_cart_validation', 'only_six_items_allowed_cart_update', 10, 4 );
      function only_six_items_allowed_cart_update( $passed, $cart_item_key, $values, $updated_quantity ) {

      $cart_items_count = WC()->cart->get_cart_contents_count();
      $original_quantity = $values['quantity'];
      $total_count = $cart_items_count - $original_quantity + $updated_quantity;

      if( $cart_items_count > 6 || $total_count > 6 ){
      // Set to false
      $passed = false;
      // Display a message
      wc_add_notice( __( "You can’t have more than 6 items in cart", "woocommerce" ), "error" );
      }
      return $passed;
      }
    • Restrict Item in a transaction:
      add_filter( 'woocommerce_update_cart_validation', 'only_five_items_allowed_cart_update', 10, 4 );
      function only_five_items_allowed_cart_update( $passed, $cart_item_key, $values, $updated_quantity ) {

      $cart_items_count = WC()->cart->get_cart_contents_count();
      $original_quantity = $values['quantity'];
      $total_count = $cart_items_count - $original_quantity + $updated_quantity;

      if( $updated_quantity > 3 ){
      // Set to false
      $passed = false;
      // Display a message
      wc_add_notice( __( "You can’t have more than 3 items in cart", "woocommerce" ), "error" );
      }
      return $passed;
      }

Tuesday, December 19, 2017

Wordpress - How to do a plugin/theme conflict test?

Sometimes when you find an issue on your wordpress site with Plugin, it will be caused by a plugin or theme conflict.
This can range from a simple CSS styling issue to a more complex issue where one Plugin/Theme is stopping another plugin/Theme from functioning properly.

do following Steps to a conflict test:
  1. Deactivate all plugins and switch to default Twenty Fifteen theme (this will ensure site is as close to a clean install as possible).
  2. Check the site to see if issue still exists. If issue goes away after deactivating other plugins and switching theme then this means that either the theme or one of the plugins was conflicting with another plugin. If the issue still exists then it is not a plugin or theme conflict.
  3. If it turns out to be a plugin/theme conflict, then you need to activate the plugins/theme one by one until you find the plugin/theme that causes the issue to come back.
  4. Once you have identified the conflict you can report the conflict to the developers of the plugin/theme and also to us.

Friday, December 15, 2017

SEO Tips

  1. Avoid Image:
    • Always avoid the images.
       
    • If you absolutely MUST use Java script drop down menus, image maps or image links, be sure to put text links somewhere on the page for the spiders to follow.
       
    • Use the words "image" or "picture" in your photo ALT descriptions and captions. A lot of searches are for a keyword plus one of those words.

       
  2. Content is king:
    • Be sure to have good, well-written, and unique content that will focus on your primary keyword or keyword phrase.
       
    • Don’t try to stuff your text with keywords. It won’t work. Search engines look at how many times a term is in your content and if it is abnormally high, will count this against you rather than for you.

       
  3. Proper linking:
    • If content is king, then links are queen. Build a network of quality backlinks. Remember, if there is no good, logical reason for a site to link to you, you don’t want the link.
       
    • Make sure your site is easy to use, proper linking
       
    • Check the link to your home page throughout your site. Is index.html appended to your domain name? If so, you’re splitting your links. Outside links go to http://www.domain.com and internal links go to http://www.domain.com/index.html. Ditch the index.html or default.php or whatever the page is and always link back to your domain.

       
  4. Fresh content:
    • Fresh content can help improve your rankings. Add new, useful content to your pages on a regular basis. Content freshness adds relevancy to your site in the eyes of the search engines.
       
    • If your site content doesn’t change often, your site needs a blog because search spiders like fresh text. Blog at least three time a week with good, fresh content to feed those little crawlers.

       
  5. Use keywords and keyword phrases:
    • Use keywords and keyword phrases appropriately in text links, image ALT attributes and even your domain name.
       
    • Be sure links to your site and within your site use your keyword phrase. In other words, if your target is “blue widgets” then link to “blue widgets” instead of a “Click here” link.
       
    • Focus on search phrases, not single keywords, and put your location in your text (“our Palm Springs store” not “our store”) to help you get found in local searches.
       
    • Be sure you have a unique, keyword focused Title tag on every page of your site. And, if you MUST have the name of your company in it, put it at the end. Unless you are a household name, your business name will probably get few searches.
       
    • Use keyword rich captions with your images.

       
  6. Check for canonicalization issues:
    • www and non-www domains. Decide which you want to use and 301 redirect the other to it. In other words, if http://www.domain.com is your preference, then http://domain.com should redirect to it.

       
  7. Be aware that by using services that block domain ownership information when you register a domain, Google might see you as a potential spammer.
     
  8. Implement google Structured Data- https://developers.google.com/structured-data/
     
  9. Google Instant - http://googleblog.blogspot.in/2010/09/google-instant-behind-scenes.html
     
  10. How the google algo works - http://www.google.co.in/insidesearch/howsearchworks/algorithms.html
     
  11. Need to implement http://ogp.me/ open graph protocols.
     
  12. Implement twitter meta tags - https://dev.twitter.com/cards/getting-started
     

Textboxes in Modalpopup Panel adding commas on postback

The solution for this problem is to get the modalpoup out of the main update panel.

Once do this the commas will go away.

If you truly need an update panel inside of the modal popup, create one of it's own inside that panel.

Wednesday, December 13, 2017

How To Clear Your DNS Cache

Windows - use the command ipconfig /flushdns
Apple Mac - use the command sudo killall -HUP mDNSResponder
Linux - use the command /etc/init.d/nscd restart

Saturday, December 2, 2017

create Instagram application, Steps to add Instagram username to sandbox, Steps to accept Instagram invitation And verification of account


Steps to create Instagram Application

  1. Log into the developer portal - Go to the Instagram Developer portal and log in with your Instagram credentials And complete the Developer Signup.
  2. Register your app - On next page that follows step 1, click Register Your Application.
  3. Fill up all the form details and Get your Client ID and Client Secret


We have created the app successfully and integrated. Right now this application is in sandbox account. So if you wants to test this application in sandbox account, you need to add the Instagram username to https://www.instagram.com/developer/.

Steps to add Instagram username to sandbox:

  1. Login to Instagram app using URL https://www.instagram.com/developer/ .
  2. Click on “Manage Clients”.
  3. Click on “Manage” of particular app.
  4. Go to “Sandbox” and add your username or developers username.


Steps to accept  Sandbox invitation:

  1. Login to Instagram from the users account and go to https://www.instagram.com/developer/clients/sandbox_invites/ 
  2. Add application details like – website - http://scriptoress.stukcdn.com, description – to upload photos
  3. Then you will able to see the invitation , please accept this invitation.


Steps to submit Instagram app for review to upgrade the application from sandbox mode to Live mode:

  1. Login to Instagram app using URL https://www.instagram.com/developer/ .
  2. Click on “Manage Clients”.
  3. Click on “Manage” of particular app.
  4. Go to permission tab and click on “start a submission” button
  5. Check option “My app allows people to login with Instagram and share their own content.”, you can see the other options after checking the option. Here you need to provide Video Screencast URL:” (Provide a link to a video screencast showing the experience in your app. Please show how your integration uses all permissions you are requesting, any interface to moderate content or getting rights to media, and any Instagram login experience. Since your app may be in sandbox mode, you can use data from sandbox users to showcase the integration.)
  6. And click “submit button” to submit the application for review.


The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.(System.Data)

This happens only for Office 2007 or higher as it requires use of OLEDB ACE drivers for connection which do not come by default in Windows and hence we need to install them in order to get rid of this error.

You can solve this issue , by installing the drivers. for more information, you can visit the links below:

Error 1061 : service cannot accept control messages at this time

This error occurred when we try to stop /reboot the service.

There is a temporary mismatch between the requested control and the state of the service to be controlled. The service may be in a state of start-pending, stop-pending, or stopped.

There are two ways to stop the service.
1. Go to task Manager and kill the process and try now, it will work
2. Disable the startup type and restart the server. this will disable the service.