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. General Programming
  3. C#
  4. Deleting temporary file

Deleting temporary file

Scheduled Pinned Locked Moved C#
databasehelpquestion
4 Posts 4 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.
  • S Offline
    S Offline
    spy
    wrote on last edited by
    #1

    hey guyz how can i delete the temporary file that i created, whenever i retrieved the image saved in my database.. it keeps on growing..i hope u can help me regarding these... here is the code string strfn = Convert.ToString(DateTime.Now.ToFileTime()); FileStream fs=new FileStream(strfn,FileMode.CreateNew,FileAccess.Write); fs.Write(imageByte,0,imageByte.Length); fs.Flush(); fs.Close(); picBox.Image = Image.FromFile(strfn);

    B L L 3 Replies Last reply
    0
    • S spy

      hey guyz how can i delete the temporary file that i created, whenever i retrieved the image saved in my database.. it keeps on growing..i hope u can help me regarding these... here is the code string strfn = Convert.ToString(DateTime.Now.ToFileTime()); FileStream fs=new FileStream(strfn,FileMode.CreateNew,FileAccess.Write); fs.Write(imageByte,0,imageByte.Length); fs.Flush(); fs.Close(); picBox.Image = Image.FromFile(strfn);

      B Offline
      B Offline
      blackjack2150
      wrote on last edited by
      #2

      System.IO.File.Delete(...)

      1 Reply Last reply
      0
      • S spy

        hey guyz how can i delete the temporary file that i created, whenever i retrieved the image saved in my database.. it keeps on growing..i hope u can help me regarding these... here is the code string strfn = Convert.ToString(DateTime.Now.ToFileTime()); FileStream fs=new FileStream(strfn,FileMode.CreateNew,FileAccess.Write); fs.Write(imageByte,0,imageByte.Length); fs.Flush(); fs.Close(); picBox.Image = Image.FromFile(strfn);

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, FromFile keeps the file locked. Replace the last line picBox.Image = Image.FromFile(strfn); by the following (approx):

        Bitmap bm = Image.FromFile(strfn);
        picBox.Image=new Bitmap(bm);
        bm.Dispose();
        File.Delete(strfn);

        :)

        Luc Pattyn


        try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


        1 Reply Last reply
        0
        • S spy

          hey guyz how can i delete the temporary file that i created, whenever i retrieved the image saved in my database.. it keeps on growing..i hope u can help me regarding these... here is the code string strfn = Convert.ToString(DateTime.Now.ToFileTime()); FileStream fs=new FileStream(strfn,FileMode.CreateNew,FileAccess.Write); fs.Write(imageByte,0,imageByte.Length); fs.Flush(); fs.Close(); picBox.Image = Image.FromFile(strfn);

          L Offline
          L Offline
          L Henson
          wrote on last edited by
          #4

          Could you not use a MemoryStream and Image.FromStream?

          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