Thursday, 23 February 2017

Setup Connection to new Remote SQL Server

After installing the new instance of SQL Server, the remote user might not be able to login remotely while can as local SQL user. To resolve this issue, follow the link more...


Wednesday, 22 February 2017

Open a Bootstrap Modal on Another Bootstrap Modal

<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  </head>

<body>
  <!-- Button for test -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#test1">Open First Modal</button>

  <!-- Modal 1 -->
  <div id="test1" class="modal fade" role="dialog" style="z-index: 1200;">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-body">
          <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#test2">
            Open Second Modal
          </button>
        </div>      
      </div>
    </div>
  </div>

  <!-- Modal 2 -->
  <div id="test2" class="modal fade" role="dialog" style="z-index: 1600;">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">  
        <div class="modal-body">
          Your content comes here
        </div>      
      </div>
    </div>
  </div>

</body>
</html>


Tuesday, 21 February 2017

C# .NET Get the List of Elements Which are in List1 but not in List2 and Vice Versa

// define the lists
List<string> list1 = new List<string>() { "a", "b", "c", "d", "e", "zz","ZZ" };
List<string> list2 = new List<string>() { "ZZ", "H","b" };

// convert the list elements to lowercase
list1 = list1.Select(x => x.ToLower()).ToList();
list2 = list2.Select(x => x.ToLower()).ToList();

// create desire lists
List<string> ItemsInList1NotInList2 = list1.Except(list2).ToList();
List<string> ItemsInList2NotInList1 = list2.Except(list1).ToList();


Sunday, 19 February 2017

Convert HTML to PDF in .NET

1. Download HtmlRenderer.PdfSharp Nuget packages: more...
Install-Package HtmlRenderer.PdfSharp -Version 1.5.0.6

2. Create a method in C# to convert html to pdf
public static void CreatePdfFromHtml (string html)
{
    Byte[] res = null;
    using (MemoryStream ms = new MemoryStream())
    {
var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf (html, PdfSharp.PageSize.A4);
pdf.Save(ms);
res = ms.ToArray();
    }
    File.WriteAllBytes("c:\\output.pdf", res);
}


Wednesday, 8 February 2017

C# Embed Image to Email

If the image is not embedded in the email, the recipient might not be able to see the image (e.g. in email signature). So use the following code to embed the image into HEML email:

// get the actual image url and assign id (content id) and assign a unique id to the image
Attachment imgAtt = new Attachment(@"C:\Images\DesireImage.jpg");
imgAtt.ContentId = "image";
email.Attachments.Add(imgAtt);

Add the image (with its unique id) to the body of the html email:
<img src='cid:image' />


Tuesday, 7 February 2017

C# ASP.NET Disable the Button After First Click Until the Process is Finished

Simply add the following properties to the desired button:

  • UseSubmitBehavior = "false" 
  • OnClientClick = "this.disabled=true; this.value='Processing. Please Wait...';"   more...

Monday, 30 January 2017

C# ASP.NET Hide Image Path on the Page

public void DrawImage(string imageURL)
{
    // convert image to bytes array
    WebClient wClient = new WebClient();
    byte[] imageBytes = wClient.DownloadData(@imageURL);

         // create memory stream of bytes array and convert image to base 64 and display it

    MemoryStream imgStream = new MemoryStream(imageBytes);
    ImageBox.ImageUrl = "data:image/jpg;base64," + Convert.ToBase64String(imgStream.ToArray(), 0, imgStream.ToArray().Length);
}

*ImageBox is a image control on the page.
*Sample call: DrawImage("c:\windows\image.jpg")



Analysis Service in Power BI Report Server

 We couldn’t connect to the Analysis Services server. Make sure you’ve entered the connection string correctly... link