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. problem related to image upload and save

problem related to image upload and save

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasehelpasp-net
6 Posts 4 Posters 1 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.
  • B Offline
    B Offline
    biswa47
    wrote on last edited by
    #1

    hi frindz i have problem n need ur help i am developing an application with asp.net along with c#.net using sqlserver2005 as db i want to add a image in the database. maeans i want to keep the path of image from where it is updated.and want to keep the image in seperate folder with iin the application name image. can you tell me what wil be code to " upload a picture in my application and then store the path name in the db and the image in a seperate folder inside my application" thanks in advance biswa007

    S A A 3 Replies Last reply
    0
    • B biswa47

      hi frindz i have problem n need ur help i am developing an application with asp.net along with c#.net using sqlserver2005 as db i want to add a image in the database. maeans i want to keep the path of image from where it is updated.and want to keep the image in seperate folder with iin the application name image. can you tell me what wil be code to " upload a picture in my application and then store the path name in the db and the image in a seperate folder inside my application" thanks in advance biswa007

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      Hi Just use File upload control that will upload the image that you want to update. Regarding the file path FileUpload1.PostedFile.FileName will give you full path path of file from client machine Google the subject you will find more articles on this topic

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

      1 Reply Last reply
      0
      • B biswa47

        hi frindz i have problem n need ur help i am developing an application with asp.net along with c#.net using sqlserver2005 as db i want to add a image in the database. maeans i want to keep the path of image from where it is updated.and want to keep the image in seperate folder with iin the application name image. can you tell me what wil be code to " upload a picture in my application and then store the path name in the db and the image in a seperate folder inside my application" thanks in advance biswa007

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        this will help, you to upload image........ and Store the path in database protected void Button2_Click(object sender, EventArgs e) { string sSavePath; string sThumbExtension; int intThumbWidth; int intThumbHeight; sSavePath = _Default.fullpath; sThumbExtension = "_thumb"; intThumbWidth = 160; intThumbHeight = 120; // If file field isn’t empty if (FileUpload1.PostedFile != null) { // Check file size (mustn’t be 0) HttpPostedFile myFile = FileUpload1.PostedFile; int nFileLen = myFile.ContentLength; if (nFileLen == 0) { lblOutput.Text = "No file was uploaded."; return; } // Check file extension (must be JPG) if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg") { lblOutput.Text = "The file must have an extension of JPG"; return; } // Read file into a data stream byte[] myData = new Byte[nFileLen]; myFile.InputStream.Read(myData, 0, nFileLen); // Make sure a duplicate file doesn’t exist. If it does, keep on appending an // incremental numeric until it is unique string sFilename = System.IO.Path.GetFileName(myFile.FileName); int file_append = 0; while (System.IO.File.Exists(( (sSavePath + sFilename)))) { file_append++; sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + ".jpg"; } // Save the stream to disk System.IO.FileStream newFile = new System.IO.FileStream((sSavePath + sFilename), System.IO.FileMode.Create); newFile.Write(myData, 0, myData.Length); newFile.Close(); // Check whether the file is really a JPEG by opening it System.Drawing.Image.GetThumbnailImageAbort myCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); Bitmap myBitmap; try { myBitmap = new Bitmap((sSavePath + sFilename)); // If jpg file is a jpeg, create a thumbnail filename that is unique. file_append = 0; string sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + sThumbExtension + ".jpg"; while (System.IO.File.Exists((sSavePath + sThumbFile))) { file_append++; sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + sThumbExtension + ".jpg"; } // Save thumbnail and output it onto the webpage System.Drawing.Image myThumbnail = myBitmap.GetThumbnailImage(intThumbWidth, intThumbHeight, myCallBack, IntPtr.Zero); // myThumbnail.Save((sSavePath + sThumbFile)); Image1.ImageUrl = @"~\" + (string)Session["user_name"].ToString() + @"\" + sSavePath + sFilename; //+ sThumbFile; //Directory.GetCurrentDire

        1 Reply Last reply
        0
        • B biswa47

          hi frindz i have problem n need ur help i am developing an application with asp.net along with c#.net using sqlserver2005 as db i want to add a image in the database. maeans i want to keep the path of image from where it is updated.and want to keep the image in seperate folder with iin the application name image. can you tell me what wil be code to " upload a picture in my application and then store the path name in the db and the image in a seperate folder inside my application" thanks in advance biswa007

          A Offline
          A Offline
          Atif Ali Bhatti
          wrote on last edited by
          #4

          Assalam-0-Alaikum, hru? well in .Net 2.0 there is a file upload control. put it on ur .aspx page. In code behind file provide its id and press a dot(.). Now the real fun starts here. --- to get file name : dim fileName As String = FileUpload1.PostedFile.FileName then u can use this string fileName to save it in the database using inLine Query or Stored Procedure etc. If u have Problem Inserting data in the database, do let me know. i would write u know how to do this. -- to Save file in the specified Location: FileUpload1.PostedFile.SaveAs("Location as string") there are other properties and method for the fileupload control tht u could use but depend on the requirement. Hope it Helps. Regards. Atif Ali Bhatti. Software Engineer. Esoul Consultancy Pvt. Ltd.

          B 1 Reply Last reply
          0
          • A Atif Ali Bhatti

            Assalam-0-Alaikum, hru? well in .Net 2.0 there is a file upload control. put it on ur .aspx page. In code behind file provide its id and press a dot(.). Now the real fun starts here. --- to get file name : dim fileName As String = FileUpload1.PostedFile.FileName then u can use this string fileName to save it in the database using inLine Query or Stored Procedure etc. If u have Problem Inserting data in the database, do let me know. i would write u know how to do this. -- to Save file in the specified Location: FileUpload1.PostedFile.SaveAs("Location as string") there are other properties and method for the fileupload control tht u could use but depend on the requirement. Hope it Helps. Regards. Atif Ali Bhatti. Software Engineer. Esoul Consultancy Pvt. Ltd.

            B Offline
            B Offline
            biswa47
            wrote on last edited by
            #5

            hai i am using the file upload control indotnet as told by you.but here i want store the path of the image where it woulb stored not where it was stored. accaording 2 ur soln it stores the the path of the image from where it upload the image...so can u solve it.

            A 1 Reply Last reply
            0
            • B biswa47

              hai i am using the file upload control indotnet as told by you.but here i want store the path of the image where it woulb stored not where it was stored. accaording 2 ur soln it stores the the path of the image from where it upload the image...so can u solve it.

              A Offline
              A Offline
              Atif Ali Bhatti
              wrote on last edited by
              #6

              Assalam-0-alaikum, yes i would tell u. look its u who will decide where to store the file. like, fileupload1.postedfile.saveas("c:\myweb\images\image1.jpg") now save the same path in the database i.e., c:\myweb\images\image1.jpg now Question arises how to differentiate files. give them a unique name. now how to give a unique name? there are so many ways but how do i save is, i create a folder with the username, save the file and name it with the username concatenated with some other patameters to make it unique. hope u get it. Regards. Atif Ali Bhatti. Software Engineer. eSoul Consultancy Pvt. Ltd.

              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