jag har en upload som fungerar finfint. Men sen har jag en HttpHandler som presenterar bilden. Och om jag har presenterat bilden med den och sedan försöker ladda upp en ny bild med samma namn så får jag.
The process cannot access the file "F:\Inetpub\wwwroot\wF\personal\img\6.jpg" because it is being used by another process
Jag förstår att filen används av httpHandlern men jag kan inte se var jag ska stänga den, så här kommer koden.
[red]
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using NineteenDecember;
namespace NineteenDecember.HttpHandler
{
/// <summary>
/// Summary description for viewimage.
/// </summary>
public class ViewImage: IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Image im = null;
string imgPath = "img/vforallaheader.jpg";
int imgQuality = 80;
if(HttpContext.Current.Request.QueryString["Path"] != null)
imgPath = HttpContext.Current.Request.QueryString["Path"];
if(HttpContext.Current.Request.QueryString["Quality"] != null)
imgQuality = Convert.ToInt32(HttpContext.Current.Request.QueryString["Quality"]);
if(!System.IO.File.Exists(HttpContext.Current.Server.MapPath(imgPath)))
{
im = Image.FromFile(HttpContext.Current.Server.MapPath("img/vforallaheader.jpg"));
}
else
{
try
{
im = Image.FromFile(HttpContext.Current.Server.MapPath(imgPath));
}
catch( Exception ex )
{
im = Image.FromFile(HttpContext.Current.Server.MapPath("img/vforallaheader.jpg"));
}
}
int imgSize = (int)im.Width;
if(HttpContext.Current.Request.QueryString["Size"] != null)
{
imgSize = Convert.ToInt32(HttpContext.Current.Request.QueryString["Size"]);
}
MemoryStream ms = Upload.ScaleAndStream(HttpContext.Current.Server.MapPath(imgPath), imgSize, imgQuality);
Byte[] Buffer = ms.ToArray();
HttpContext.Current.Response.BufferOutput = true;
ms.Close();
im.Dispose();
try
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.ContentType = "Image/jpeg";
HttpContext.Current.Response.AppendHeader("content-disposition", "inline");
HttpContext.Current.Response.OutputStream.Write(Buffer, 0, Buffer.Length);
}
catch( Exception ex )
{
//Debug.WriteLine(inputFileName);
throw(ex);
}
}
public bool IsReusable
{
get
{
return true;
}
}
}
}
[/red]
tacksamt om ni kunde hjälpa mig att felsöka denna....
mv icaaq