简体   繁体   English

在SQL Server 2008 R2上保存图像时C#Web服务中的GDI +错误

[英]GDI+ error in c# web service while saving image on sql server 2008 r2

hi i make a web services that will store the image in inetpub\\wwwroot\\finder in this folder ... so in this case is it necessary to make a virtual directory.... I get the following error --- 您好,我制作了一个网络服务,将图像存储在此文件夹的inetpub \\ wwwroot \\ finder中。因此,在这种情况下,有必要创建一个虚拟目录。...我收到以下错误-

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误。 at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at Service.add_product(String addprod) 在System.Drawing.Image.Save(字符串文件名,ImageCodecInfo编码器,EncoderParameters encoderParams)在Service.add_product(字符串addprod)

even if allowing Everyone's all permissions allow of my finder folder... 即使允许所有人的所有权限也允许我的finder文件夹...

   string img_base64;
   [WebMethod]
   public string add_product(string addprod)
   {

       String[] str_arr = addprod.Split('>');
       city = str_arr[0];
       cat = str_arr[1];
       description = str_arr[2];
       prod_pos = str_arr[3];
       _mobile = str_arr[4];

       img_base64 = str_arr[5];

       lati = str_arr[6];
       longi = str_arr[7];
       land = str_arr[8];

       Decimal latitu = Convert.ToDecimal(lati);
       Decimal longit = Convert.ToDecimal(longi);
     //  Environment.CurrentDirectory();
      // Environment.GetFolderPath("~");
       string saveLocation = HttpContext.Current.Server.MapPath("~" +_mobile+ ".jpeg");

       byte[] bytes = Convert.FromBase64String(img_base64);
       Image image;
       using (var ms = new MemoryStream(bytes))
       {
               image = Image.FromStream(ms);
               image.Save(saveLocation, System.Drawing.Imaging.ImageFormat.Png);
       }

       String img_path = "http://Server IP/folder name/" + _mobile + ".png";
       string sql = "insert into add_product (city,category,description,prod_pos,mobile,latitudeimage,longitude,landmark,image) values('" + city + "','" + cat + "','" + description + "','" + prod_pos + "','" + _mobile + "','" + latitu + "','" + longit + "','" + land + "','" + img_path + "')";
       con.InsertData(sql);

       return "Added Successfully";
   }

Please suggest the solution..... 请提出解决方案.....

Server.MapPath("~") gives you the directory, so you need to include a filename when you save the file. Server.MapPath("~")为您提供目录,因此在保存文件时需要包括文件名。

string saveLocation = System.IO.Path.Combine(Server.MapPath("~"), "filename.png");

With that being said, I would reconsider saving to the IIS folder. 话虽如此,我会重新考虑保存到IIS文件夹中。 You would be better suited storing items like these to your AppData directory on the machine. 您将更适合将此类项目存储到计算机上的AppData目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM