Posts

Showing posts from January, 2020

Stored Procedure with Try Catch in SQL

-- =============================================          -- Author:  <SARAVANANS>          -- Create date: <22-NOV-14>          -- Description: <Common sp to update employee details>          -- [usp_update_employee] 1        -- =============================================          CREATE PROCEDURE [dbo].[usp_update_employee]             @EmployeeID INT ,  @EmployeeSalary MONEY AS          BEGIN TRY                  SET ARITHABORT  ON        SET NOCOUNT ON    UPDATE EMPLOYEE SET EMPLOYEESALARY =@EmployeeSalary WHERE EmployeeID =@EmployeeID  END TRY          BEGIN CATCH            SELECT @ErrorNumbe...

Create PDF from TIFF using iTextSharp in C#

        private void ConvertTIFFtoPDF(string tiffFileName,  PdfWriter writer,  Document document)         {             try             {                 using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(tiffFileName))                 {                     int numberOfPages = bitmap.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);                     PdfContentByte cb = writer.DirectContent;                     for (int page = 0; page < numberOfPages; page++)                     {                         bi...

How to check whether the website is active or not using c#?

HttpClient client = new HttpClient (); var response = await client . GetAsync ( url ); if (r esponse . IsSuccessStatusCode ) { return "Active" ; } else { return "InActive" ; }

Creating web api call using C#

public class WebapiClient  { private static string _apiBaseUrl=Configuration Manager.AppSettings["Apiurl"]; private static double _apiTimeout=Convert.ToDouble(Configuration Manager.AppSettings["ApiTimeout"]); public static HttpClient CreateHttpClient() { HttpClient client= new HttpClient(); client.BaseAddress=new Uri(_apiBaseUrl); client.Timeout=TimeSpan.FromMinutes(_A pi time out); return client; } } public class ApicallTest { public bool MakeApiCall() { try { var apiClient= WebApiClient.CreateHttpClient(); HttpResponseMessage response= apiClient.PostAsJsonAsync(apiname, input).Result; if(response.StatusCode) { var jsonContent= response.Content.ReadAsStringAsync().Result; var result= JsonConvert.DeserializeObject<book>(jsonContent); return result; } else { return false; } } catch() { return false; } finally { apiClient.Dispose (); } } }