Archive for tag: C

iPhone or iPad Safari cache clear

There are few solutions of clearing out Cache for iPhone or iPad but I have found that many people struggling to find it without restarting device so, I thought of writing blog. Following is step through.

1.  Go to Settings

2.  Then go down and go to Safari

3.  Then go down and see options Clear Cookie and Data as in below Image

I Phone -i Pad -Cookie -and -Data -Clear

4.  Now go back to your safari and you are done!

If you have any more question comment below.

 

Shorten up this overly long JavaScript-jQuery function

Recently, I have been aseked this question and found bit of good solution as below:

I have a simple script that selects a class's and adds a class of selected to it and remove it from all other 's with the similar class. It all works perfectly, but I know that there has to be a better way to write this out, I just can't figure it out.. Does it involve something like this?

$('.adv-option-set a').click(function()
{
    // if clicked item is selected then do nothing
    if ($(this).hasClass('selected')){}

    // otherwise deselect all and select just this one
    else
    {
        $('.adv-option-set a').removeClass('selected');
        $(this).addClass('selected');
    }
});

$('.adv-option-set2 a').click(function()
{
    // if clicked item is selected then do nothing
    if ($(this).hasClass('selected')){}

    // otherwise deselect all and select just this one
    else
    {
        $('.adv-option-set2 a').removeClass('selected');
        $(this).addClass('selected');
    }
});

And below is HTML that has been provided

     <article id="filter">
        <ul id="filter-nav" class="option-set">
          <li>Filter: </li>
          <li><a data-categories="*" data-subid="all" class="selected">All</a></li>
          <li><a data-categories="tubs-and-showers" data-subid="tubs-and-showers">Tubs &amp; Showers</a></li>
          <li><a data-categories="countertops" data-subid="countertops">Countertops</a></li>
          <li><a data-categories="faucets" data-subid="faucets"><s>Faucets</s></a></li>
          <li><a data-categories="cabinetry" data-subid="cabinetry"><s>Cabinetry</s></a></li>
          <li><a data-categories="flooring" data-subid="flooring"><s>Flooring</s></a></li>
          <li><a data-categories="toilets" data-subid="toilets"><s>Toilets</s></a></li>
          <li><a data-categories="accessories" data-subid="accessories"><s>Accessories</s></a></li>
        </ul>
        <div id="advfilter" class="advfilter filter-nav hidden">
          <ul id="tubs-and-showers" class="adv-option-set1">
            <li><span class="small">ADV</span> Filter: </li>
            <li><a data-categories="modular">Modular</a></li>
            <li><a data-categories="custom">Custom</a></li>
          </ul>
          <ul id="countertops" class="adv-option-set2">
            <li><span class="small">ADV</span> Filter: </li>
            <li><a data-categories="marble">Marble</a></li>
            <li><a data-categories="solid-surface">Solid Surface</a></li>
            <li><a data-categories="laminate"><s>Laminate</s></a></li>
            <li><a data-categories="granite"><s>Granite</s></a></li>
          </ul>
          <ul id="faucets" class="adv-option-set3">
            <li><span class="small">ADV</span> Filter: </li>
            <li><a data-categories="">Coming Soon</a></li>
            <li><a data-categories="">Coming Soon</a></li>
          </ul>
          <ul id="cabinetry" class="adv-option-set4">
            <li><span class="small">ADV</span> Filter: </li>
            <li><a data-categories="">Coming Soon</a></li>
            <li><a data-categories="">Coming Soon</a></li>
          </ul>
        </div>
      </article>

Here is the solution:

$('[class^=adv-option-set] a').click(
    function()
    {
       $(this).addClass('selected');
       $('[class^=adv-option-set] a').not(this).removeClass('selected');
    }
);

It is very simple but most effective and reduce code redundancy as well.

C# interface instance-like

to work with a library I just found I need to implement a few interfaces first. But some methods seem to be asking for objects that have the type of some interfaces... And if I have an interface called MyInterface I can write things like :

    MyInterface shoe;

It does not really make sense to me. Can somebody teach me this concept ?

