byte[]の画像データをサーバにアップロードし、サーバ指定フォルダに保存

4842 ワード

/       //****************2013-04-12********************
//       ////
//       /// <summary> 
//       ///   
//       /// </summary> 
//       /// <param name="byt"> </param> 
//       /// <returns> Image </returns> 
//       public System.Drawing.Image BytesToImg(byte[] byt) 
//       { 
//           MemoryStream ms = new MemoryStream(byt); 
//           System.Drawing.Image img = System.Drawing.Image.FromStream(ms); 
//           return img; 
//       }
//
//       //****************2013-04-12********************


       public void SavePic(byte[] aImageBytes, string aPicName)
       {
           try
           {
               string fullName = GetServerName() + "/PartInfo/" +aPicName;
               if(File.Exists(fullName))
               {
                   File.Delete(fullName);
               }

//               Image preDrivePic  = BytesToImg(aImageBytes);
//               preDrivePic.Save(fullName,System.Drawing.Imaging.ImageFormat.Jpeg);

               FileStream fs = new FileStream(fullName, FileMode.Create);
               // 
               BinaryWriter bw = new BinaryWriter(fs);
               bw.Write(aImageBytes);
               bw.Flush();
               bw.Close();
               fs.Close();
               GC.Collect();

           }
           catch(Exception ex)
           {
               throw new Exception(" PadResourceFiles/PartInfo/" + ex.Message);
           }
       }

    private static string GetServerName()
       {
           return AppDomain.CurrentDomain.BaseDirectory + "Pad/PadResourceFiles";
       }