0

我正在尝试保存从 asp.net 服务器上的 byte[] 恢复的 piture。这是我的代码:

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();

其中 cli.LOGO 是一个字节数组。我只是想将它作为 .jpg 图像保存在我的 App_Data 文件夹中(当然也可以是其他任何东西)但是......它什么也没做。cli.LOGO 不为空,但文件没有创建...为什么会这样?这是保存图像的正确方法吗?谢谢 !

4

2 回答 2

0

试试这样,它比你的代码短一点:

string path = Server.MapPath("~/App_Data/logo.jpg");
File.WriteAllBytes("file", cli.LOGO);
于 2013-08-27T16:05:29.270 回答
0

尝试这样做

 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.
            }
于 2017-02-25T06:53:32.810 回答