简体   繁体   English

将图像保存在asp.net服务器上

[英]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.

相关问题 使用ASP.NET MVC将图像保存到数据库 - Save image to database with ASP.NET MVC ASP.NET在ashx处理程序中保存图像 - ASP.NET Save Image in ashx handler 从asp.net网站保存图像 - Save a image from asp.net website 如何在客户端(javascript)或服务器端的asp.net上将html页面的一部分保存到图像或pdf? - How to save part of an html page to an image or pdf either on client (javascript) or asp.net on the server side? 带有asp.net 4.0的JQuery网络摄像头插件,无法在服务器上保存捕获的图像 - JQuery webcam plugin with asp.net 4.0, not able to save captured image on server 如何访问剪贴板图像并将其保存在asp.net Web应用程序的服务器位置? - How to access clipboard image and save it at server location in asp.net web application? 如何使用 ASP.NET 在一台服务器上上传图像并将其保存在另一台服务器上 - How to upload an image on one server and save it on another using ASP.NET ASP.NET C#-从QueryString获取图像并将其另存为.ico - ASP.NET C# - get image from QueryString and save it to server as .ico 使用c#在asp.net中的SQL Server中保存和检索图像 - Image Save and Retrieve in SQL Server in asp.net using c# Asp.Net Mvc 5 Azure Active Directory在服务器上获取并保存用户配置文件图像 - Asp.Net Mvc 5 Azure Active Directory Get and save user profile image on server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM