Skip to main content

Posts

Showing posts from 2014

Adding BitMap on WPF Flow Document

Here is the C# code snippet for adding BitMap on Flow Document of WPF. System.Windows.Controls.Image testimage = new System.Windows.Controls.Image();  object o = Properties.Resources.ResourceManager.GetObject("bitmap1");  Bitmap bm = (Bitmap)o;  var memoryStream = new MemoryStream();  bm.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);  memoryStream.Position = 0; var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memoryStream; bitmapImage.EndInit(); testimage.Source = bitmapImage; testimage.Stretch = Stretch.None; testimage.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;  Label lblImageName= new Label(); lblImageName.Content = "bitmap1"; StackPanel sp1 = new StackPanel(); sp1.Children.Add(testimage); sp1.Children.Add(lblImageName); dc1.Children.Add(sp1); BlockUIContainer buc = new BlockUIContainer(dc1); flowDoc.Blocks.Add(buc); XAML Code:             <Grid>  

ASP.NET Page Life cycle

ASP.NET Life cycle At higer level, this is a two step process - 1. When user sends a request ASP.NET creates an environment which can process the request. Here ASP.NET creates instances of the core objects that will be used to process the requst. This includes HTTPContext, HttpRequest and HttpResponse object. 2. After creating the environment their is a series of events processed by modules, handlers and page objects to process the request. (I) ASP.NET Environment Creations 1. User sends a request to IIS. IIS first checks which ISAPI (Internet Server Application Programming Interface) extension can server this request. If the request is for an .aspx page then the request will be redirected to ASP.NET (aspnet_isapi.dll) for processing. 2. If this is the first request to the website then a class called as "ApplicationManager" creates a application domian where the website can run.Application domain provides the actual isolation levels so that various website host

Adding AJAX HTMLEditorExtender control in webform

Here are the steps to add ajax HMTLEditorExtender control in webform. 1. In VS 2013 open Tools > Library Package Manager > Package Manager Console. 2. Enter command : PM> Install-Package AjaxControlToolkit . This will download and add AjaxControlToolkit.dll reference with your website. 3. Add following tags in web.config  - <configSections>     <sectionGroup name="system.web">       <section name="sanitizer" requirePermission="false" type="AjaxControlToolkit.Sanitizer.ProviderSanitizerSection, AjaxControlToolkit" />     </sectionGroup>   </configSections> <sanitizer defaultProvider="HtmlAgilityPackSanitizerProvider">       <providers>         <add name="HtmlAgilityPackSanitizerProvider" type="AjaxControlToolkit.Sanitizer.HtmlAgilityPackSanitizerProvider"></add>       </providers>     </sanitizer> <configSections> sho

Implementing Validation group in ASP.NET

Sometimes we have multiple sections in our web forms for validation. These sections need their separate validation. For example I have two sections - one to insert a category and other one to update existing category name. For inserting category the  text box is txtNewCategory and for updating category text box is txtUpdateCategory. Both have RequiredFieldValidator validation control. In this case we want that when validation of txtNewCategory happens then txtUpdateCategory should not be validated and vice versa. This can be achieved by creating Validation Group. Here is the example  - <asp:TextBox ID="txtNewCategory" runat="server"> </asp:TextBox> <asp:RequiredFieldValidator ID="reqFieldCategory" runat="server"  ValidationGroup="GrpNewCategory" ControlToValidate="txtNewCategoryName" ErrorMessage="Please enter new category name"> </asp:RequiredFieldValidator>  <asp:Button ID

Adding Countdown on webpage using jQuery Countdown.js

I wanted to show a countdown on my webpage. So I searched across the internet to find the solution. I found a jQuery library - Countdown.js useful for this. Here I am sharing the script used  for creating the default countdown of this jQuery library. <head> <title>jQuery Countdown</title> <link rel="stylesheet" href="Styles/jquery.countdown.css"></link> <style type="text/css"> #defaultCountdown { width: 240px; height: 45px; } </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript" src="Scripts/jquery.plugin.js"></script> <script type="text/javascript" src="Scripts/jquery.countdown.js"></script> <script type="text/javascript">     $(function () {         $('#defaultCountdown').countdown({

invalid compressed data--format violated on Linux

I created a zip file on Linux environment. I wanted to transfer this zip file to another linux machine. For this, I uploaded the zip file to server using ftp. Now, after downloading the zip file on other server I tried to unzip it on other linux machine. Their I get following error - gzip: <file name> : invalid compressed data--format violated After some analysis and googling I found that reason for this error was the way I was uploading and downloading files from ftp server. When I used binary format to upload and download the zip file I was able to unzip it on other linux machine without any error. Here are the commands that I used on linux file to zip and upload file - $ gzip file.txt             (This will create file.txt.gz file) $ ftp <URL of ftp server> $ ftp : <enter username and password to login> $ ftp binary $ ftp put file.txt.gz Above commands will zip file.txt and upload that on server in binary format On other linux machine I used

Prepared Statements for Database driven application

Prepared Statement is commonly used by application to execute the same parameterized SQL statement again and again. Prepared statements are compiled only once. If we need to execute a statement multiple times then execution of prepared statement is faster as it is compiled only once, while in case if we are using direct statements then each statement is first compiled every time before execution. So, time taken in Prepared execution is lesser as compared to the time taken in direct execution. Prepared statement are also known as parameterized queries. Parameterized queries and prepared statements are features of database management systems that basically act as templates in which SQL can be executed. Example of Prepared Statement using Java and C# We are using Emp table. Here "id" is the primary key of the table. Following query will retrive all the data of a row for id =1 SELECT * FROM Emp WHERE id =1 Now, if we create a template of above statement and use that fo