Re: File used by another process error without using the stream

  •  10-08-2008, 11:19 PM

    Re: File used by another process error without using the stream

    Hi,
     
    When the code execute
     
    // Save the file as image
    _uploadedImage = System.Drawing.Image.FromFile(args.GetTempFilePath());
     
    the file would be locked until the _uploadedImage is disposed.
     
    So
     
    return System.Drawing.Image.FromFile(files[0]);
    would not works.
     
    maybe you can try this way :
     
      static public System.Drawing.Image LoadFromFileAndFree(string filepath)
      {
       byte[] data;
       using (System.IO.FileStream fs = new System.IO.FileStream(filepath,
        System.IO.FileMode.Open, System.IO.FileAccess.Read))
       {
        data = new byte[fs.Length];
        fs.Read(data, 0, data.Length);
       }
       return System.Drawing.Image.FromStream(new System.IO.MemoryStream(data));
      }
     
    Regards , Terry
View Complete Thread