Then i have found out very nice solution about C# Inerface, Interfaces establish a contract between a class and the code that calls it. They also allow you to have similar classes that implement the same interface but do different actions or events and not have to know which you are actually working with. This might make more sense as an example so let me use same example as per your link with bit of modification:

using System; 
 
interface IPerl 
{ 
    void Read(); 
} 
 
class Test : IPerl 
{ 
    public void Read() 
    { 
    Console.WriteLine("Read Test"); 
    } 
} 
 
class Test1 : IPerl 
{ 
    public void Read() 
    { 
    Console.WriteLine("Read Test1"); 
    } 
} 
 
class Program 
{ 
    static void Main() 
    { 
    IPerl perl = new Test(); // Create instance of Test. 
    perl.Read(); // Call method on interface output will be different then Test1. 
 
        perl = new Test1(); // Create instance of Test1. 
    perl.Read(); // Call method on interface output will be different then Test. 
 
    } 
} 

Output:

  1. "Read Test"
  2. "Read Test1"

I hope this would help.

Remove events with jquery or javascript

This is the function that we have bound it as below:

$(function(){ 
    //remove click doSomething
    $("div").click(doSomething1); 
}); 

 In jQuery we can do add and remove events as we go along, there are two way that we can remove or unbind event of jQuery

$('div').off('click', doSomething); 
 
// or 
 
$('div').unbind('click', doSomething); 

 if is there any batter way then caould yo ucomment down below please,

I hope this would help.

Thanks

URL fragments or parts and get Paths using HttpRequest in C#

URL fragments or parts and get Paths using HttpRequest, If we want URL fragments or parts of the URL we can get that in C# using HttpRequest as like follwoing:

In following example we have used those properties of .Net Framework Library

Below is just example URL that has taken for us to understand:

http://www.example.com:80/Products/Product-name/Detail.aspx/path/info?q=item#classic

as below

HttpRequest path and URL fragments / parts

Request.ApplicationPath: /Products

Request.CurrentExecutionFilePath: /Products/Product-name/Detail.aspx

Request.FilePath: /Products/Product-name/Detail.aspx

Request.Path: /Products/Product-name/Detail.aspx/path/info

Request.PathInfo: /path/info

Request.PhysicalApplicationPath: D:\Inetpub\wwwroot\CambiaWeb\Products\

Request.RawUrl: /Products/Product-name/Detail.aspx/path/info?q=item

Request.Url.AbsolutePath: /Products/Product-name/Detail.aspx/path/info

Request.Url.AbsoluteUri: http://www.example.com:80/Products/Product-name/Detail.aspx/path/info?q=item

Request.Url.Classic:

Request.Url.Host: www.example.com

Request.Url.LocalPath: /Products/Product-name/Detail.aspx/path/info

Request.Url.PathAndQuery: /Products/Product-name/Detail.aspx/path/info?q=item

Request.Url.Port: 80

Request.Url.Query: ?q=item

Request.Url.Scheme: http

Request.Url.Segments: /
Products/
Product-name/
Detail.aspx/
path/
info

Those are all the ways to get full, partial, fragments or parts of the URL.

THank you very much for going through this article.

Trim function or normalize space in XPath with C#

In XPath we can trim or remove spaces, it doesn't have trim function in XPath 1.0 but can use normalize-space(), it just doesn't trim it doesn't it more thing that as well following is an example:

normalize-space()

//removing spaces from beginning and end
NodeIter = nav.Select("/Products/Product/name[normalize-space(' Item1 ') ='Item1']");

//removing only trailing spaces
NodeIter = nav.Select("/Products/Product/name[normalize-space(' Item 1 ') ='Item 1']");

//removing more than one spaces and leave just one space between characters or words
NodeIter = nav.Select("/Products/Product/name[normalize-space(' Item    1   2 ') ='Item 1 2']");

 

normalize-space() does more than just trimming spaces.

If you have question don't forget to ask.

Thank you for going through

XPath value lower case or upper case function in C#

XPath function to translate or convert into lower case using two different ways based on version of XPath.

In XPath 2.0 onwards it has function lower-case() or upper-case(). If your environment supports this version of the standard, you can write:

