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. Images delete.

Images delete.

Scheduled Pinned Locked Moved ASP.NET
graphicssysadminhelptutorial
2 Posts 2 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.
  • J Offline
    J Offline
    jai 123
    wrote on last edited by
    #1

    hi, I am using the below coding to thumbnail creation, this coding is saving both the original image and the thumbnail image. I don’t want the original image. How to delete the original image. Please help me. private void btnUpload_Click(object sender, System.EventArgs e) { // Initialize variables string sSavePath; string sThumbExtension; int intThumbWidth; int intThumbHeight; // Set constant values sSavePath = "images/"; sThumbExtension = "_thumb"; intThumbWidth = 160; intThumbHeight = 120; // If file field isn’t empty if (filUpload.PostedFile != null) { // Check file size (mustn’t be 0) HttpPostedFile myFile = filUpload.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(Server.MapPath(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(Server.MapPath(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(Server.MapPath(sSavePath + sFilename)); // If jpg file is a jpeg, create a thumbnail filename that is uniqu

    G 1 Reply Last reply
    0
    • J jai 123

      hi, I am using the below coding to thumbnail creation, this coding is saving both the original image and the thumbnail image. I don’t want the original image. How to delete the original image. Please help me. private void btnUpload_Click(object sender, System.EventArgs e) { // Initialize variables string sSavePath; string sThumbExtension; int intThumbWidth; int intThumbHeight; // Set constant values sSavePath = "images/"; sThumbExtension = "_thumb"; intThumbWidth = 160; intThumbHeight = 120; // If file field isn’t empty if (filUpload.PostedFile != null) { // Check file size (mustn’t be 0) HttpPostedFile myFile = filUpload.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(Server.MapPath(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(Server.MapPath(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(Server.MapPath(sSavePath + sFilename)); // If jpg file is a jpeg, create a thumbnail filename that is uniqu

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You don't have to delete the file. Just don't create it. Create a MemoryStream object from the byte array, and load the image from that.

      jai 123 wrote:

      myFile.InputStream.Read(myData,0,nFileLen);

      That's not a secure way to read the data. The Read method returns an integer that tells you how many bytes where actually read, and this can be less than the number of bytes requested. You have to loop until you have read all bytes, or until the value returned is zero.

      --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

      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