DS Solutions

Pages

Sunday, March 5, 2017

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.

Wednesday, July 6, 2016

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:

Above line will parse CloudStorageAccount from your connection
string.

Create the Blob
service client

The CloudBlobClient class enables you to retrieve
containers and blobs stored in your storage. Here's one way to create the
service client:

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

Create
Containers for Blob service Client

Below
example shows how to create a container for blob service client, you can create
different containers for different users by replacing your names with
"<container name>" in below code and also shows how to set
permissions for that perticular container :

For defining container name there are
basic rules are there, which are as follows :

Container names
must start with a letter or number, and can contain only letters, numbers, and
the dash (-) character.

Every dash (-)
character must be immediately preceded and followed by a letter or number;
consecutive dashes are not permitted in container names.

All letters in a
container name must be lowercase.

Container names
must be from 3 through 63 characters long.

Create
Blob into Containers

To
upload a file to a block blob, get a container reference as shown above and use
it to get a block blob reference. Once you have a blob reference, you can
upload any stream of data to it by calling the UploadFromStream method. This operation will create the
blob if it didn't previously exist, or overwrite it if it does exist.

The
following example shows how to upload a blob into a container which is already
created :

CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

blob.UploadFromStream(upload.InputStream);

Now, you can get that files or data by using blob.Uri.AbsoluteUri, this will give you url for download or
display data or files that you uploaded into

blob container. Or you can use below line of code for download
stream of data which uploaded uisng UploadFromStream
function
:

In above code,
first it will retreive refernce of blob which you want to download, and then it
will transfer the blob contents to a stream object and then save that stream
into file which given as "@"path\myfile".

Delete blob from Container :

To
delete a blob, first get a blob reference and then call the Delete method of
that blob as shown below :

Place above code in your View page, in above code the use of Excel() and Pdf() function in Kendo MVC.

For Generating buttons for Excel and Pdf export Toolbar() function is used shown in code.

In above their sub-functions which are used like FileName(), ProxyURL(),etc. are used to customize Excel and Pdf.

FileName() : This function is used to give file name.

ProxyURL() : Sometimes client wants reports or file in different format or customize view in file at that time ProxyURL() function is used to create customize file. ProxyURL() generally takes two arguments like action name and controller name.

ProxyURL Action in Controller

Filterable() : This function takes one argument i.e. true or false. If you passed true and then it will allows filtration in generated excel which you used in table.

Friday, April 29, 2016

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.

MVC Controller Code for Saving FileIn 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.

Saturday, April 2, 2016

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 is by sending a Base64 string as dataURL through ViewBag. As shown in below 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.

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 usingReadAllBytes() method. Once it read all bytes of that image in form of byte array,it will converts that byte array into base64 string format.This converted base64 string is used to generate dataURL as shown in code. Take care of not to forget to append data:image/png;base64 at beginning of base64 string as shown.This way the browser knows that the
src attribute value itself contains the image data. and at last assign value of dataURL to ViewBag.and then just below line in View to use that ViewBag.

Output :

2) By Sending Image File as ActionResultIn this approach it will reads byte array from image physical path and creates one file, after this it will send that file as result of action method in Controller.

Friday, February 19, 2016

WWW version is very useful to make your web site easily searchable by web crawler also WWW version helps to increase your chances make your web site rank higher in SEO purpose.

One common use of URL Rewrite is redirecting http://domain.com to
http://www.domain.com. Many people are doing this for search engine
optimization (SEO) so that search engines only see the one site, rather
than two sites. The goal is to set a permanent 301 redirect.

URL Rewrite works at the global level, or site level (or application
level for that matter). Where you apply it is really up to how you
manage your server. Either will work for a domain name redirect like
this.You can choose to create the rules using IIS Manager, or
using a text editor and updating web.config directly.

For specifying non-WWW version to WWW version for your web site in C#.net, write below code in web.config inside system.webServer tag,