I want to uploade image and also want to store in database.Please anyone help me and tell me the code or share some link of uploading image.

thanxx

Dani AI

Generated

As asked about uploading an image and saving it to a database, here is a short, practical follow-up that fills gaps left by the links posted by and : two common patterns (with pros/cons), a minimal end-to-end example, and key validations/cautions that are often missing.

Minimal HTML form and a classic ASP.NET MVC action that saves the file to an uploads folder (recommended for scale) and records the path in a DB column:

<form action="/Home/Upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<button type="submit">Upload</button>
</form>

[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
    if (file == null || file.ContentLength == 0) return new HttpStatusCodeResult(400);
    var ext = Path.GetExtension(file.FileName).ToLowerInvariant();
    var allowed = new[] { ".jpg", ".jpeg", ".png", ".gif" };
    if (!allowed.Contains(ext)) return new HttpStatusCodeResult(415);

    var unique = Guid.NewGuid().ToString() + ext;
    var folder = Server.MapPath("~/uploads");
    Directory.CreateDirectory(folder);
    var path = Path.Combine(folder, unique);
    file.SaveAs(path);

    // insert path into Images table (FileName, Url, ContentType, Size)
    return RedirectToAction("Index");
}

If storing images in the database is required, use a varbinary(MAX) column and parameterized commands or an EF byte[] property. Example table:

CREATE TABLE Images (
  Id INT IDENTITY PRIMARY KEY,
  FileName NVARCHAR(260),
  ContentType NVARCHAR(100),
  Data VARBINARY(MAX),
  Size INT,
  UploadedAt DATETIME DEFAULT GETDATE()
);

Key cautions and troubleshooting (common missing points): validate both extension and actual MIME/content (e.g., open stream with an image library), enforce a max file size, sanitize/generate file names (GUIDs), ensure the uploads folder has write permission for the app pool identity, avoid storing large sets of images in DB unless needed (backup/restore and performance impact), generate thumbnails server-side to save bandwidth, and consider cloud blob storage (Azure/AWS) for scale. These checks reduce security and performance problems that often trip up first implementations.

Recommended Answers

All 2 Replies

There are really numerous way on how you can do this. But there is a good article on CodeProject and it helped me a lot.
Click Here

Google! Example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.