Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Uploading an Image

Uploading an Image

Scheduled Pinned Locked Moved ASP.NET
helpdatabasequestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10281574
    wrote on last edited by
    #1

    Hey Friends, Thnx For the help last time, It was great on your part and the error gor solved. But again have stuck up at a point, where i have to upload the images and store it in the questions database.!the question must be in image format and the answers could also be in image format, and i have to save all this in the question database.! Please Help me out friends.!

    A P 2 Replies Last reply
    0
    • U User 10281574

      Hey Friends, Thnx For the help last time, It was great on your part and the error gor solved. But again have stuck up at a point, where i have to upload the images and store it in the questions database.!the question must be in image format and the answers could also be in image format, and i have to save all this in the question database.! Please Help me out friends.!

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      There are quite a few articles on this topic. Try the following for some tips - Storing images in SQL Server using EF and ASP.NET[^] http://www.dotnetgallery.com/kb/resource21-How-to-store-and-retrieve-images-from-SQL-server-database-using-aspnet.aspx[^]

      Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial

      1 Reply Last reply
      0
      • U User 10281574

        Hey Friends, Thnx For the help last time, It was great on your part and the error gor solved. But again have stuck up at a point, where i have to upload the images and store it in the questions database.!the question must be in image format and the answers could also be in image format, and i have to save all this in the question database.! Please Help me out friends.!

        P Offline
        P Offline
        Pratik Bhuva
        wrote on last edited by
        #3

        Code To upload Your Image to folder

        YourFunctionToUploadImage()
        {
        //Check FileUpload controll has File Or not
        if (ImageFileUploadControll.HasFile)
        {
        string fileExtention = System.IO.Path.GetExtension(ImageFileUploadControll.FileName);
        //Check For Valid Extension
        if (fileExtention.ToLower() != ".jpg" && fileExtention.ToLower() != ".jpeg" && fileExtention.ToLower() != ".png")
        {
        lblUploadstatus.Text = "Invalid File Choose .jpg/.jpeg/.png/.gif";
        }
        else
        {
        //check if file already Exists in Folder
        if (File.Exists(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName)))
        {
        lblUploadstatus.Text = "File Already Exists. Rename filename";
        }
        else
        {
        //To Save Image To your Specific Location.
        //srever.mappath takes us to Folder which containing our application
        ImageFileUploadControll.SaveAs(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName));
        lblUploadstatus.Text = "Upload Status : File Uploaded Successfully";
        }
        }

        }
        else
        {
        lblUploadstatus.Text = "Please Select File";
        }
        }

        Code To Retrive All Images form Folder and display in image_control you can use

        PageLoadEvent()
        {
        //use DirectoryInfo to get all imageFile's Information
        DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/Folder_Name/"));
        FileInfo[] fi = dir.GetFiles();

           //Now you just need to create new image control each time and add ImageUrl to it
           foreach(FileInfo f in fi)
           {
                string imageUrl = f.ToString();
                Image img = new Image();
                img.ImageUrl = "~/Folder\_Name/"+"imageUrl";
           }
        

        }

        Hope This Help

        Pratik Bhuva --------------- The night is darkest just before the dawn. And I promise you, the dawn is coming

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups