Asp net check image resolution and save in db


ASP.NET is a popular used for building web applications. In this article, we will discuss how to check the resolution of an image and save it in a database ASP.NET.

Checking Image Resolution

saving an image in a database, it is important to check its resolution to ensure it meets certain . To do this, we can use the System. in ASP.NET.

using System.Drawing;

First, we need to create an instance of the Image class and load the image file.

string imagePath = "path_to_image.jpg";
Image image = Image.FromFile(imagePath);

Next, we can use the Width and Height properties of the Image class to get the resolution of the image.

int width = image.Width;
int height = image.Height;

We can then perform any necessary checks on the image resolution. For example, we can ensure that the image is at least a certain width and height.

Saving Image in Database

Once we have checked the image resolution, we can proceed to save the image in a database. The specific steps for saving an image in a database may vary depending on the database system you are using.

Here is a example of how to save an image in a SQL Server database using ASP.NET:

string connectionString = "your_connection_string";
string query = "INSERT INTO Images (Name, Resolution) VALUES (@Name, @Resolution)";

using (SqlConnection  = new SqlConnection(connectionString))
    using (SqlCommand command = new SqlCommand(query, connection))
        command.Parameters.AddWithValue("@Name", "image_name.jpg");
        command.Parameters.AddWithValue("@Resolution", $"{width}x{height}");


In this example, we assume that you have a table named “Images” in your database with columns “Name” and “Resolution”. We use parameterized queries to prevent SQL injection attacks.


In this article, we have discussed how to check the resolution of an image and save it in a database using ASP.NET. By checking the image resolution before saving, we can ensure that only images certain requirements are stored in the database. Saving images in a database can be useful for various applications, such as image galleries or content management systems.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents