C# 在asp.net服务器上保存映像

C# 在asp.net服务器上保存映像,c#,asp.net,jpeg,C#,Asp.net,Jpeg,我正在尝试保存从asp.net服务器上的字节[]恢复的文件。这是我的密码: 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 = th

我正在尝试保存从asp.net服务器上的字节[]恢复的文件。这是我的密码:

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是字节数组。我只是想在我的App_数据文件夹(当然也可以是其他任何文件夹)中将它保存为.jpg图像,但是。。。它什么也没做。cli.LOGO不为空,但未创建文件。。。为什么会这样?这是保存图像的正确方法吗?谢谢

像这样尝试,它比您的代码短一点:

string path = Server.MapPath("~/App_Data/logo.jpg");
File.WriteAllBytes("file", cli.LOGO);
试着这样做

 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.
            }

调用
File.writealBytes
。如果(cli.LOGO!=null){string thePath=Server.MapPath(“~/App_Data”);string wholePath=thePath+“\\LOGO.jpg”;System.IO.File.writealBytes(wholePath,cli.LOGO);},我已经尝试了以下方法。但是它在附近不起作用。。。什么也不做。知道如何调试吗?