画像を保存するには、次のコードを使用します。
string filenamewithpath =
System.Web.HttpContext.Current.Server.MapPath(
@"~/userimages/" + incID + ".jpg");
System.IO.File.WriteAllBytes(filenamewithpath, Util.ReadFully(image));
public class Util
{
public static byte[] ReadFully(Stream stream)
{
byte[] buffer = new byte[32768];
using (MemoryStream ms = new MemoryStream())
{
while (true)
{
int read = stream.Read(buffer, 0, buffer.Length);
if (read <= 0)
return ms.ToArray();
ms.Write(buffer, 0, read);
}
}
}
}
上記はIDで画像を保存するために機能します。更新するときは、既存のイメージを上書きする必要があり、これを行う方法についてアドバイスが必要になります。