Posts

Convert a color image to black and white image in C#

In this simple article you will learn that how we can convert colored image into black and white image in C#.net. This technique uses a ColorMatrix to perform the conversion. A ColorMatrix is a 5x5 matrix that can make just about any modifications to the color of an image. A ColorMatrix is pretty complicated and deserves a whole tutorial to itself. We're going to use GDI to draw the new black and white image. The benefit of this technique over the last one is that we don't need to know any information about the image's pixel format. The code here is pretty straight forward. First create the blank image and get a Graphics object from it. Next, create the ColorMatrix that will convert the original image to grayscale. Declare an ImageAttributes object that will use the ColorMatrix and use it to draw the new image using DrawImage . Below is code for your proble m      

Document Upload in Azure Cloud with ASP.Net MVC

Configure Azure storage connection string To configure your connection string, open the web .config or app.config file from Solution Explorer in Visual Studio.Add below line in <appSettings> tag of your config file. Replace "your account name" with the name of your storage account, and "your account key" with your account access key: < add key = " StorageConnectionString " value = " DefaultEndpointsProtocol=https;AccountName=<your account name>;AccountKey=<your account key> " /> Parse the connection string from Config file The Microsoft Azure Configuration Manager Library for .NET provides a class for parsing a connection string from a configuration file. below is example that shows to retrieve a connection string from a configuration file: CloudStorageAccount storageAccount = CloudStorageAccount .Parse( CloudConfigurationManager .GetSetting( "StorageConnectionString" )); Above line w...

Export excel and Pdf with Kendo UI MVC c#

Image
Export to Excel and Pdf Export excel and pdf is now a days a basic needs of clients for saving reports or tables data. Kendo UI has build features for exporting table data to excel and pdf with Excel() and Pdf() functions. Functions are used as below. @(Html.Kendo().Grid(Model) .Name("timeGrid") .NoRecords() .Columns(columns => { columns.Bound(p => p.Field1).Title("Field1"); columns.Bound(p => p.Field2).Title("Field2"); columns.Bound(p => p.Field3).Title("Field3"); }).Groupable() .Sortable() .Excel(excel => excel .FileName("FileName.xlsx").AllPages(true) .Filterable(true) .ProxyURL(Url.Action("Excel_Export_Save", "Controller")) ) .Pdf(pdf => pdf .AllPages() .FileName("FileName.pdf").ForceProxy(true) .ProxyURL(Url.Action("Pdf_Export_Save...

File Upload uisng Jquery in C# ASP.Net MVC

There so many ways to upload files with jqueries in ASP.Net C#. One way is with creating XMLHttpRequest and another way is with FormData object. In this post i'll show uploading files and saving form data in one ajax call using jquery. Upload Files with Jquery in ASP.Net MVC C# First code for View which represents normal html code of form @model modelname File Upload File @Html.TextBoxFor(m => m.File, new { @type = "file", @multiple = "multiple" }) Field 1 @Html.TextBoxFor(m => m.Field1, new { @class = "form-control datepicker" }) @Html.ValidationMessageFor(m => m.Field1) Submit MVC Controller Code for Saving File In controller create action method with two arguments one is for formdata and another one is for List of HttpPostedFileBase Class which represents multiple files that you select. public JsonResult SaveFilesWithFormData(ModelName FormData, List Of HTTPPostedFileBase Files) //Model Name rep...

Display image from byte array in ASP.NET MVC

Image
There are many ways to display image from byte array in MVC as well as normal ASP.Net projects.In this post I'll explain couple of them. 1) Using BASE64 string of the image through ViewBag  The first way i s by sending a Base64 string as dataURL through ViewBag. As shown in b elow action method under consideration generates such a Base64 string of the image (often called Data URL) and then pass it to the view via a ViewBag property in MVC . public ActionResult Image() { string path = Server.MapPath("~/images/computer.png"); byte[] imageByteData = System.IO.File.ReadAllBytes(path); string imageBase64Data=Convert.ToBase64String(imageByteData); string imageDataURL= string.Format("data:image/png;base64,{0}", imageBase64Data); ViewBag.ImageData = imageDataURL; return View(); } The above code is a action method of Controller. In this action method it uses physical path of image and read all bytes of that image using ReadAllByte...

C# Currency Converter using Google API

C urrenc y conve rsion in C# u sing Googl e API There are so many ways to convert amount from one currency to another currency like using google finance converter, Yahoo finance and rate-exchange . In this post i will show conversion using   Google Finance Converter. In b elow code, I create one WebRequest for Google Finance Converter which will return result of arguments which are attached with it. Get the response of WebRequest in form of Stream and stored it in streamReader (which is the object of StreamReader Class) . By using, Regex fetched converted amount with desired currency code and stored this result into a string variable and again using Regex fetched only decimal part from generated string. Hope this post will help you to get the exact result that you want. public string CurrencyConvert(decimal amount, string fromCurrency, string toCurrency) { decimal currency = 0; string convertedAmount = "0"; try { string...

Allow only numbers in textbox jquery

For allowing only numbers in textbox using jQuery, you can create key-press or key-down or key-up event for textbox by using textbox id or class. In below example i used class name ("number") for applying validation to textbox.  You just had copy above code and paste where you want to apply numeric validation. For allowin g numbers with decimal points