Lower Case:

NodeIter = nav.Select("/Products/Product/name[lower-case(.) ='" + productName +"']")

Upper Case:

NodeIter = nav.Select("/Products/Product/name[upper-case(.) ='" + productName +"']")

However, if your system supports XPath version 1.0. In that case, you can use the translate() function:

Lower Case:

NodeIter = nav.Select("("/Products/Product/name[ (translate(., "
    + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '"
    + productName + '"]");

Upper Case:

NodeIter = nav.Select("("/Products/Product/name[ (translate(., "
    + "'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), '"
    + productName + '"]");

If you have any question don't forget to ask
Thank you for watching this article

PDF Generation with HTML tags and background image in C#

Generate PDF in C# including Background Image and HTML Tags, I have been through many blogs but there are very few blogs that they have explained to include background image while generating PDFs, so though it's worth creating C# Program and writing blog.

Step 1:

Once you have created your solution, then you have to download iTextSharp in this zip file you will have DLLs so Add Reference to your solution.

Step 2:

Now add following line of code to to reference the code

using iTextSharp.text;
using iTextSharp.text.pdf;

Step 3:

Following is code for it: 

 

        void PDF_Generation_With_HTML_And_Background_Image()
        {

            //setting ContentType
            Response.ContentType = "application/pdf";

            //setting up PDF header and filename
            Response.AddHeader("content-disposition", "attachment;filename=filename.pdf");

            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            //getting image & it's path from server
            string imageFilePath = Server.MapPath(".") + "/images/imagename.jpg";

            //creating Image object
            Image imageFile = Image.GetInstance(imageFilePath);

            //Page site and margin left, right, top, bottom is defined
            var pdfDocument = new Document(PageSize.A4, 20f, 0f, 20f, 0f);

            //Resize image depend upon your need
            //here I had Landscape Image
            imageFile.ScaleToFit(800, 800);

            //If you want to choose image as background then,
            imageFile.Alignment = Image.UNDERLYING;

            //Scale Percent of image. 
            //Here we have 50% in float is 50f
            imageFile.ScalePercent(50f);

            //pdf writer will get instance of document
            PdfWriter.GetInstance(pdfDocument, Response.OutputStream);

            pdfDocument.Open();

            pdfDocument.NewPage();

            //html p tag or Pragraph tag
            Paragraph paragraph = new Paragraph("Lorem Ipsum is simply dummy text of the printing and typesetting " + 
                "industry.\n\n Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an " + 
                "unknown printer took a galley of type and scrambled it to make a type specimen book.");

            pdfDocument.Add(imageFile);

            pdfDocument.Add(paragraph);

            pdfDocument.Close();

            Response.Write(pdfDocument);

            Response.End();
        }

 

Thank you for going through

Get and set #hash value in URL using Javascript or jQuery

Get or set #hash value in URL using Javascript or jQuery, we can change URL without refreshing page using Javascript or jQuery by changing #hash value, like below:

  • example.com/page.html#example
  • example.com/page.html#example-page

Javascript or jQuery

// get #hash value
var hashValue = window.location.hash

// set #hash value, it will change URL to example.com/page.html#example-page
window.location.hash = "example-page"

If you have question don't forget to ask.

Thank you for going through

 

ASP.NET forms authentication keeps displaying login page on iPad

ASP.NET forms authentication keeps displaying login page on iPad, when I was developing iPad web app, I have come across one of the bug that once we "Add as Home Screen" then we can create Web as App then once you have logged in then when we try and go through website somewhere it automatically clears the session out so then I have found out the solution, that we need to make changes inside web.config file and I had my my web.config file as following:

<authentication mode="Forms">
  <forms loginurl="/Account/LogOn" />
</authentication>

 Then, I have found out, and I have added timeout="2880" cookieless="UseCookies" as following: 

<authentication mode="Forms">
  <forms loginurl="/Account/LogOn" timeout="2880" cookieless="UseCookies" />
</authentication>

and it will start getting it working and you will not loose session.

If you have question don't forget to ask.

Thank you for going through