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")



Sunday, 11 December 2016

Backup(Export) / Restore(Import) Passwords in Google Chrome

Backup/Export
  • Open Chrome://flags in your Chrome
  • Find Password Import and Export option, select Enabled from the drop-down box, and then restart the Chrome browser
  • Now, open Chrome://settings/passwords page
  • Click on Export button to export/backup saved passwords
  • Enter your Windows account password, when asked
  • Passwords will be saved into a CSV file

Restore/Import
  • Open Chrome://settings/passwords page
  • Click the Import button to restore previously saved passwords


Wednesday, 9 November 2016

Friday, 14 October 2016

Require PowerShell Modules to Excute CmdLets in C#

Add the following Powershell library as a reference:
C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0

Import the following libraries in C#:
  • using System.Management.Automation;
  • using System.Management.Automation.Runspaces;


Create a C# method:
public void ExecuteScript(string fileName)
{
     try
     {
         string script = File.ReadAllText(fileName);
         var shell = PowerShell.Create();
         shell.Commands.AddScript(script);
         shell.Invoke();
     }
     catch (Exception) {
         // Exception Handling Code
     }
}


Wednesday, 5 October 2016

Get Network Account ID in IIS and ASP.NET

  1. Follow this link to DisableLoopbackCheck more...
  2. In IIS, set the desire application pool to: "ApplicaitonPoolIdentity"
  3. In IIS, set the "Authentication" for the desire website to only "Windows Authentication = Enabled" and others disabled
  4. In you ASP.NET application, under default page:
    • Session["UserName"] = Utilities.GetUserNetworkLoginName(Request.ServerVariables["AUTH_USER"]);
  5.  In "Utilities" class, use the following method to get the user in both IIS Express and IIS:
    •  public static string GetUserNetworkLoginName(string networkLoginId)
              {           
                  if (string.IsNullOrEmpty(networkLoginId))
                      networkLoginId = WindowsIdentity.GetCurrent().Name;

                  // if login contains monet\, drop it
                  if (networkLoginId.Contains("\\"))
                      networkLoginId = networkLoginId.Substring(networkLoginId.LastIndexOf("\\") + 1);

                  return networkLoginId;
              }


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