[英]Save an image on asp.net server
I'm trying to save a piture recovered from a byte[] on the asp.net server. 我正在尝试保存从asp.net服务器上的byte []恢复的图片。 Here is my code :
这是我的代码:
MemoryStream ms = new MemoryStream(cli.LOGO, 0, cli.LOGO.Length);
ms.Write(cli.LOGO, 0, cli.LOGO.Length);
string thePath = Server.MapPath("~/App_Data");
string wholePath = thePath + "\\logo.jpg";
FileStream fs = new FileStream(wholePath, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(cli.LOGO);
bw.Close();
Where cli.LOGO is a byte array. 其中cli.LOGO是字节数组。 I'm just trying to save it as a .jpg image in my App_Data folder (or anything else of course) but... It's doing nothing.
我只是想将其另存为.jpg图像到我的App_Data文件夹(或其他任何文件)中,但是...什么也没做。 cli.LOGO is not empty, but the file is not created... Why so ?
cli.LOGO不为空,但未创建文件...为什么这样? Is it the proper way to save an image ?
这是保存图像的正确方法吗? Thanks !
谢谢 !
Try like this which is a bit shorter than your code: 尝试这样,它比您的代码短一点:
string path = Server.MapPath("~/App_Data/logo.jpg");
File.WriteAllBytes("file", cli.LOGO);
try doing this 尝试这样做
if (Request.Files["Photo"] != null)
{
string path = "/uploads/" + DateTime.Now.Ticks.ToString() + "_" + Request.Files["Photo"].FileName;
Request.Files["Photo"].SaveAs(Server.MapPath(path));
SP.PhotoPath = path;
//The MapPath method maps the specified relative or virtual path to the
//corresponding physical directory on the server.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.